aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/evaluate.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-08-08 06:22:56 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-08-08 15:36:51 +0200
commita060d243f8dc17e399641b0dfebeb4faf5eb7580 (patch)
tree6a086284707033c6dd75a3c1d4b3baa32025ed26 /evaluate.c
parentaa198d93e6a28bd8c040d82a00a9256d97d61516 (diff)
downloadsparse-dev-a060d243f8dc17e399641b0dfebeb4faf5eb7580.tar.gz
wstring: add support for checking size in string initializer
A warning is given for string initializers if the LHS array is not large enough to contains the string. But this check doesn't knowns about wide strings. Fix this by selecting the correct char type and use this type for the size calculations. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'evaluate.c')
-rw-r--r--evaluate.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/evaluate.c b/evaluate.c
index acad11ab..bbfa77c3 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -2841,10 +2841,12 @@ String:
*p = *e;
type = evaluate_expression(p);
if (ctype->bit_size != -1) {
- if (ctype->bit_size + bits_in_char < type->bit_size)
+ struct symbol *char_type = e->wide ? wchar_ctype : &char_ctype;
+ unsigned int size_with_null = ctype->bit_size + char_type->bit_size;
+ if (size_with_null < type->bit_size)
warning(e->pos,
"too long initializer-string for array of char");
- else if (Winit_cstring && ctype->bit_size + bits_in_char == type->bit_size) {
+ else if (Winit_cstring && size_with_null == type->bit_size) {
warning(e->pos,
"too long initializer-string for array of char(no space for nul char)");
}