summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-03-20 06:27:22 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-03-20 06:27:22 +0000
commit85dd7bb0ef28fe4ce63641e653d92e42327b0207 (patch)
treebcd1e5b816c1a7cdc06f31f28cd967f6b78e9a96 /sprintf.c
parent5782e5b0006ca5f941e8cdd7101ca07218c9d816 (diff)
* eval.c (load_dyna): clear ruby_errinfo. (ruby-bugs-ja PR#409)
* io.c (read_all): make str empty if given. (ruby-bugs-ja PR#408) * io.c (io_read): ditto. * io.c (rb_io_sysread): ditto. * range.c: do not override min and max. * sprintf.c (remove_sign_bits): octal left most digit for negative numbers may be '3'. (ruby-bugs-ja PR#407) * sprintf.c (rb_f_sprintf): should prefix sign bits if bignum is negative, using sign_bits(). * eval.c (avalue_to_mrhs): split argument passing and assignment conversion. * eval.c (svalue_to_mrhs): ditto. * eval.c (avalue_to_svalue): avalue_to_svalue([[1,2]]) should be [[1,2]], not [1,2] to wrap-around. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/sprintf.c b/sprintf.c
index 2d5f13e372..69f9fa3ff3 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -38,6 +38,7 @@ remove_sign_bits(str, base)
}
}
else if (base == 8) {
+ if (*t == '3') t++;
while (t<end && *t == '7') {
t++;
}
@@ -53,6 +54,26 @@ remove_sign_bits(str, base)
return str;
}
+static char
+sign_bits(base, p)
+ int base;
+ char *p;
+{
+ char c = '.';
+
+ switch (base) {
+ case 16:
+ if (*p == 'X') c = 'F';
+ else c = 'f';
+ break;
+ case 8:
+ c = '7'; break;
+ case 2:
+ c = '1'; break;
+ }
+ return c;
+}
+
#define FNONE 0
#define FSHARP 1
#define FMINUS 2
@@ -529,25 +550,15 @@ rb_f_sprintf(argc, argv)
}
CHECK(prec - len);
if (!bignum && v < 0) {
- char c = '.';
-
- switch (base) {
- case 16:
- if (*p == 'X') c = 'F';
- else c = 'f';
- break;
- case 8:
- c = '7'; break;
- case 2:
- c = '1'; break;
- }
+ char c = sign_bits(base, p);
while (len < prec--) {
buf[blen++] = c;
}
}
else {
+ char c = sign_bits(base, p);
while (len < prec--) {
- buf[blen++] = '0';
+ buf[blen++] = c;
}
}
PUSH(s, len);