summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-22 14:30:33 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-22 14:30:33 +0000
commit7f62113f4d4e29795561df9a0d52a6960e207252 (patch)
tree7b4929124e6add95ef37c61bb7303cf5094b9a2a /sprintf.c
parent0b2c50f3a7c952a518330ac22c16a72089e613a8 (diff)
* sprintf.c (rb_f_sprintf): preceding ".." for negative
hexadecimal numbers should not appear if prec (e.g. %.4) is specified. * pack.c (NUM2I32): support platforms which does not have 32bit integers (e.g. Cray). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/sprintf.c b/sprintf.c
index 190af52e86..f5e95423a1 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -404,7 +404,7 @@ rb_f_sprintf(argc, argv)
if (base == 10) {
rb_warning("negative number for %%u specifier");
}
- else {
+ else if (!(flags&FPREC)) {
strcpy(s, "..");
s += 2;
}
@@ -463,8 +463,10 @@ rb_f_sprintf(argc, argv)
remove_sign_bits(++s, base);
val = rb_str_new(0, 3+strlen(s));
t = RSTRING(val)->ptr;
- strcpy(t, "..");
- t += 2;
+ if (!(flags&FPREC)) {
+ strcpy(t, "..");
+ t += 2;
+ }
switch (base) {
case 16:
if (s[0] != 'f') strcpy(t++, "f"); break;
@@ -492,7 +494,7 @@ rb_f_sprintf(argc, argv)
}
if (prec < len) prec = len;
width -= prec;
- if (!(flags&(FZERO|FMINUS)) && s[0] != '.') {
+ if (!(flags&(FZERO|FMINUS)) && v >= 0) {
CHECK(width);
while (width-->0) {
buf[blen++] = ' ';
@@ -507,7 +509,7 @@ rb_f_sprintf(argc, argv)
if (!(flags & FMINUS)) {
char c = ' ';
- if (s[0] == '.') {
+ if (v < 0) {
c = '.';
if ((flags & FPREC) && prec > len) {
pos = blen;
@@ -524,7 +526,7 @@ rb_f_sprintf(argc, argv)
}
CHECK(prec - len);
while (len < prec--) {
- buf[blen++] = s[0]=='.'?'.':'0';
+ buf[blen++] = v < 0 ? '.' : '0';
}
PUSH(s, len);
CHECK(width);