aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-08-08 06:18:42 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-08-08 15:36:51 +0200
commitaa198d93e6a28bd8c040d82a00a9256d97d61516 (patch)
treededb5031f9590ce041a847229f39be076057ef9d
parente1578773182e8f69c3a0cd8add8dfbe7561a8240 (diff)
downloadsparse-aa198d93e6a28bd8c040d82a00a9256d97d61516.tar.gz
wstring: add support for evaluation of wide string
Evaluation doesn't know about wide strings. Fix this by: 1) selecting the right base type (char_ctype vs wchar_ctype) 2) adapting the type, size & alignment of the underlying array to this base type. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--evaluate.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/evaluate.c b/evaluate.c
index dddea761..acad11ab 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -102,9 +102,10 @@ static struct symbol *evaluate_string(struct expression *expr)
struct expression *addr = alloc_expression(expr->pos, EXPR_SYMBOL);
struct expression *initstr = alloc_expression(expr->pos, EXPR_STRING);
unsigned int length = expr->string->length;
+ struct symbol *char_type = expr->wide ? wchar_ctype : &char_ctype;
sym->array_size = alloc_const_expression(expr->pos, length);
- sym->bit_size = bytes_to_bits(length);
+ sym->bit_size = length * char_type->bit_size;
sym->ctype.alignment = 1;
sym->string = 1;
sym->ctype.modifiers = MOD_STATIC;
@@ -117,10 +118,10 @@ static struct symbol *evaluate_string(struct expression *expr)
initstr->string = expr->string;
array->array_size = sym->array_size;
- array->bit_size = bytes_to_bits(length);
- array->ctype.alignment = 1;
+ array->bit_size = sym->bit_size;
+ array->ctype.alignment = char_type->ctype.alignment;
array->ctype.modifiers = MOD_STATIC;
- array->ctype.base_type = &char_ctype;
+ array->ctype.base_type = char_type;
array->examined = 1;
array->evaluated = 1;