From 23b4c10dd8dcde2b955072ef0f014bb291866e89 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 13 Jan 2012 09:41:22 +0000 Subject: [PATCH] * sprintf.c (rb_enc_vsprintf): can be used for ASCII compatible encodings only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ sprintf.c | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index dade700f06..3f2b6a418f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Jan 13 18:41:19 2012 Nobuyoshi Nakada + + * sprintf.c (rb_enc_vsprintf): can be used for ASCII compatible + encodings only. + Fri Jan 13 18:29:06 2012 Nobuyoshi Nakada * thread.c (rb_mutex_unlock_th): simplified. diff --git a/sprintf.c b/sprintf.c index eb8cd73985..bae6c146ac 100644 --- a/sprintf.c +++ b/sprintf.c @@ -1168,7 +1168,13 @@ rb_enc_vsprintf(rb_encoding *enc, const char *fmt, va_list ap) f._bf._size = 0; f._w = 120; result = rb_str_buf_new(f._w); - if (enc) rb_enc_associate(result, enc); + if (enc) { + if (!rb_enc_asciicompat(enc)) { + rb_raise(rb_eArgError, "cannot construct ASCII-incompatible encoding string: %s", + rb_enc_name(enc)); + } + rb_enc_associate(result, enc); + } f._bf._base = (unsigned char *)result; f._p = (unsigned char *)RSTRING_PTR(result); RBASIC(result)->klass = 0;