C++ PATCH: check catch parameter

Nathan Sidwell nathan@acm.org
Mon Jun 7 07:38:00 GMT 1999


Hi,
We currently don't validate the type of a catch parameter, (it cannot be
incomplete or pointer/ref to incomplete other than cv void) and hence either
accept bogus code, or die trying.

Similarly to my recent patch to build_throw, this checks
process_start_catch_block.

Ok to install?

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
        I have seen the death of PhotoShop -- it is called GIMP
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk
1999-06-06  Nathan Sidwell  <nathan@acm.org>

	* except.c (process_start_catch_block): Validate catch parameter type.

*** ../mainline/egcs/gcc/cp/except.c	Fri Jun  4 09:25:05 1999
--- egcs/gcc/cp/except.c	Sun Jun  6 23:35:10 1999
*************** process_start_catch_block (declspecs, de
*** 625,630 ****
--- 629,657 ----
  
        if (decl == NULL_TREE)
  	error ("invalid catch parameter");
+       else
+         {
+           tree t = TREE_TYPE (decl);
+   
+           /* Cannot throw an incomplete type. */
+           if (!complete_type_or_else (t, NULL_TREE))
+             decl = NULL_TREE;
+           else
+             {
+               /* Or a pointer or ref to one, other than cv void *.  */
+               int is_ptr = TREE_CODE (t) == POINTER_TYPE;
+               if (is_ptr || TREE_CODE (t) == REFERENCE_TYPE)
+                 {
+                   t = TREE_TYPE (t);
+                   
+                   if (is_ptr && same_type_p (TYPE_MAIN_VARIANT (t),
+                                              void_type_node))
+                     /* OK */;
+                   else if (!complete_type_or_else (t, NULL_TREE))
+                     decl = NULL_TREE;
+                 }
+             }
+         }
      }
  
    if (decl)


More information about the Gcc-patches mailing list