diff Objects/stringobject.c @ 10923:8234bb36fb8c legacy-trunk

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.
author Guido van Rossum <guido@python.org>
date Mon, 07 Jun 1999 15:12:32 +0000
parents 083efa076366
children aca7b5eaf5e8
line wrap: on
line diff
--- a/Objects/stringobject.c	Mon Jun 07 14:28:14 1999 +0000
+++ b/Objects/stringobject.c	Mon Jun 07 15:12:32 1999 +0000
@@ -832,8 +832,10 @@
 					goto error;
 				}
 				width = PyInt_AsLong(v);
-				if (width < 0)
-					width = 0;
+				if (width < 0) {
+					flags |= F_LJUST;
+					width = -width;
+				}
 				if (--fmtcnt >= 0)
 					c = *fmt++;
 			}