This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C++ PATCH: Robustify pointer-to-member error checking



We crashed on bogus pointer-to-member dereference operations, as 
in PR 196.

Fixed with this patch.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2001-02-15  Mark Mitchell  <mark@codesourcery.com>

	* typeck2.c (build_m_component_ref): Robustify.

Index: cp/typeck2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck2.c,v
retrieving revision 1.98
diff -c -p -r1.98 typeck2.c
*** typeck2.c	2001/02/12 15:09:00	1.98
--- typeck2.c	2001/02/16 01:19:42
*************** build_m_component_ref (datum, component)
*** 1093,1098 ****
--- 1093,1102 ----
      return build_min_nt (DOTSTAR_EXPR, datum, component);
  
    datum = decay_conversion (datum);
+ 
+   if (datum == error_mark_node || component == error_mark_node)
+     return error_mark_node;
+ 
    objtype = TYPE_MAIN_VARIANT (TREE_TYPE (datum));  
  
    if (TYPE_PTRMEMFUNC_P (TREE_TYPE (component)))
*************** build_m_component_ref (datum, component)
*** 1100,1117 ****
        type = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (component)));
        field_type = type;
      }
!   else
      {
        type = TREE_TYPE (TREE_TYPE (component));
        field_type = TREE_TYPE (type);
      }
! 
!   if (datum == error_mark_node || component == error_mark_node)
!     return error_mark_node;
! 
!   if (TREE_CODE (type) != OFFSET_TYPE && TREE_CODE (type) != METHOD_TYPE)
      {
!       cp_error ("`%E' cannot be used as a member pointer, since it is of type `%T'", component, type);
        return error_mark_node;
      }
  
--- 1104,1118 ----
        type = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (component)));
        field_type = type;
      }
!   else if (TYPE_PTRMEM_P (TREE_TYPE (component)))
      {
        type = TREE_TYPE (TREE_TYPE (component));
        field_type = TREE_TYPE (type);
      }
!   else
      {
!       cp_error ("`%E' cannot be used as a member pointer, since it is of type `%T'", 
! 		component, TREE_TYPE (component));
        return error_mark_node;
      }
  
Index: testsuite/g++.old-deja/g++.other/ptrmem6.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.other/ptrmem6.C,v
retrieving revision 1.1
diff -c -p -r1.1 ptrmem6.C
*** ptrmem6.C	2000/02/02 04:45:58	1.1
--- ptrmem6.C	2001/02/16 01:19:43
***************
*** 1,7 ****
  // Build don't link:
! // crash test - XFAIL *-*-*
  
! // Copyright (c) 2000 Free Software Foundation.
  // Distilled from a bug report by Eric Ford <eford@princeton.edu>
  
  extern double *y;
--- 1,7 ----
  // Build don't link:
! // crash test
  
! // Copyright (c) 2000, 2001 Free Software Foundation.
  // Distilled from a bug report by Eric Ford <eford@princeton.edu>
  
  extern double *y;
*************** void SetInitCond(void)
*** 12,16 ****
  {
    int i;
    for(i = 2; i < nPoints; ++i)
!     y[i] = y[nPoints] .* (x[i]-x[1]) / (x[nPoints]-x[1]);  // ERROR
  }
--- 12,16 ----
  {
    int i;
    for(i = 2; i < nPoints; ++i)
!     y[i] = y[nPoints] .* (x[i]-x[1]) / (x[nPoints]-x[1]);  // ERROR - .*
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]