[ruby-cvs:65209] Re: nobu:r58021 (trunk): sprintf.c: use FILL

Eric Wong normalperson at yhbt.net
Tue Mar 21 08:33:38 JST 2017


--- a/sprintf.c
+++ b/sprintf.c
@@ -74,6 +74,7 @@ sign_bits(int base, const char *p)
 } while (0)
 
 #define FILL(c, l) do { \
+    if ((l) <= 0) break;\
     CHECK(l);\
     FILL_(c, l);\
 } while (0)
@@ -758,20 +759,15 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
 		    if ((flags&FWIDTH) && (width > slen)) {
 			width -= (int)slen;
 			if (!(flags&FMINUS)) {
-			    CHECK(width);
-			    while (width--) {
-				buf[blen++] = ' ';
-			    }
+			    FILL(' ', width);
+			    width = 0;
 			}
 			CHECK(len);
 			memcpy(&buf[blen], RSTRING_PTR(str), len);

I'm not familiar with this code; but we need to update blen
for memcpy, right?

Maybe other callsites will need blen updated, too.


More information about the ruby-cvs mailing list