strftime: fix a bug in yesterday's change
authorJim Meyering <meyering@redhat.com>
Mon, 21 Mar 2011 14:32:54 +0000 (15:32 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 21 Mar 2011 14:38:14 +0000 (15:38 +0100)
* lib/strftime.c (add): Accommodate width's initial value of -1.
Otherwise, nstrftime would copy uninitialized data into
the result buffer.

ChangeLog
lib/strftime.c

index 0e4261168ba54ee742c97d6269beaf74aa85304e..070cada462ac7e5dd32b018cc7ba7be415694dfa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-03-21  Jim Meyering  <meyering@redhat.com>
+
+       strftime: fix a bug in yesterday's change
+       * lib/strftime.c (add): Accommodate width's initial value of -1.
+       Otherwise, nstrftime would copy uninitialized data into
+       the result buffer.
+
 2011-03-21  Jim Meyering  <meyering@redhat.com>
 
        tests: add strftime-tests module
index 95d5beeb84482761d3fc1045ff2edeec241264b1..acebc9adfad65b9f968c96055b50d26ec38f89fc 100644 (file)
@@ -173,12 +173,13 @@ extern char *tzname[];
   do                                                                          \
     {                                                                         \
       size_t _n = (n);                                                        \
-      size_t _incr = _n < width ? width : _n;                                 \
+      size_t _w = (width < 0 ? 0 : width);                                    \
+      size_t _incr = _n < _w ? _w : _n;                                       \
       if (_incr >= maxsize - i)                                               \
         return 0;                                                             \
       if (p)                                                                  \
         {                                                                     \
-          if (digits == 0 && _n < width)                                      \
+          if (digits == 0 && _n < _w)                                         \
             {                                                                 \
               size_t _delta = width - _n;                                     \
               if (pad == L_('0'))                                             \