From 5af7e2c2e1949e500d44d78d25f98cd3cfdf3e3c Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 8 Jun 2000 00:27:57 +0200 Subject: [PATCH] cpplib.c (do_ifdef, do_ifndef): Don't segfault if parse_ifdef returned NULL. 2000-06-06 Jakub Jelinek * cpplib.c (do_ifdef, do_ifndef): Don't segfault if parse_ifdef returned NULL. From-SVN: r34448 --- gcc/ChangeLog | 5 +++++ gcc/cpplib.c | 23 ++++++++++++++--------- gcc/testsuite/gcc.dg/cpp-if5.c | 12 ++++++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/cpp-if5.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7906c8dcc72..4aac5bb6f8c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2000-06-06 Jakub Jelinek + + * cpplib.c (do_ifdef, do_ifndef): Don't segfault if parse_ifdef + returned NULL. + Wed Jun 7 20:34:33 2000 Denis Chertykov * config/avr/avr.c (asm_output_section_name): output section diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 529d1bb349f..60dfbdd2c27 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -1126,10 +1126,13 @@ do_ifdef (pfile) { int def = 0; const cpp_hashnode *node = parse_ifdef (pfile, dtable[T_IFDEF].name); - if (node->type == T_POISON) - cpp_error (pfile, "attempt to use poisoned `%s'", node->name); - else - def = (node->type != T_VOID); + if (node) + { + if (node->type == T_POISON) + cpp_error (pfile, "attempt to use poisoned `%s'", node->name); + else + def = (node->type != T_VOID); + } push_conditional (pfile, !def, T_IFDEF, 0); return 0; } @@ -1147,11 +1150,13 @@ do_ifndef (pfile) start_of_file = pfile->only_seen_white == 2; cmacro = parse_ifdef (pfile, dtable[T_IFNDEF].name); - if (cmacro->type == T_POISON) - cpp_error (pfile, "attempt to use poisoned `%s'", cmacro->name); - else - def = (cmacro->type != T_VOID); - + if (cmacro) + { + if (cmacro->type == T_POISON) + cpp_error (pfile, "attempt to use poisoned `%s'", cmacro->name); + else + def = (cmacro->type != T_VOID); + } push_conditional (pfile, def, T_IFNDEF, start_of_file ? cmacro : 0); return 0; diff --git a/gcc/testsuite/gcc.dg/cpp-if5.c b/gcc/testsuite/gcc.dg/cpp-if5.c new file mode 100644 index 00000000000..2eac73b6132 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp-if5.c @@ -0,0 +1,12 @@ +/* Regression test: #ifdef 0 should not crash. Problem noted by + Jakub Jelinek . */ +/* { dg-do preprocess } */ + +#ifdef 0 /* { dg-error "with invalid argument" } */ +#error not seen +#endif + +#ifndef 0 /* { dg-error "with invalid argument" } */ +#else +#error not seen +#endif -- 2.30.2