From: Guido van Rossum Date: Mon, 7 Jun 1999 15:12:32 +0000 (+0000) Subject: Fix bug discovered by John W. Shipman -- when the width of a format X-Git-Tag: v1.6a1~1283 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=98c9eba945dd75d63e97dc66fb70b8dc53b8d9a7;p=thirdparty%2FPython%2Fcpython.git Fix bug discovered by John W. Shipman -- when the width of a format specifier came from an int expression instead of a constant in the format, a negative width was truncated to zero instead of taken to mean the same as that negative constant plugged into the format. E.g. "(%*s)" % (-5, "foo") yielded "(foo)" while "(%-5s)" yields "(foo )". Now both yield the latter -- like sprintf() in C. --- diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 1f1a41b21bdd..eecb0060b582 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -832,8 +832,10 @@ PyString_Format(format, args) goto error; } width = PyInt_AsLong(v); - if (width < 0) - width = 0; + if (width < 0) { + flags |= F_LJUST; + width = -width; + } if (--fmtcnt >= 0) c = *fmt++; }