Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6938a29

Browse files
committed
Three micro fixes to formatstring
1 parent b31c7f7 commit 6938a29

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

Objects/stringobject.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ formatstring(format, args)
643643
int width = -1;
644644
int prec = -1;
645645
int size = 0;
646-
int c;
646+
int c = '\0';
647647
int fill;
648648
object *v;
649649
char *buf;
@@ -788,15 +788,13 @@ formatstring(format, args)
788788
buf = formatchar(v);
789789
if (buf == NULL)
790790
goto error;
791-
len = strlen(buf);
791+
len = 1;
792792
break;
793793
default:
794794
err_setstr(ValueError,
795795
"unsupported format character");
796796
goto error;
797797
}
798-
/* XXX There's a bug somewhere here so that
799-
XXX '%4d'%-1 yields '- 1' ... */
800798
if (sign) {
801799
if (*buf == '-' || *buf == '+') {
802800
sign = *buf++;
@@ -820,7 +818,6 @@ formatstring(format, args)
820818
res = getstringvalue(result) + reslen - rescnt;
821819
}
822820
if (sign) {
823-
*res++ = sign;
824821
rescnt--;
825822
if (width > len)
826823
width--;
@@ -831,6 +828,8 @@ formatstring(format, args)
831828
*res++ = fill;
832829
} while (--width > len);
833830
}
831+
if (sign)
832+
*res++ = sign;
834833
memcpy(res, buf, len);
835834
res += len;
836835
rescnt -= len;

0 commit comments

Comments
 (0)