aboutsummaryrefslogtreecommitdiffstats
path: root/pack.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-16 00:25:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-16 00:25:54 +0000
commit027cf467a4d093275b9c18fe694337765ff00213 (patch)
treed6a0abc2d887a4d5acd0dd2eeee5963aa712ee37 /pack.c
parent6a6d03791b53d5363a2b09cde3847f4992dbe53c (diff)
downloadruby-027cf467a4d093275b9c18fe694337765ff00213.tar.gz
pack.c: refine warning
* pack.c (unknown_directive): refine warning message at unknown directive in unpack too, and quote unprintable characters. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'pack.c')
-rw-r--r--pack.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/pack.c b/pack.c
index bccd503957..7a1a425cee 100644
--- a/pack.c
+++ b/pack.c
@@ -127,6 +127,27 @@ str_associated(VALUE str)
return rb_ivar_lookup(str, id_associated, Qfalse);
}
+static void
+unknown_directive(const char *mode, char type, VALUE fmt)
+{
+ VALUE f;
+ char unknown[5];
+
+ if (ISPRINT(type)) {
+ unknown[0] = type;
+ unknown[1] = '\0';
+ }
+ else {
+ snprintf(unknown, sizeof(unknown), "\\x%.2x", type & 0xff);
+ }
+ f = rb_str_quote_unprintable(fmt);
+ if (f != fmt) {
+ fmt = rb_str_subseq(f, 1, RSTRING_LEN(f) - 2);
+ }
+ rb_warning("unknown %s directive '%s' in '%"PRIsVALUE"'",
+ mode, unknown, fmt);
+}
+
/*
* call-seq:
* arr.pack( aTemplateString ) -> aBinaryString
@@ -849,16 +870,7 @@ pack_pack(int argc, VALUE *argv, VALUE ary)
break;
default: {
- char unknown[5];
- if (ISPRINT(type)) {
- unknown[0] = type;
- unknown[1] = '\0';
- }
- else {
- snprintf(unknown, sizeof(unknown), "\\x%.2x", type & 0xff);
- }
- rb_warning("unknown pack directive '%s' in '% "PRIsVALUE"'",
- unknown, fmt);
+ unknown_directive("pack", type, fmt);
break;
}
}
@@ -1748,8 +1760,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, int mode)
break;
default:
- rb_warning("unknown unpack directive '%c' in '%s'",
- type, RSTRING_PTR(fmt));
+ unknown_directive("unpack", type, fmt);
break;
}
}