diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-02-11 14:01:11 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-02-11 14:01:11 -0500 |
| commit | f7173f4f081bdc200732cc9f7d58d3d54f9b0205 (patch) | |
| tree | 88a20049672953760a86f463fbf9a335cdc6346c /src/analyze.cpp | |
| parent | 39287d7346436a87ce785866befa77351bf2fc85 (diff) | |
| download | zig-f7173f4f081bdc200732cc9f7d58d3d54f9b0205.tar.gz zig-f7173f4f081bdc200732cc9f7d58d3d54f9b0205.zip | |
fix crash on string literal with character code >= 128
See #258
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index efa3cde333..53004d402e 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3038,7 +3038,7 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) { ConstExprValue *this_char = &const_val->data.x_array.elements[i]; this_char->special = ConstValSpecialStatic; this_char->type = g->builtin_types.entry_u8; - bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]); + bignum_init_unsigned(&this_char->data.x_bignum, (uint8_t)buf_ptr(str)[i]); } } @@ -3059,7 +3059,7 @@ void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) { ConstExprValue *this_char = &array_val->data.x_array.elements[i]; this_char->special = ConstValSpecialStatic; this_char->type = g->builtin_types.entry_u8; - bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]); + bignum_init_unsigned(&this_char->data.x_bignum, (uint8_t)buf_ptr(str)[i]); } ConstExprValue *null_char = &array_val->data.x_array.elements[len_with_null - 1]; null_char->special = ConstValSpecialStatic; @@ -3594,11 +3594,13 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) { buf_append_char(buf, '"'); for (uint64_t i = 0; i < len; i += 1) { ConstExprValue *child_value = &const_val->data.x_array.elements[i]; - uint64_t x = child_value->data.x_bignum.data.x_uint; - if (x == '"') { + uint64_t big_c = child_value->data.x_bignum.data.x_uint; + assert(big_c <= UINT8_MAX); + uint8_t c = big_c; + if (c == '"') { buf_append_str(buf, "\\\""); } else { - buf_append_char(buf, x); + buf_append_char(buf, c); } } buf_append_char(buf, '"'); |
