From 4cae3d45b2bad5f45adef5a0fab285313b58eb69 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 21 Mar 2011 15:32:54 +0100 Subject: [PATCH] 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. --- ChangeLog | 7 +++++++ lib/strftime.c | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0e4261168..070cada46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2011-03-21 Jim Meyering + 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 + tests: add strftime-tests module * tests/test-strftime.c: New file. * modules/strftime-tests: New module. diff --git a/lib/strftime.c b/lib/strftime.c index 95d5beeb8..acebc9adf 100644 --- a/lib/strftime.c +++ b/lib/strftime.c @@ -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')) \ -- 2.11.0