fix scanf %c conversion wrongly storing a terminating null byte
authorRich Felker <dalias@aerifal.cx>
Sat, 22 Jun 2013 21:23:45 +0000 (17:23 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 22 Jun 2013 21:23:45 +0000 (17:23 -0400)
this seems to have been a regression from the refactoring which added
the 'm' modifier.

src/stdio/vfscanf.c
src/stdio/vfwscanf.c

index 6bea6ad8f1d82fa0ec56887f025aaf04c1a70d48..bb9284809846473f09a2ca3aab0de7fd0e2bbab9 100644 (file)
@@ -265,8 +265,10 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap)
                                if (size == SIZE_l) *(wchar_t **)dest = wcs;
                                else *(char **)dest = s;
                        }
-                       if (wcs) wcs[i] = 0;
-                       if (s) s[i] = 0;
+                       if (t != 'c') {
+                               if (wcs) wcs[i] = 0;
+                               if (s) s[i] = 0;
+                       }
                        break;
                case 'p':
                case 'X':
index b1eb7939e2461d31be439a676b6d5514fd2c1ef3..760864ff97b3800508fdcf264b80b4cd6ba7ce3b 100644 (file)
@@ -281,8 +281,10 @@ int vfwscanf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap)
                                if (size == SIZE_l) *(wchar_t **)dest = wcs;
                                else *(char **)dest = s;
                        }
-                       if (wcs) wcs[i] = 0;
-                       if (s) s[i] = 0;
+                       if (t != 'c') {
+                               if (wcs) wcs[i] = 0;
+                               if (s) s[i] = 0;
+                       }
                        break;
 
                case 'd': case 'i': case 'o': case 'u': case 'x':