Commit 6938a297 authored by Guido van Rossum's avatar Guido van Rossum

Three micro fixes to formatstring

parent b31c7f73
...@@ -643,7 +643,7 @@ formatstring(format, args) ...@@ -643,7 +643,7 @@ formatstring(format, args)
int width = -1; int width = -1;
int prec = -1; int prec = -1;
int size = 0; int size = 0;
int c; int c = '\0';
int fill; int fill;
object *v; object *v;
char *buf; char *buf;
...@@ -788,15 +788,13 @@ formatstring(format, args) ...@@ -788,15 +788,13 @@ formatstring(format, args)
buf = formatchar(v); buf = formatchar(v);
if (buf == NULL) if (buf == NULL)
goto error; goto error;
len = strlen(buf); len = 1;
break; break;
default: default:
err_setstr(ValueError, err_setstr(ValueError,
"unsupported format character"); "unsupported format character");
goto error; goto error;
} }
/* XXX There's a bug somewhere here so that
XXX '%4d'%-1 yields '- 1' ... */
if (sign) { if (sign) {
if (*buf == '-' || *buf == '+') { if (*buf == '-' || *buf == '+') {
sign = *buf++; sign = *buf++;
...@@ -820,7 +818,6 @@ formatstring(format, args) ...@@ -820,7 +818,6 @@ formatstring(format, args)
res = getstringvalue(result) + reslen - rescnt; res = getstringvalue(result) + reslen - rescnt;
} }
if (sign) { if (sign) {
*res++ = sign;
rescnt--; rescnt--;
if (width > len) if (width > len)
width--; width--;
...@@ -831,6 +828,8 @@ formatstring(format, args) ...@@ -831,6 +828,8 @@ formatstring(format, args)
*res++ = fill; *res++ = fill;
} while (--width > len); } while (--width > len);
} }
if (sign)
*res++ = sign;
memcpy(res, buf, len); memcpy(res, buf, len);
res += len; res += len;
rescnt -= len; rescnt -= len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment