summaryrefslogtreecommitdiffhomepage
path: root/src/error.c
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-08-02 17:15:34 +0900
committerKOBAYASHI Shuji <[email protected]>2019-08-02 19:22:08 +0900
commitd1817e77910a2747d2bc602964a5f51a1490a252 (patch)
treec28a69d2f764d4026d38b0b168652d4a8fc57646 /src/error.c
parent3bacc302a3b3dd875de87d895cb9b532b522a4f0 (diff)
downloadmruby-d1817e77910a2747d2bc602964a5f51a1490a252.tar.gz
mruby-d1817e77910a2747d2bc602964a5f51a1490a252.zip
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.
Diffstat (limited to 'src/error.c')
-rw-r--r--src/error.c8
1 files changed, 5 insertions, 3 deletions
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));