From: Oleg Nesterov <oleg@tv-sign.ru>
To: Linus Torvalds <torvalds@osdl.org>
Cc: linux-sparse@vger.kernel.org, Josh Triplett <josht@us.ibm.com>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH 3/4] fix (SIGSEGV) handle_define() on #weak_define
Date: Mon, 4 Sep 2006 19:41:57 +0400 [thread overview]
Message-ID: <20060904154157.GA6434@oleg> (raw)
This patch fixes 2 bugs in do_handle_define()
1.
do_handle_define:
...
if (sym->weak)
goto replace_it;
This is wrong, we should allocate a new symbol if
sym->scope != file_scope, example:
inc.h:
#weak_define FOO default
redefine.c:
#define FOO redefine
FOO
default.c:
FOO
$ ./test-lexing -include inc.h redefine.c default.c
redefine
Segmentation fault
2.
'#define' shouldn't inherit a weak attribute if the symbol
was previously weak_define'd. Example:
#weak_define FOO 1
#define FOO 1 // has no effect
#define FOO 2 // redefined without warning
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
--- git-snapshot-20060904/pre-process.c~3WEAK 2006-09-04 18:20:23.000000000 +0400
+++ git-snapshot-20060904/pre-process.c 2006-09-04 19:16:45.000000000 +0400
@@ -1061,6 +1061,7 @@ static int do_handle_define(struct strea
struct token *left = token->next;
struct symbol *sym;
struct ident *name;
+ int ret;
if (token_type(left) != TOKEN_IDENT) {
sparse_error(token->pos, "expected identifier to 'define'");
@@ -1082,35 +1083,43 @@ static int do_handle_define(struct strea
if (!expansion)
return 1;
+ ret = 1;
sym = lookup_macro(name);
- if (sym) {
- if (token_list_different(sym->expansion, expansion) ||
- token_list_different(sym->arglist, arglist)) {
- if (sym->weak)
- goto replace_it;
- if (weak)
- return 1;
- warning(left->pos, "preprocessor token %.*s redefined",
- name->len, name->name);
- info(sym->pos, "this was the original definition");
-
- /* Don't overwrite global defs */
- if (sym->scope != file_scope)
- goto allocate_new;
- goto replace_it;
- }
- return 1;
- }
-allocate_new:
- sym = alloc_symbol(left->pos, SYM_NODE);
- bind_symbol(sym, name, NS_MACRO);
-
-replace_it:
- sym->expansion = expansion;
- sym->arglist = arglist;
- sym->weak = weak;
- __free_token(token); /* Free the "define" token, but not the rest of the line */
- return 0;
+ if (sym) {
+ int clean;
+
+ if (weak > sym->weak)
+ goto out;
+
+ clean = (weak == sym->weak);
+
+ if (token_list_different(sym->expansion, expansion) ||
+ token_list_different(sym->arglist, arglist)) {
+ ret = 0;
+ if (clean && !weak) {
+ warning(left->pos, "preprocessor token %.*s redefined",
+ name->len, name->name);
+ info(sym->pos, "this was the original definition");
+ }
+ } else if (clean)
+ goto out;
+ }
+
+ if (!sym || sym->scope != file_scope) {
+ sym = alloc_symbol(left->pos, SYM_NODE);
+ bind_symbol(sym, name, NS_MACRO);
+ ret = 0;
+ }
+
+ if (!ret) {
+ sym->expansion = expansion;
+ sym->arglist = arglist;
+ __free_token(token); /* Free the "define" token, but not the rest of the line */
+ }
+
+ sym->weak = weak;
+out:
+ return ret;
}
static int handle_define(struct stream *stream, struct token **line, struct token *token)
--
VGER BF report: U 0.499562
reply other threads:[~2006-09-04 11:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20060904154157.GA6434@oleg \
--to=oleg@tv-sign.ru \
--cc=josht@us.ibm.com \
--cc=linux-sparse@vger.kernel.org \
--cc=torvalds@osdl.org \
--cc=viro@zeniv.linux.org.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.