diff Objects/stringobject.c @ 1408:18df674539da legacy-trunk

Three micro fixes to formatstring
author Guido van Rossum <guido@python.org>
date Thu, 11 Nov 1993 14:51:57 +0000
parents a4aa83012af3
children f5b1ddfddba8
line wrap: on
line diff
--- a/Objects/stringobject.c	Thu Nov 11 10:31:23 1993 +0000
+++ b/Objects/stringobject.c	Thu Nov 11 14:51:57 1993 +0000
@@ -643,7 +643,7 @@
 			int width = -1;
 			int prec = -1;
 			int size = 0;
-			int c;
+			int c = '\0';
 			int fill;
 			object *v;
 			char *buf;
@@ -788,15 +788,13 @@
 				buf = formatchar(v);
 				if (buf == NULL)
 					goto error;
-				len = strlen(buf);
+				len = 1;
 				break;
 			default:
 				err_setstr(ValueError,
 					   "unsupported format character");
 				goto error;
 			}
-			/* XXX There's a bug somewhere here so that
-			   XXX '%4d'%-1 yields '-  1' ... */
 			if (sign) {
 				if (*buf == '-' || *buf == '+') {
 					sign = *buf++;
@@ -820,7 +818,6 @@
 				res = getstringvalue(result) + reslen - rescnt;
 			}
 			if (sign) {
-				*res++ = sign;
 				rescnt--;
 				if (width > len)
 					width--;
@@ -831,6 +828,8 @@
 					*res++ = fill;
 				} while (--width > len);
 			}
+			if (sign)
+				*res++ = sign;
 			memcpy(res, buf, len);
 			res += len;
 			rescnt -= len;