https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2f548599a4b9e33eeec79b113e7d8bc511336b07
commit 2f548599a4b9e33eeec79b113e7d8bc511336b07 Author: Mark Jansen <mark.jan...@reactos.org> AuthorDate: Thu Mar 8 21:38:40 2018 +0100 Commit: Mark Jansen <mark.jan...@reactos.org> CommitDate: Sat Mar 10 00:04:57 2018 +0100 [SDK] Do not use a NUL file while calculating format string length CORE-14342 --- sdk/lib/crt/printf/_vscprintf.c | 15 +++++---------- sdk/lib/crt/printf/_vscwprintf.c | 14 +++++--------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/sdk/lib/crt/printf/_vscprintf.c b/sdk/lib/crt/printf/_vscprintf.c index 5db594f718..7b4e6b5f72 100644 --- a/sdk/lib/crt/printf/_vscprintf.c +++ b/sdk/lib/crt/printf/_vscprintf.c @@ -15,14 +15,9 @@ _vscprintf( const char *format, va_list argptr) { - int ret; - FILE* nulfile = fopen("nul", "w"); - if(nulfile == NULL) - { - /* This should never happen... */ - return -1; - } - ret = streamout(nulfile, format, argptr); - fclose(nulfile); - return ret; + FILE nulfile; + nulfile._tmpfname = nulfile._ptr = nulfile._base = NULL; + nulfile._bufsiz = nulfile._charbuf = nulfile._cnt = 0; + nulfile._flag = _IOSTRG | _IOWRT; + return streamout(&nulfile, format, argptr); } diff --git a/sdk/lib/crt/printf/_vscwprintf.c b/sdk/lib/crt/printf/_vscwprintf.c index f6b7e9d55d..5b01fc1db9 100644 --- a/sdk/lib/crt/printf/_vscwprintf.c +++ b/sdk/lib/crt/printf/_vscwprintf.c @@ -22,15 +22,11 @@ _vscwprintf( { int ret; #ifndef _LIBCNT_ - FILE* nulfile; - nulfile = fopen("nul", "w"); - if(nulfile == NULL) - { - /* This should never happen... */ - return -1; - } - ret = wstreamout(nulfile, format, argptr); - fclose(nulfile); + FILE nulfile; + nulfile._tmpfname = nulfile._ptr = nulfile._base = NULL; + nulfile._bufsiz = nulfile._charbuf = nulfile._cnt = 0; + nulfile._flag = _IOSTRG | _IOWRT; + ret = wstreamout(&nulfile, format, argptr); #else ret = -1; #endif