[PATCH 3/6] wstring: add support for examination of string initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The examination of a string initializer doesn't know about wide
strings. The only thing needed is if the base type is some kind
of char but for wide chars, this type is the same as 'int' and
an array of ints can't be treated the same as an array of chars.

So, do the detection for wide string initializers as:
1) check that the LHS base type is wchar_ctype
2) check that the RHS is a kind of string expression
   (possibly between braces or parenthesis, recursively).

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 symbol.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/symbol.c b/symbol.c
index 6fcb1b150d27..7f0c85580f06 100644
--- a/symbol.c
+++ b/symbol.c
@@ -307,6 +307,29 @@ void merge_type(struct symbol *sym, struct symbol *base_type)
 		merge_type(sym, sym->ctype.base_type);
 }
 
+static bool is_wstring_expr(struct expression *expr)
+{
+	while (expr) {
+		switch (expr->type) {
+		case EXPR_STRING:
+			return 1;
+		case EXPR_INITIALIZER:
+			if (expression_list_size(expr->expr_list) != 1)
+				return 0;
+			expr = first_expression(expr->expr_list);
+			break;
+		case EXPR_PREOP:
+			if (expr->op == '(') {
+				expr = expr->unop;
+				break;
+			}
+		default:
+			return 0;
+		}
+	}
+	return 0;
+}
+
 static int count_array_initializer(struct symbol *t, struct expression *expr)
 {
 	int nr = 0;
@@ -321,6 +344,8 @@ static int count_array_initializer(struct symbol *t, struct expression *expr)
 	 */
 	if (t->ctype.base_type == &int_type && t->rank == -2)
 		is_char = 1;
+	else if (t == wchar_ctype && is_wstring_expr(expr))
+		is_char = 1;
 
 	switch (expr->type) {
 	case EXPR_INITIALIZER: {
-- 
2.28.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux