nobu / ruby-lang.org wrote:
>   https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61386

rb_enc_find_index may raise, so ALLOCV should be safer;
(the allocation is bound at 101 bytes, even alloca is fine)

--- a/string.c
+++ b/string.c
@@ -6266,6 +6266,7 @@ str_undump(VALUE str)
 		char *buf;
 		int encidx;
 		ptrdiff_t size;
+		VALUE v;
 
 		if (utf8) {
 		    rb_raise(rb_eRuntimeError, "dumped string contained Unicode escape but used force_encoding");
@@ -6283,11 +6284,11 @@ str_undump(VALUE str)
 		if (size > 100) {
 		    rb_raise(rb_eRuntimeError, "dumped string has unknown encoding name");
 		}
-		buf = ALLOC_N(char, size+1);
+		buf = ALLOCV(v, size+1);
 		memcpy(buf, encname, size);
 		buf[size] = '\0';
 		encidx = rb_enc_find_index(buf);
-		xfree(buf);
+		ALLOCV_END(v);
 		if (encidx < 0) {
 		    rb_raise(rb_eRuntimeError, "dumped string has unknown encoding name");
 		}

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>