[PATCH] fix zero/sign extension of integer character constants

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

 



From: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>

An integer character constant has type 'int' but, subtly enough,
its value is the one of a 'char' converted to an 'int'.

So, do this conversion.
Also set the type of wide character constants from 'long' to 'wchar_t'.

Link: https://lore.kernel.org/r/20210927130253.GH2083@kadam
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
Reported-by: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 expression.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/expression.c b/expression.c
index 221d7780a76e..e3b58cb5b653 100644
--- a/expression.c
+++ b/expression.c
@@ -427,8 +427,15 @@ struct token *primary_expression(struct token *token, struct expression **tree)
 	case TOKEN_CHAR ... TOKEN_WIDE_CHAR_EMBEDDED_3:
 		expr = alloc_expression(token->pos, EXPR_VALUE);
 		expr->flags = CEF_SET_CHAR;
-		expr->ctype = token_type(token) < TOKEN_WIDE_CHAR ? &int_ctype : &long_ctype;
 		get_char_constant(token, &expr->value);
+
+		// TODO: handle 'u8', 'u' & 'U' prefixes.
+		if (token_type(token) < TOKEN_WIDE_CHAR) {
+			expr->ctype = &int_ctype;
+			expr->value = extend_value(expr->value, &char_ctype);
+		} else {
+			expr->ctype = wchar_ctype;
+		}
 		token = token->next;
 		break;
 
-- 
2.36.1




[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