mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
pack.c (encodes): name a magic number
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
43b0066d2b
commit
de79761ef6
1 changed files with 6 additions and 6 deletions
12
pack.c
12
pack.c
|
@ -945,10 +945,10 @@ static const char b64_table[] =
|
||||||
static void
|
static void
|
||||||
encodes(VALUE str, const char *s, long len, int type, int tail_lf)
|
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 */
|
char buff[buff_size + 1]; /* +1 for tail_lf */
|
||||||
long i = 0;
|
long i = 0;
|
||||||
const char *trans = type == 'u' ? uu_table : b64_table;
|
const char *const trans = type == 'u' ? uu_table : b64_table;
|
||||||
char padding;
|
char padding;
|
||||||
|
|
||||||
if (type == 'u') {
|
if (type == 'u') {
|
||||||
|
@ -958,14 +958,14 @@ encodes(VALUE str, const char *s, long len, int type, int tail_lf)
|
||||||
else {
|
else {
|
||||||
padding = '=';
|
padding = '=';
|
||||||
}
|
}
|
||||||
while (len >= 3) {
|
while (len >= input_unit) {
|
||||||
while (len >= 3 && buff_size-i >= encoded_unit) {
|
while (len >= input_unit && buff_size-i >= encoded_unit) {
|
||||||
buff[i++] = trans[077 & (*s >> 2)];
|
buff[i++] = trans[077 & (*s >> 2)];
|
||||||
buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
|
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[1] << 2) & 074) | ((s[2] >> 6) & 03))];
|
||||||
buff[i++] = trans[077 & s[2]];
|
buff[i++] = trans[077 & s[2]];
|
||||||
s += 3;
|
s += input_unit;
|
||||||
len -= 3;
|
len -= input_unit;
|
||||||
}
|
}
|
||||||
if (buff_size-i < encoded_unit) {
|
if (buff_size-i < encoded_unit) {
|
||||||
rb_str_buf_cat(str, buff, i);
|
rb_str_buf_cat(str, buff, i);
|
||||||
|
|
Loading…
Reference in a new issue