]> granicus.if.org Git - jq/commitdiff
MultiByteToWideChar() usage bug (fix #1072)
authorNicolas Williams <nico@cryptonector.com>
Fri, 15 Jan 2016 17:58:41 +0000 (11:58 -0600)
committerNicolas Williams <nico@cryptonector.com>
Fri, 15 Jan 2016 17:58:41 +0000 (11:58 -0600)
src/util.c

index 3f7cab8de24305c52aecd5c5ed8d7f3f968ceab7..7eefc666c403ee82ba5333d6cb1036051e9e7116 100644 (file)
@@ -48,11 +48,11 @@ void *alloca (size_t);
 #ifdef WIN32
 FILE *fopen(const char *fname, const char *mode) {
   size_t sz = sizeof(wchar_t) * MultiByteToWideChar(CP_UTF8, 0, fname, -1, NULL, 0);
-  wchar_t *wfname = alloca(sz);
+  wchar_t *wfname = alloca(sz + 2); // +2 is not needed, but just in case
   MultiByteToWideChar(CP_UTF8, 0, fname, -1, wfname, sz);
 
-  sz = MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0);
-  wchar_t *wmode = alloca(sz);
+  sz = sizeof(wchar_t) * MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0);
+  wchar_t *wmode = alloca(sz); // +2 is not needed, but just in case
   MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, sz);
   return _wfopen(wfname, wmode);
 }