]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(process_arg): Correct %ls handling wrt to precision.
authorUlrich Drepper <drepper@redhat.com>
Tue, 17 Aug 1999 01:08:31 +0000 (01:08 +0000)
committerUlrich Drepper <drepper@redhat.com>
Tue, 17 Aug 1999 01:08:31 +0000 (01:08 +0000)
stdio-common/vfprintf.c

index 15a4e219df8f925b730ba2d7f3404f74c6372ef0..bc66393a366221b0da91dc35afba358a2a98b23f 100644 (file)
@@ -915,20 +915,31 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
            mbstate_t mbstate;                                                \
                                                                              \
            memset (&mbstate, '\0', sizeof (mbstate_t));                      \
-           len = __wcsrtombs (NULL, &s2, 0, &mbstate);                       \
+                                                                             \
+           if (prec > 0)                                                     \
+             {                                                               \
+               /* The string `s2' might not be NUL terminated.  */           \
+               string = (char *) alloca (prec + 1);                          \
+               len = __wcsrtombs (string, &s2, prec + 1, &mbstate);          \
+             }                                                               \
+           else                                                              \
+             {                                                               \
+               len = __wcsrtombs (NULL, &s2, 0, &mbstate);                   \
+               if (len != (size_t) -1)                                       \
+                 {                                                           \
+                   assert (__mbsinit (&mbstate));                            \
+                   s2 = (const wchar_t *) string;                            \
+                   string = (char *) alloca (len + 1);                       \
+                   (void) __wcsrtombs (string, &s2, len + 1, &mbstate);      \
+                 }                                                           \
+             }                                                               \
+                                                                             \
            if (len == (size_t) -1)                                           \
              {                                                               \
                /* Illegal wide-character string.  */                         \
                done = -1;                                                    \
                goto all_done;                                                \
              }                                                               \
-                                                                             \
-           assert (__mbsinit (&mbstate));                                    \
-           s2 = (const wchar_t *) string;                                    \
-           string = alloca (len + 1);                                        \
-           (void) __wcsrtombs (string, &s2, len + 1, &mbstate);              \
-           if (prec < len)                                                   \
-             len = prec;                                                     \
          }                                                                   \
                                                                              \
        if ((width -= len) < 0)                                               \