OSDN Git Service

2000-06-06 Jakub Jelinek <jakub@redhat.com>
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 7 Jun 2000 22:27:57 +0000 (22:27 +0000)
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 7 Jun 2000 22:27:57 +0000 (22:27 +0000)
* cpplib.c (do_ifdef, do_ifndef): Don't segfault if parse_ifdef
returned NULL.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@34448 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/cpplib.c
gcc/testsuite/gcc.dg/cpp-if5.c [new file with mode: 0644]

index 7906c8d..4aac5bb 100644 (file)
@@ -1,3 +1,8 @@
+2000-06-06  Jakub Jelinek  <jakub@redhat.com>
+
+       * cpplib.c (do_ifdef, do_ifndef): Don't segfault if parse_ifdef
+       returned NULL.
+
 Wed Jun  7 20:34:33 2000  Denis Chertykov  <denisc@overta.ru>
 
        * config/avr/avr.c (asm_output_section_name): output section
index 529d1bb..60dfbdd 100644 (file)
@@ -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 (file)
index 0000000..2eac73b
--- /dev/null
@@ -0,0 +1,12 @@
+/* Regression test: #ifdef 0 should not crash.  Problem noted by
+   Jakub Jelinek <jakub@redhat.com>.  */
+/* { 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