From: Chris Li <christ.li@gmail.com>
To: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Cc: Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH 3/3] symbol.c: Set correct size of array from parenthesized string initializer
Date: Sat, 18 May 2013 01:14:54 -0700 [thread overview]
Message-ID: <5197387E.5030000@gmail.com> (raw)
In-Reply-To: <51972FDB.6060201@chrisli.org>
[-- Attachment #1: Type: text/plain, Size: 245 bytes --]
On 05/18/2013 12:38 AM, Christopher Li wrote:
> I guess the rules is that parenthesized string can appear in
> any place where string was allowed.
I create an incremental patch to address the issue. Please
check if that works for you.
Chris
[-- Attachment #2: parenthesed-string-improve.patch --]
[-- Type: text/x-patch, Size: 2211 bytes --]
diff --git a/symbol.c b/symbol.c
index 051a909..a59a4ca 100644
--- a/symbol.c
+++ b/symbol.c
@@ -284,15 +284,6 @@ static int count_array_initializer(struct symbol *t, struct expression *expr)
if (t->ctype.base_type == &int_type && t->ctype.modifiers & MOD_CHAR)
is_char = 1;
- /* check for a parenthesized string: char x[] = ("string"); */
- if (is_char && expr->type == EXPR_PREOP && expr->op == '(') {
- struct expression *e = expr;
- while (e && e->type == EXPR_PREOP && e->op == '(')
- e = e->unop;
- if (e && e->type == EXPR_STRING)
- expr = e;
- }
-
switch (expr->type) {
case EXPR_INITIALIZER: {
struct expression *entry;
@@ -305,6 +296,15 @@ static int count_array_initializer(struct symbol *t, struct expression *expr)
if (entry->idx_to >= nr)
nr = entry->idx_to+1;
break;
+ case EXPR_PREOP: {
+ struct expression *e = entry;
+ while (e && e->type == EXPR_PREOP && e->op == '(')
+ e = e->unop;
+ if (!(e && e->type == EXPR_STRING))
+ break;
+ entry = e;
+ /* fall through to strings. */
+ }
case EXPR_STRING:
if (is_char)
str_len = entry->string->length;
@@ -316,6 +316,15 @@ static int count_array_initializer(struct symbol *t, struct expression *expr)
nr = str_len;
break;
}
+ case EXPR_PREOP: {
+ struct expression *e = expr;
+ while (e && e->type == EXPR_PREOP && e->op == '(')
+ e = e->unop;
+ if (!(e && e->type == EXPR_STRING))
+ break;
+ expr = e;
+ /* fall through to strings. */
+ }
case EXPR_STRING:
if (is_char)
nr = expr->string->length;
diff --git a/validation/init-char-array1.c b/validation/init-char-array1.c
index 7427702..24fd8d8 100644
--- a/validation/init-char-array1.c
+++ b/validation/init-char-array1.c
@@ -5,6 +5,7 @@
*/
static const char u[] = ("hello");
static const char v[] = {"hello"};
+static const char v1[] = {("hello")};
static const char w[] = "hello";
static const char x[5] = "hello";
@@ -21,5 +22,6 @@ static void f(void)
*
* check-error-start
init-char-array1.c:6:26: warning: array initialized from parenthesized string constant
+init-char-array1.c:8:28: warning: array initialized from parenthesized string constant
* check-error-end
*/
next prev parent reply other threads:[~2013-05-18 8:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-16 19:44 [PATCH 3/3] symbol.c: Set correct size of array from parenthesized string initializer Ramsay Jones
2013-05-18 7:38 ` Christopher Li
2013-05-18 8:14 ` Chris Li [this message]
2013-05-20 18:42 ` Ramsay Jones
2013-05-23 15:28 ` Chris Li
2013-05-25 20:01 ` Ramsay Jones
2013-05-29 10:02 ` Chris Li
2013-06-01 17:42 ` Ramsay Jones
2013-05-20 18:37 ` Ramsay Jones
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=5197387E.5030000@gmail.com \
--to=christ.li@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=ramsay@ramsay1.demon.co.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.