summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-17 23:14:52 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-17 23:14:52 +0000
commit72a28f3cef12210c4f2adb538343865496e073f1 (patch)
tree138b56367394a582a8767e42ab25331300233327 /sprintf.c
parent2ed6ca584d41d712b5d867b1053f34da254b9c6a (diff)
* sprintf.c (rb_f_sprintf): remove extra sign digit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/sprintf.c b/sprintf.c
index c3ba21b..98db29e 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -25,31 +25,30 @@ remove_sign_bits(str, base)
char *str;
int base;
{
- char *s, *t, *end;
- unsigned long len;
+ char *s, *t;
s = t = str;
- len = strlen(str);
- end = str + len;
if (base == 16) {
- while (t<end && *t == 'f') {
+ while (*t == 'f') {
t++;
}
}
else if (base == 8) {
if (*t == '3') t++;
- while (t<end && *t == '7') {
+ while (*t == '7') {
t++;
}
}
else if (base == 2) {
- while (t<end && *t == '1') {
+ while (*t == '1') {
t++;
}
}
- while (*t) *s++ = *t++;
- *s = '\0';
+ if (t > s) {
+ while (*t) *s++ = *t++;
+ *s = '\0';
+ }
return str;
}
@@ -57,7 +56,7 @@ remove_sign_bits(str, base)
static char
sign_bits(base, p)
int base;
- char *p;
+ const char *p;
{
char c = '.';
@@ -234,7 +233,8 @@ rb_f_sprintf(argc, argv)
VALUE *argv;
{
VALUE fmt;
- char *buf, *p, *end;
+ const char *p, *end;
+ char *buf;
int blen, bsiz;
VALUE result;
@@ -257,7 +257,7 @@ rb_f_sprintf(argc, argv)
buf = RSTRING(result)->ptr;
for (; p < end; p++) {
- char *t;
+ const char *t;
int n;
for (t = p; t < end && *t != '%'; t++) ;
@@ -550,7 +550,7 @@ rb_f_sprintf(argc, argv)
s += 2;
}
}
- sprintf(fbuf, "%%l%c", *p);
+ sprintf(fbuf, "%%l%c", *p == 'X' ? 'x' : *p);
sprintf(s, fbuf, v);
if (v < 0) {
char d = 0;