Piotr Caban : msvcrt: Don' t touch _bufsiz value while initializing FILE structure.
Alexandre Julliard
julliard at wine.codeweavers.com
Fri Jun 27 10:27:36 CDT 2014
Module: wine
Branch: master
Commit: 60eb44d8209e9829f21edb159408b8930b68107e
URL: http://source.winehq.org/git/wine.git/?a=commit;h=60eb44d8209e9829f21edb159408b8930b68107e
Author: Piotr Caban <piotr at codeweavers.com>
Date: Fri Jun 27 10:17:52 2014 +0200
msvcrt: Don't touch _bufsiz value while initializing FILE structure.
---
dlls/msvcrt/file.c | 4 +++-
dlls/msvcrt/tests/file.c | 19 +++++++++++++++++--
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 77ec853..44e9339 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -458,9 +458,11 @@ static int msvcrt_init_fp(MSVCRT_FILE* file, int fd, unsigned stream_flags)
*MSVCRT__errno() = MSVCRT_EBADF;
return -1;
}
- memset(file, 0, sizeof(*file));
+ file->_ptr = file->_base = NULL;
+ file->_cnt = 0;
file->_file = fd;
file->_flag = stream_flags;
+ file->_tmpfname = NULL;
TRACE(":got FILE* (%p)\n",file);
return 0;
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index 2fd46f2..c253f88 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -1628,7 +1628,7 @@ static void test_fopen_s( void )
const char name[] = "empty1";
char buff[16];
unsigned char *ubuff = (unsigned char*)buff;
- FILE *file;
+ FILE *file, *file2;
int ret;
int len;
@@ -1719,6 +1719,22 @@ static void test_fopen_s( void )
ubuff[0], ubuff[1], ubuff[2]);
fclose(file);
+ /* test initial FILE values */
+ memset(file, 0xfe, sizeof(*file));
+ file->_flag = 0;
+ ret = p_fopen_s(&file2, name, "r");
+ ok(!ret, "fopen_s failed with %d\n", ret);
+ ok(file == file2, "file != file2 %p %p\n", file, file2);
+ ok(!file->_ptr, "file->_ptr != NULL\n");
+ ok(!file->_cnt, "file->_cnt != 0\n");
+ ok(!file->_base, "file->_base != NULL\n");
+ ok(file->_flag == 1, "file->_flag = %x\n", file->_flag);
+ ok(file->_file, "file->_file == 0\n");
+ ok(file->_charbuf == 0xfefefefe, "file->_charbuf = %x\n", file->_charbuf);
+ ok(file->_bufsiz == 0xfefefefe, "file->_bufsiz = %x\n", file->_bufsiz);
+ ok(!file->_tmpfname, "file->_tmpfname != NULL\n");
+ fclose(file2);
+
ok(_unlink(name) == 0, "Couldn't unlink file named '%s'\n", name);
}
@@ -2273,7 +2289,6 @@ static void test_write_flush(void)
file = fopen(tempf, "wb+");
ok(file != NULL, "unable to create test file\n");
iobuf[0] = 0;
- fwrite(iobuf, 1, 1, file); /* needed for wine to init _bufsiz */
ok(file->_bufsiz == 4096, "incorrect default buffer size: %d\n", file->_bufsiz);
test_write_flush_size(file, file->_bufsiz);
setvbuf(file, iobuf, _IOFBF, sizeof(iobuf));
More information about the wine-cvs
mailing list