aboutsummaryrefslogtreecommitdiffstats
path: root/sprintf.c
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-25 15:33:28 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-25 15:33:28 +0000
commit6444789abdc3281c6846e99b1a59a32de9eedae0 (patch)
treec4d9db00a864d5eb740b17cc32c0b557cb9b6360 /sprintf.c
parent431de5be4e68c69bc880c831b42c20241dd53a85 (diff)
downloadruby-6444789abdc3281c6846e99b1a59a32de9eedae0.tar.gz
Raise ArgumentError if sprintf format string ends with %
* Add tests and specs. See ruby/spec#401. Patch by Yuta Iwama and Shintaro Morikawa. [ruby-core:80153] [Bug #13315] [Fix GH-1560] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/sprintf.c b/sprintf.c
index 89541344a9..8488d58cbd 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -520,7 +520,10 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
VALUE sym = Qnil;
for (t = p; t < end && *t != '%'; t++) ;
- if (t + 1 == end) ++t;
+ if (t + 1 == end) {
+ if (*t == '%') rb_raise(rb_eArgError, "incomplete format specifier");
+ ++t;
+ }
PUSH(p, t - p);
if (coderange != ENC_CODERANGE_BROKEN && scanned < blen) {
scanned += rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &coderange);