summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-01-29 06:00:24 (GMT)
committerGuido van Rossum <guido@python.org>1997-01-29 06:00:24 (GMT)
commit4acdc2327f206ecaacad7671d9acb87a3b7e57dd (patch)
treec514c3e7d583216c2d2367d1790749f7e4f5ac00 /Objects
parent9e5656ca3f3eed7169ead42e7a768733baaf2a16 (diff)
downloadcpython-4acdc2327f206ecaacad7671d9acb87a3b7e57dd.zip
cpython-4acdc2327f206ecaacad7671d9acb87a3b7e57dd.tar.gz
cpython-4acdc2327f206ecaacad7671d9acb87a3b7e57dd.tar.bz2
Fix bug reported by Per Lindqvist: "%#06x" % 1 stuck the 0 padding
in front of the 0x, like such: "0000x1".
Diffstat (limited to 'Objects')
-rw-r--r--Objects/stringobject.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index f037f96..283e219 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -855,8 +855,20 @@ formatstring(format, args)
if (len < 0)
goto error;
sign = (c == 'd');
- if (flags&F_ZERO)
+ if (flags&F_ZERO) {
fill = '0';
+ if ((flags&F_ALT) &&
+ (c == 'x' || c == 'X') &&
+ buf[0] == '0' && buf[1] == c) {
+ *res++ = *buf++;
+ *res++ = *buf++;
+ rescnt -= 2;
+ len -= 2;
+ width -= 2;
+ if (width < 0)
+ width = 0;
+ }
+ }
break;
case 'e':
case 'E':