aboutsummaryrefslogtreecommitdiffstats
path: root/pack.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-06 14:58:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-06 14:58:43 +0000
commit1f53145dd467ebdb5d25a234f69d774ba0086afe (patch)
tree11fd401966c6af2024d4231a766a0f566ea5f973 /pack.c
parentfa892d27af38ef0685e944bf3a26390ef336b2ba (diff)
downloadruby-1f53145dd467ebdb5d25a234f69d774ba0086afe.tar.gz
pack.c: escape and encoding
* pack.c (pack_pack): escape unprintable characters and preserve the encoding of warning message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'pack.c')
-rw-r--r--pack.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/pack.c b/pack.c
index 937cbe28c1..728c1d1560 100644
--- a/pack.c
+++ b/pack.c
@@ -912,10 +912,19 @@ pack_pack(VALUE ary, VALUE fmt)
}
break;
- default:
- rb_warning("unknown pack directive '%c' in '%s'",
- type, RSTRING_PTR(fmt));
+ 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);
break;
+ }
}
}