ruby-changes:9460
From: yugui <ko1@a...>
Date: Thu, 25 Dec 2008 18:51:38 +0900 (JST)
Subject: [ruby-changes:9460] Ruby:r20999 (ruby_1_9_1): merges r20911 and 20921 from trunk into ruby_1_9_1.
yugui 2008-12-25 18:51:20 +0900 (Thu, 25 Dec 2008) New Revision: 20999 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20999 Log: merges r20911 and 20921 from trunk into ruby_1_9_1. * missing/vsnprintf.c (BSD_vfprintf): fix for test_sprintf_comb.rb, by wanabe in [ruby-dev:36935]. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/missing/vsnprintf.c branches/ruby_1_9_1/sprintf.c Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 20998) +++ ruby_1_9_1/ChangeLog (revision 20999) @@ -1,3 +1,12 @@ +Tue Dec 23 00:16:48 2008 Yusuke Endoh <mame@t...> + + * sprintf.c (rb_str_format): fix buffer overflow. + +Mon Dec 22 12:25:09 2008 Nobuyoshi Nakada <nobu@r...> + + * missing/vsnprintf.c (BSD_vfprintf): fix for test_sprintf_comb.rb, by + wanabe in [ruby-dev:36935]. + Mon Dec 22 12:05:14 2008 Nobuyoshi Nakada <nobu@r...> * configure.in (mingw): no longer uses snprintf and vsnprintf of Index: ruby_1_9_1/sprintf.c =================================================================== --- ruby_1_9_1/sprintf.c (revision 20998) +++ ruby_1_9_1/sprintf.c (revision 20999) @@ -979,8 +979,8 @@ if ((flags & FWIDTH) && need < width) need = width; - CHECK(need); - snprintf(&buf[blen], need, "%*s", need, ""); + CHECK(need + 1); + snprintf(&buf[blen], need + 1, "%*s", need, ""); if (flags & FMINUS) { if (!isnan(fval) && fval < 0.0) buf[blen++] = '-'; Index: ruby_1_9_1/missing/vsnprintf.c =================================================================== --- ruby_1_9_1/missing/vsnprintf.c (revision 20998) +++ ruby_1_9_1/missing/vsnprintf.c (revision 20999) @@ -753,6 +753,8 @@ #ifdef FLOATING_POINT case 'e': /* anomalous precision */ case 'E': + if (prec != 0) + flags |= ALT; prec = (prec == -1) ? DEFPREC + 1 : prec + 1; /* FALLTHROUGH */ @@ -782,7 +784,7 @@ cp = cvt(_double, prec, flags, &softsign, &expt, ch, &ndig); if (ch == 'g' || ch == 'G') { - if (expt <= -4 || expt > prec) + if (expt <= -4 || (expt > prec && expt > 1)) ch = (ch == 'g') ? 'e' : 'E'; else ch = 'g'; @@ -798,6 +800,8 @@ size = expt; if (prec || flags & ALT) size += prec + 1; + } else if (!prec) { /* "0" */ + size = 1; } else /* "0.X" */ size = prec + 2; } else if (expt >= ndig) { /* fixed g fmt */ @@ -1008,13 +1012,15 @@ if (ch >= 'f') { /* 'f' or 'g' */ if (_double == 0) { /* kludge for __dtoa irregularity */ - if (prec == 0 || + if (ndig <= 1 && (flags & ALT) == 0) { PRINT("0", 1); } else { PRINT("0.", 2); PAD(ndig - 1, zeroes); } + } else if (expt == 0 && ndig == 0 && (flags & ALT) == 0) { + PRINT("0", 1); } else if (expt <= 0) { PRINT("0.", 2); PAD(-expt, zeroes); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/