aboutsummaryrefslogtreecommitdiffstats
path: root/pack.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-04 13:27:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-04 13:27:01 +0000
commitde79761ef614dbec200afb0a00694a90c23e9222 (patch)
treeb5d746c3cf290efef0e59408531cf91147512a3a /pack.c
parent43b0066d2bbaecb5a8d342eabe74970ce6aedf42 (diff)
downloadruby-de79761ef614dbec200afb0a00694a90c23e9222.tar.gz
pack.c (encodes): name a magic number
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'pack.c')
-rw-r--r--pack.c12
1 files 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);