From de79761ef614dbec200afb0a00694a90c23e9222 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 4 Aug 2014 13:27:01 +0000 Subject: pack.c (encodes): name a magic number git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- pack.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pack.c b/pack.c index 80ffef5930..74637adca4 100644 --- a/pack.c +++ b/pack.c @@ -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); -- cgit v1.2.3