summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-12 02:39:24 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-12 02:39:24 +0000
commit21e1260fb94f7d339ee60eedbba1975113ade7f1 (patch)
tree1a7302fafa10fbd9bd2628d4d65b3b17fc3dfd7f
parentbc7976f2c629e08262da404fa29f6ba6f4a46671 (diff)
char is neither signed nor unsigned
read_escaped_byte() returns values of range -1...256. -1 indicates error. So the function basically expects char to be 0..255 range. There is no such guarantee. `char` is not always unsigned. We need to explicitly declare chbuf to be unsigned char. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--re.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/re.c b/re.c
index ecb3c253cd..9223689b42 100644
--- a/re.c
+++ b/re.c
@@ -2389,7 +2389,8 @@ unescape_escaped_nonascii(const char **pp, const char *end, rb_encoding *enc,
{
const char *p = *pp;
int chmaxlen = rb_enc_mbmaxlen(enc);
- char *chbuf = ALLOCA_N(char, chmaxlen);
+ unsigned char *area = ALLOCA_N(unsigned char, chmaxlen);
+ char *chbuf = (char *)area;
int chlen = 0;
int byte;
int l;
@@ -2401,14 +2402,14 @@ unescape_escaped_nonascii(const char **pp, const char *end, rb_encoding *enc,
return -1;
}
- chbuf[chlen++] = byte;
+ area[chlen++] = byte;
while (chlen < chmaxlen &&
MBCLEN_NEEDMORE_P(rb_enc_precise_mbclen(chbuf, chbuf+chlen, enc))) {
byte = read_escaped_byte(&p, end, err);
if (byte == -1) {
return -1;
}
- chbuf[chlen++] = byte;
+ area[chlen++] = byte;
}
l = rb_enc_precise_mbclen(chbuf, chbuf+chlen, enc);
@@ -2416,7 +2417,7 @@ unescape_escaped_nonascii(const char **pp, const char *end, rb_encoding *enc,
errcpy(err, "invalid multibyte escape");
return -1;
}
- if (1 < chlen || (chbuf[0] & 0x80)) {
+ if (1 < chlen || (area[0] & 0x80)) {
rb_str_buf_cat(buf, chbuf, chlen);
if (*encp == 0)
@@ -2428,7 +2429,7 @@ unescape_escaped_nonascii(const char **pp, const char *end, rb_encoding *enc,
}
else {
char escbuf[5];
- snprintf(escbuf, sizeof(escbuf), "\\x%02X", chbuf[0]&0xff);
+ snprintf(escbuf, sizeof(escbuf), "\\x%02X", area[0]&0xff);
rb_str_buf_cat(buf, escbuf, 4);
}
*pp = p;