Commit 84d9296c authored by dearblue's avatar dearblue

Use inttypes for `snprintf()`

parent 3c1a2612
...@@ -41,12 +41,15 @@ struct mrb_state; ...@@ -41,12 +41,15 @@ struct mrb_state;
#if defined _MSC_VER && _MSC_VER < 1800 #if defined _MSC_VER && _MSC_VER < 1800
# define PRIo64 "llo" # define PRIo64 "llo"
# define PRId64 "lld" # define PRId64 "lld"
# define PRIu64 "llu"
# define PRIx64 "llx" # define PRIx64 "llx"
# define PRIo16 "ho" # define PRIo16 "ho"
# define PRId16 "hd" # define PRId16 "hd"
# define PRIu16 "hu"
# define PRIx16 "hx" # define PRIx16 "hx"
# define PRIo32 "o" # define PRIo32 "o"
# define PRId32 "d" # define PRId32 "d"
# define PRIu32 "u"
# define PRIx32 "x" # define PRIx32 "x"
#else #else
# include <inttypes.h> # include <inttypes.h>
......
...@@ -237,7 +237,7 @@ unpack_l(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un ...@@ -237,7 +237,7 @@ unpack_l(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un
int32_t sl = ul; int32_t sl = ul;
#ifndef MRB_INT64 #ifndef MRB_INT64
if (!FIXABLE(sl)) { if (!FIXABLE(sl)) {
snprintf(msg, sizeof(msg), "cannot unpack to Fixnum: %ld", (long)sl); snprintf(msg, sizeof(msg), "cannot unpack to Fixnum: %" PRId32, sl);
mrb_raise(mrb, E_RANGE_ERROR, msg); mrb_raise(mrb, E_RANGE_ERROR, msg);
} }
#endif #endif
...@@ -245,7 +245,7 @@ unpack_l(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un ...@@ -245,7 +245,7 @@ unpack_l(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un
} else { } else {
#ifndef MRB_INT64 #ifndef MRB_INT64
if (!POSFIXABLE(ul)) { if (!POSFIXABLE(ul)) {
snprintf(msg, sizeof(msg), "cannot unpack to Fixnum: %lu", (unsigned long)ul); snprintf(msg, sizeof(msg), "cannot unpack to Fixnum: %" PRIu32, ul);
mrb_raise(mrb, E_RANGE_ERROR, msg); mrb_raise(mrb, E_RANGE_ERROR, msg);
} }
#endif #endif
...@@ -307,13 +307,13 @@ unpack_q(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un ...@@ -307,13 +307,13 @@ unpack_q(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un
if (flags & PACK_FLAG_SIGNED) { if (flags & PACK_FLAG_SIGNED) {
int64_t sll = ull; int64_t sll = ull;
if (!FIXABLE(sll)) { if (!FIXABLE(sll)) {
snprintf(msg, sizeof(msg), "cannot unpack to Fixnum: %lld", (long long)sll); snprintf(msg, sizeof(msg), "cannot unpack to Fixnum: %" PRId64, sll);
mrb_raise(mrb, E_RANGE_ERROR, msg); mrb_raise(mrb, E_RANGE_ERROR, msg);
} }
n = sll; n = sll;
} else { } else {
if (!POSFIXABLE(ull)) { if (!POSFIXABLE(ull)) {
snprintf(msg, sizeof(msg), "cannot unpack to Fixnum: %llu", (unsigned long long)ull); snprintf(msg, sizeof(msg), "cannot unpack to Fixnum: %" PRIu64, ull);
mrb_raise(mrb, E_RANGE_ERROR, msg); mrb_raise(mrb, E_RANGE_ERROR, msg);
} }
n = ull; n = ull;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment