authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-11 14:01:11-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-11 14:01:11-05:00
logf7173f4f081bdc200732cc9f7d58d3d54f9b0205
tree88a20049672953760a86f463fbf9a335cdc6346c
parent39287d7346436a87ce785866befa77351bf2fc85

fix crash on string literal with character code >= 128

See #258

2 files changed, 8 insertions(+), 6 deletions(-)

src/analyze.cpp+7-5
...@@ -3038,7 +3038,7 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {...@@ -3038,7 +3038,7 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
3038 ConstExprValue *this_char = &const_val->data.x_array.elements[i];3038 ConstExprValue *this_char = &const_val->data.x_array.elements[i];
3039 this_char->special = ConstValSpecialStatic;3039 this_char->special = ConstValSpecialStatic;
3040 this_char->type = g->builtin_types.entry_u8;3040 this_char->type = g->builtin_types.entry_u8;
3041 bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]);3041 bignum_init_unsigned(&this_char->data.x_bignum, (uint8_t)buf_ptr(str)[i]);
3042 }3042 }
3043}3043}
30443044
...@@ -3059,7 +3059,7 @@ void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {...@@ -3059,7 +3059,7 @@ void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
3059 ConstExprValue *this_char = &array_val->data.x_array.elements[i];3059 ConstExprValue *this_char = &array_val->data.x_array.elements[i];
3060 this_char->special = ConstValSpecialStatic;3060 this_char->special = ConstValSpecialStatic;
3061 this_char->type = g->builtin_types.entry_u8;3061 this_char->type = g->builtin_types.entry_u8;
3062 bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]);3062 bignum_init_unsigned(&this_char->data.x_bignum, (uint8_t)buf_ptr(str)[i]);
3063 }3063 }
3064 ConstExprValue *null_char = &array_val->data.x_array.elements[len_with_null - 1];3064 ConstExprValue *null_char = &array_val->data.x_array.elements[len_with_null - 1];
3065 null_char->special = ConstValSpecialStatic;3065 null_char->special = ConstValSpecialStatic;
...@@ -3594,11 +3594,13 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {...@@ -3594,11 +3594,13 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {
3594 buf_append_char(buf, '"');3594 buf_append_char(buf, '"');
3595 for (uint64_t i = 0; i < len; i += 1) {3595 for (uint64_t i = 0; i < len; i += 1) {
3596 ConstExprValue *child_value = &const_val->data.x_array.elements[i];3596 ConstExprValue *child_value = &const_val->data.x_array.elements[i];
3597 uint64_t x = child_value->data.x_bignum.data.x_uint;3597 uint64_t big_c = child_value->data.x_bignum.data.x_uint;
3598 if (x == '"') {3598 assert(big_c <= UINT8_MAX);
3599 uint8_t c = big_c;
3600 if (c == '"') {
3599 buf_append_str(buf, "\\\"");3601 buf_append_str(buf, "\\\"");
3600 } else {3602 } else {
3601 buf_append_char(buf, x);3603 buf_append_char(buf, c);
3602 }3604 }
3603 }3605 }
3604 buf_append_char(buf, '"');3606 buf_append_char(buf, '"');
std/io.zig+1-1
...@@ -156,7 +156,7 @@ pub const OutStream = struct {...@@ -156,7 +156,7 @@ pub const OutStream = struct {
156 width = 0;156 width = 0;
157 state = State.Integer;157 state = State.Integer;
158 },158 },
159 else => @compileError("Unknown format character: " ++ c),159 else => @compileError("Unknown format character: " ++ []u8{c}),
160 },160 },
161 State.CloseBrace => switch (c) {161 State.CloseBrace => switch (c) {
162 '}' => {162 '}' => {