From: Luc Van Oostenryck <lucvoo@kernel.org>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>,
Dan Carpenter <dan.carpenter@oracle.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: [PATCH] fix zero/sign extension of integer character constants
Date: Sun, 22 May 2022 21:08:58 +0200 [thread overview]
Message-ID: <20220522190858.42163-1-lucvoo@kernel.org> (raw)
In-Reply-To: <78f6d6cc-2be5-c69b-bd17-7da135448438@rasmusvillemoes.dk>
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
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@oracle.com>
Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
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
prev parent reply other threads:[~2022-05-22 19:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210927094123.576521-1-arnd@kernel.org>
[not found] ` <40217483-1b8d-28ec-bbfc-8f979773b166@redhat.com>
2021-09-27 13:02 ` [PATCH] vboxsf: fix old signature detection Dan Carpenter
2021-09-27 13:21 ` Arnd Bergmann
2021-09-27 18:33 ` Linus Torvalds
2021-09-28 9:39 ` Hans de Goede
2021-09-28 10:11 ` Arnd Bergmann
2021-09-28 10:31 ` Hans de Goede
2021-09-28 10:40 ` Arnd Bergmann
2021-09-28 9:56 ` Rasmus Villemoes
2022-05-22 19:08 ` Luc Van Oostenryck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220522190858.42163-1-lucvoo@kernel.org \
--to=lucvoo@kernel.org \
--cc=dan.carpenter@oracle.com \
--cc=linux-sparse@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=luc.vanoostenryck@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).