* pack.c (pack_unpack): Add casts for char references for 'u'.
Fix line ending recognition algorithm. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
50650bb338
commit
108627d911
@ -1,3 +1,8 @@
|
|||||||
|
Fri Oct 17 22:47:11 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* pack.c (pack_unpack): Add casts for char references for 'u'.
|
||||||
|
Fix line ending recognition algorithm.
|
||||||
|
|
||||||
Fri Oct 17 21:49:52 2014 Tanaka Akira <akr@fsij.org>
|
Fri Oct 17 21:49:52 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* pack.c (pack_unpack): Add casts for char references for 'b' and 'h'.
|
* pack.c (pack_unpack): Add casts for char references for 'b' and 'h'.
|
||||||
|
32
pack.c
32
pack.c
@ -1612,12 +1612,12 @@ pack_unpack(VALUE str, VALUE fmt)
|
|||||||
char *ptr = RSTRING_PTR(buf);
|
char *ptr = RSTRING_PTR(buf);
|
||||||
long total = 0;
|
long total = 0;
|
||||||
|
|
||||||
while (s < send && *s > ' ' && *s < 'a') {
|
while (s < send && (unsigned char)*s > ' ' && (unsigned char)*s < 'a') {
|
||||||
long a,b,c,d;
|
long a,b,c,d;
|
||||||
char hunk[4];
|
char hunk[3];
|
||||||
|
|
||||||
|
len = ((unsigned char)*s++ - ' ') & 077;
|
||||||
|
|
||||||
hunk[3] = '\0';
|
|
||||||
len = (*s++ - ' ') & 077;
|
|
||||||
total += len;
|
total += len;
|
||||||
if (total > RSTRING_LEN(buf)) {
|
if (total > RSTRING_LEN(buf)) {
|
||||||
len -= total - RSTRING_LEN(buf);
|
len -= total - RSTRING_LEN(buf);
|
||||||
@ -1627,20 +1627,20 @@ pack_unpack(VALUE str, VALUE fmt)
|
|||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
long mlen = len > 3 ? 3 : len;
|
long mlen = len > 3 ? 3 : len;
|
||||||
|
|
||||||
if (s < send && *s >= ' ')
|
if (s < send && (unsigned char)*s >= ' ' && (unsigned char)*s < 'a')
|
||||||
a = (*s++ - ' ') & 077;
|
a = ((unsigned char)*s++ - ' ') & 077;
|
||||||
else
|
else
|
||||||
a = 0;
|
a = 0;
|
||||||
if (s < send && *s >= ' ')
|
if (s < send && (unsigned char)*s >= ' ' && (unsigned char)*s < 'a')
|
||||||
b = (*s++ - ' ') & 077;
|
b = ((unsigned char)*s++ - ' ') & 077;
|
||||||
else
|
else
|
||||||
b = 0;
|
b = 0;
|
||||||
if (s < send && *s >= ' ')
|
if (s < send && (unsigned char)*s >= ' ' && (unsigned char)*s < 'a')
|
||||||
c = (*s++ - ' ') & 077;
|
c = ((unsigned char)*s++ - ' ') & 077;
|
||||||
else
|
else
|
||||||
c = 0;
|
c = 0;
|
||||||
if (s < send && *s >= ' ')
|
if (s < send && (unsigned char)*s >= ' ' && (unsigned char)*s < 'a')
|
||||||
d = (*s++ - ' ') & 077;
|
d = ((unsigned char)*s++ - ' ') & 077;
|
||||||
else
|
else
|
||||||
d = 0;
|
d = 0;
|
||||||
hunk[0] = (char)(a << 2 | b >> 4);
|
hunk[0] = (char)(a << 2 | b >> 4);
|
||||||
@ -1650,10 +1650,10 @@ pack_unpack(VALUE str, VALUE fmt)
|
|||||||
ptr += mlen;
|
ptr += mlen;
|
||||||
len -= mlen;
|
len -= mlen;
|
||||||
}
|
}
|
||||||
if (*s == '\r') s++;
|
if (s < send && (unsigned char)*s != '\r' && *s != '\n')
|
||||||
if (*s == '\n') s++;
|
s++; /* possible checksum byte */
|
||||||
else if (s < send && (s+1 == send || s[1] == '\n'))
|
if (s < send && *s == '\r') s++;
|
||||||
s += 2; /* possible checksum byte */
|
if (s < send && *s == '\n') s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_str_set_len(buf, total);
|
rb_str_set_len(buf, total);
|
||||||
|
@ -526,6 +526,11 @@ EXPECTED
|
|||||||
assert_equal(["a"*46], "M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n!80``\n".unpack("u"))
|
assert_equal(["a"*46], "M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A\n!80``\n".unpack("u"))
|
||||||
assert_equal(["abcdefghi"], "&86)C9&5F\n#9VAI\n".unpack("u"))
|
assert_equal(["abcdefghi"], "&86)C9&5F\n#9VAI\n".unpack("u"))
|
||||||
|
|
||||||
|
assert_equal(["abcdef"], "#86)C\n#9&5F\n".unpack("u"))
|
||||||
|
assert_equal(["abcdef"], "#86)CX\n#9&5FX\n".unpack("u")) # X is a (dummy) checksum.
|
||||||
|
assert_equal(["abcdef"], "#86)C\r\n#9&5F\r\n".unpack("u"))
|
||||||
|
assert_equal(["abcdef"], "#86)CX\r\n#9&5FX\r\n".unpack("u")) # X is a (dummy) checksum.
|
||||||
|
|
||||||
assert_equal(["\x00"], "\"\n".unpack("u"))
|
assert_equal(["\x00"], "\"\n".unpack("u"))
|
||||||
assert_equal(["\x00"], "! \r \n".unpack("u"))
|
assert_equal(["\x00"], "! \r \n".unpack("u"))
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user