diff options
Diffstat (limited to 'pack.c')
-rw-r--r-- | pack.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -945,10 +945,10 @@ static const char b64_table[] = static void encodes(VALUE str, const char *s, long len, int type, int tail_lf) { - enum {buff_size = 4096, encoded_unit = 4}; + enum {buff_size = 4096, encoded_unit = 4, input_unit = 3}; char buff[buff_size + 1]; /* +1 for tail_lf */ long i = 0; - const char *trans = type == 'u' ? uu_table : b64_table; + const char *const trans = type == 'u' ? uu_table : b64_table; char padding; if (type == 'u') { @@ -958,14 +958,14 @@ encodes(VALUE str, const char *s, long len, int type, int tail_lf) else { padding = '='; } - while (len >= 3) { - while (len >= 3 && buff_size-i >= encoded_unit) { + while (len >= input_unit) { + while (len >= input_unit && buff_size-i >= encoded_unit) { 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))]; buff[i++] = trans[077 & s[2]]; - s += 3; - len -= 3; + s += input_unit; + len -= input_unit; } if (buff_size-i < encoded_unit) { rb_str_buf_cat(str, buff, i); |