[前][次][番号順一覧][スレッド一覧]

ruby-changes:73005

From: Nobuyoshi <ko1@a...>
Date: Sun, 21 Aug 2022 21:59:14 +0900 (JST)
Subject: [ruby-changes:73005] b043dd9c5d (master): Check the room including the space to fill

https://git.ruby-lang.org/ruby.git/commit/?id=b043dd9c5d

From b043dd9c5dd7b5c46580e49ad38b49d5cb5beaf1 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 21 Aug 2022 20:06:39 +0900
Subject: Check the room including the space to fill

---
 sprintf.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/sprintf.c b/sprintf.c
index 22323265b3..32a72439af 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -460,14 +460,16 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/sprintf.c#L460
                     blen += n;
                 }
                 else if ((flags & FMINUS)) {
-                    CHECK(n);
+                    --width;
+                    CHECK(n + (width > 0 ? width : 0));
                     rb_enc_mbcput(c, &buf[blen], enc);
                     blen += n;
-                    if (width > 1) FILL(' ', width-1);
+                    if (width > 0) FILL_(' ', width);
                 }
                 else {
-                    if (width > 1) FILL(' ', width-1);
-                    CHECK(n);
+                    --width;
+                    CHECK(n + (width > 0 ? width : 0));
+                    if (width > 0) FILL_(' ', width);
                     rb_enc_mbcput(c, &buf[blen], enc);
                     blen += n;
                 }
@@ -512,16 +514,16 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/sprintf.c#L514
                     /* need to adjust multi-byte string pos */
                     if ((flags&FWIDTH) && (width > slen)) {
                         width -= (int)slen;
+                        CHECK(len + width);
                         if (!(flags&FMINUS)) {
-                            FILL(' ', width);
+                            FILL_(' ', width);
                             width = 0;
                         }
-                        CHECK(len);
                         memcpy(&buf[blen], RSTRING_PTR(str), len);
                         RB_GC_GUARD(str);
                         blen += len;
                         if (flags&FMINUS) {
-                            FILL(' ', width);
+                            FILL_(' ', width);
                         }
                         rb_enc_associate(result, enc);
                         break;
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]