From d1817e77910a2747d2bc602964a5f51a1490a252 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Fri, 2 Aug 2019 17:15:34 +0900 Subject: Change the `mrb_vformat` specifier `%d` for `int` It potentially breaks, for example, in the case of `mrb_int` is 64-bit and more smaller type is passed by `%d`. In fact, the problem could become apparent when I used `%d` to `backtrace_location::lineno` in `src/backtrace.c:mrb_unpack_backtrace()` on AppVeyor. Therefore, change `%d` for `int` (not `mrb_int`) so that it can be used mostly without casting. --- src/error.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/error.c') diff --git a/src/error.c b/src/error.c index d8224622b..6e7c3763a 100644 --- a/src/error.c +++ b/src/error.c @@ -282,8 +282,9 @@ mrb_raise(mrb_state *mrb, struct RClass *c, const char *msg) * Specifier | Argument Type | Note * ----------+----------------+-------------------------------------------- * c | char | - * d,i | mrb_int | + * d | int | * f | mrb_float | + * i | mrb_int | * l | char*, mrb_int | Arguments are string and length. * n | mrb_sym | * s | char* | Argument is NUL terminated string. @@ -303,7 +304,7 @@ mrb_vformat(mrb_state *mrb, const char *format, va_list ap) const char *chars, *p = format, *b = format, *e; char ch; struct RClass *cls; - mrb_int len; + mrb_int len, i; mrb_bool inspect = FALSE; mrb_value result = mrb_str_new_capa(mrb, 128), obj, str; int ai = mrb_gc_arena_save(mrb); @@ -324,7 +325,8 @@ mrb_vformat(mrb_state *mrb, const char *format, va_list ap) len = 1; goto L_cat; case 'd': case 'i': - obj = mrb_fixnum_value(va_arg(ap, mrb_int)); + i = *p == 'd' ? (mrb_int)va_arg(ap, int) : va_arg(ap, mrb_int); + obj = mrb_fixnum_value(i); goto L_cat_obj; case 'f': obj = mrb_float_value(mrb, va_arg(ap, mrb_float)); -- cgit v1.2.3