--- C:/Users/will/AppData/Local/Temp/pack.c-rev43579.svn000.tmp.c Wed Jul 3 08:32:14 2013 +++ D:/rubyinstaller/downloads/ruby_2_1/pack.c Wed Jul 9 09:17:30 2014 @@ -2,7 +2,7 @@ pack.c - - $Author: akr $ + $Author: glass $ created at: Thu Feb 10 15:17:05 JST 1994 Copyright (C) 1993-2007 Yukihiro Matsumoto @@ -15,7 +15,9 @@ #include #include #include +#include + /* * It is intentional that the condition for natstr is HAVE_TRUE_LONG_LONG * instead of HAVE_LONG_LONG or LONG_LONG. @@ -946,20 +948,21 @@ static const char b64_table[] = static void encodes(VALUE str, const char *s, long len, int type, int tail_lf) { - char buff[4096]; + long bufLen = len + 128; // enough room + char* buff = (char*)malloc(bufLen); long i = 0; const char *trans = type == 'u' ? uu_table : b64_table; char padding; if (type == 'u') { - buff[i++] = (char)len + ' '; - padding = '`'; + buff[i++] = (char)len + ' '; + padding = '`'; } else { - padding = '='; + padding = '='; } while (len >= 3) { - while (len >= 3 && sizeof(buff)-i >= 4) { + while (len >= 3 && bufLen-i >= 4) { buff[i++] = trans[077 & (*s >> 2)]; buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))]; buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))]; @@ -967,7 +970,7 @@ encodes(VALUE str, const char *s, long len, int ty s += 3; len -= 3; } - if (sizeof(buff)-i < 4) { + if (bufLen-i < 4) { rb_str_buf_cat(str, buff, i); i = 0; } @@ -987,6 +990,7 @@ encodes(VALUE str, const char *s, long len, int ty } if (tail_lf) buff[i++] = '\n'; rb_str_buf_cat(str, buff, i); + free(buff); } static const char hex_table[] = "0123456789ABCDEF"; @@ -1798,12 +1802,13 @@ pack_unpack(VALUE str, VALUE fmt) s += sizeof(char *); if (t) { - VALUE a, *p, *pend; + VALUE a; + const VALUE *p, *pend; if (!(a = rb_str_associated(str))) { rb_raise(rb_eArgError, "no associated pointer"); } - p = RARRAY_PTR(a); + p = RARRAY_CONST_PTR(a); pend = p + RARRAY_LEN(a); while (p < pend) { if (RB_TYPE_P(*p, T_STRING) && RSTRING_PTR(*p) == t) { @@ -1840,12 +1845,13 @@ pack_unpack(VALUE str, VALUE fmt) s += sizeof(char *); if (t) { - VALUE a, *p, *pend; + VALUE a; + const VALUE *p, *pend; if (!(a = rb_str_associated(str))) { rb_raise(rb_eArgError, "no associated pointer"); } - p = RARRAY_PTR(a); + p = RARRAY_CONST_PTR(a); pend = p + RARRAY_LEN(a); while (p < pend) { if (RB_TYPE_P(*p, T_STRING) && RSTRING_PTR(*p) == t) {