From afb5f0ee62257c7bcb1c00673d29c012797db347 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Thu, 8 Mar 2018 21:38:40 +0100 Subject: [PATCH] [SDK] Do not use a NUL file while calculating printf 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 -- 2.12.2.windows.1