]> granicus.if.org Git - python/commitdiff
Fix bug reported by Per Lindqvist: "%#06x" % 1 stuck the 0 padding
authorGuido van Rossum <guido@python.org>
Wed, 29 Jan 1997 06:00:24 +0000 (06:00 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 29 Jan 1997 06:00:24 +0000 (06:00 +0000)
in front of the 0x, like such: "0000x1".

Objects/stringobject.c

index f037f961771bd24460b38ad651b64f5c642c814d..283e219d34a7d3995c6400eba15cb850bc388e0f 100644 (file)
@@ -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':