linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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: Thu, 23 May 2013 08:28:02 -0700	[thread overview]
Message-ID: <519E3582.7060704@gmail.com> (raw)
In-Reply-To: <519A6EAD.8070700@ramsay1.demon.co.uk>

[-- Attachment #1: Type: text/plain, Size: 390 bytes --]

On 05/20/2013 11:42 AM, Ramsay Jones wrote:

> Unfortunately not. :(

Sorry about that.

>         const char *paths[] = { path, NULL };

I see where I make the mistake. I need to drop the parentheses
only for char type. Can you please try this patch again? It is a
replacement patch of your patch No3. Not a delta. It works for the
the test case above.

Let's hope this one works.

Chris


[-- Attachment #2: 0001-symbol.c-Set-correct-size-of-array-from-parenthesize.patch --]
[-- Type: text/x-patch, Size: 2824 bytes --]

From 5a3bd40c1e9976c0896ad2d198e202a515dcf194 Mon Sep 17 00:00:00 2001
From: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Date: Thu, 16 May 2013 20:44:11 +0100
Subject: [PATCH] symbol.c: Set correct size of array from parenthesized string
 initializer

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Christopher Li <sparse@chrisli.org>
---
 symbol.c                      | 30 ++++++++++++++++++++++++++----
 validation/init-char-array1.c | 27 +++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 4 deletions(-)
 create mode 100644 validation/init-char-array1.c

diff --git a/symbol.c b/symbol.c
index 80a2f23..2ec6200 100644
--- a/symbol.c
+++ b/symbol.c
@@ -296,9 +296,21 @@ 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;
+				if (is_char) {
+					while (e && e->type == EXPR_PREOP && e->op == '(')
+						e = e->unop;
+					if (e && e->type == EXPR_STRING) {
+						entry = e;
 			case EXPR_STRING:
-				if (is_char)
-					str_len = entry->string->length;
+						if (is_char)
+							str_len = entry->string->length;
+					}
+
+
+				}
+			}
 			default:
 				nr++;
 			}
@@ -307,9 +319,19 @@ static int count_array_initializer(struct symbol *t, struct expression *expr)
 			nr = str_len;
 		break;
 	}
+	case EXPR_PREOP:
+		if (is_char) { 
+			struct expression *e = expr;
+			while (e && e->type == EXPR_PREOP && e->op == '(')
+				e = e->unop;
+			if (e && e->type == EXPR_STRING) {
+				expr = e;
 	case EXPR_STRING:
-		if (is_char)
-			nr = expr->string->length;
+				if (is_char)
+					nr = expr->string->length;
+			}
+		}
+		break;
 	default:
 		break;
 	}
diff --git a/validation/init-char-array1.c b/validation/init-char-array1.c
new file mode 100644
index 0000000..24fd8d8
--- /dev/null
+++ b/validation/init-char-array1.c
@@ -0,0 +1,27 @@
+/*
+ * for array of char, ("...") as the initializer is an gcc language
+ * extension. check that a parenthesized string initializer is handled
+ * correctly and that -Wparen-string warns about it's use.
+ */
+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";
+
+static void f(void)
+{
+	char a[1/(sizeof(u) == 6)];
+	char b[1/(sizeof(v) == 6)];
+	char c[1/(sizeof(w) == 6)];
+	char d[1/(sizeof(x) == 5)];
+}
+/*
+ * check-name: parenthesized string initializer
+ * check-command: sparse -Wparen-string $file
+ *
+ * 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
+ */
-- 
1.8.1.4


  reply	other threads:[~2013-05-23 15:28 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
2013-05-20 18:42     ` Ramsay Jones
2013-05-23 15:28       ` Chris Li [this message]
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=519E3582.7060704@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 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).