changeset 14445:e0be175bb753

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.
author Jim Meyering <meyering@redhat.com>
date Mon, 21 Mar 2011 15:32:54 +0100
parents 4d990235f694
children 44ed78c8bb5b
files ChangeLog lib/strftime.c
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -173,12 +173,13 @@
   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'))                                             \