Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] jv-lang, guard against NULL
@ 2007-07-31 23:29 msnyder
  2007-08-02 21:06 ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: msnyder @ 2007-07-31 23:29 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2: 255.txt --]
[-- Type: text/plain, Size: 955 bytes --]

2007-07-31  Michael Snyder  <msnyder@access-company.com>

	* jv-lang.c (java_link_class_type): Guard against NULL.

Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.47
diff -p -r1.47 jv-lang.c
*** jv-lang.c	13 Jun 2007 17:30:01 -0000	1.47
--- jv-lang.c	31 Jul 2007 23:23:06 -0000
*************** java_link_class_type (struct type *type,
*** 407,414 ****
  	SET_TYPE_FIELD_PRIVATE (type, 0);
      }
  
!   i = strlen (name);
!   if (i > 2 && name[i - 1] == ']' && tsuper != NULL)
      {
        /* FIXME */
        TYPE_LENGTH (type) = TYPE_LENGTH (tsuper) + 4;	/* size with "length" */
--- 407,414 ----
  	SET_TYPE_FIELD_PRIVATE (type, 0);
      }
  
!   if (name != NULL && (i = strlen (name)) > 2 
!       && name[i - 1] == ']' && tsuper != NULL)
      {
        /* FIXME */
        TYPE_LENGTH (type) = TYPE_LENGTH (tsuper) + 4;	/* size with "length" */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] jv-lang, guard against NULL
  2007-07-31 23:29 [PATCH] jv-lang, guard against NULL msnyder
@ 2007-08-02 21:06 ` Daniel Jacobowitz
       [not found]   ` <655C3D4066B7954481633935A40BB36F22BA4C@ussunex02.svl.access-company.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2007-08-02 21:06 UTC (permalink / raw)
  To: gdb-patches

On Tue, Jul 31, 2007 at 04:25:12PM -0700, Michael Snyder wrote:
> !   if (name != NULL && (i = strlen (name)) > 2 
> !       && name[i - 1] == ']' && tsuper != NULL)

Can we avoid assignments inside the if statement?  Also, there's an
unprotected call to strrchr above.  Maybe this should be an assert
instead, at the top of the function.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: FW: [PATCH] jv-lang, guard against NULL
       [not found]     ` <655C3D4066B7954481633935A40BB36F22BA4C@ussunex02.svl.access-company.c      om>
@ 2007-08-02 21:30       ` msnyder
  2007-08-02 21:37         ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: msnyder @ 2007-08-02 21:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: drow

[-- Attachment #1: Type: text/plain, Size: 651 bytes --]


>
> On Tue, Jul 31, 2007 at 04:25:12PM -0700, Michael Snyder wrote:
>> !   if (name != NULL && (i = strlen (name)) > 2
>> !       && name[i - 1] == ']' && tsuper != NULL)
>
> Can we avoid assignments inside the if statement?

Yeah, I tried, but it ended up looking really awkward.
Test 'name', then do the strlen, then test name again.

> Also, there's an
> unprotected call to strrchr above.  Maybe this should be an assert
> instead, at the top of the function.

Good idea -- except, can we really be sure that name can
never legitimately be null?  Oh, yeah, I guess the unprotected
strrchr sort of tells us that, doesn't it?

OK, how about this?


[-- Attachment #2: 255b.txt --]
[-- Type: text/plain, Size: 1403 bytes --]

2007-07-31  Michael Snyder  <msnyder@access-company.com>

	* jv-lang.c (java_link_class_type): Guard against NULL.

Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.47
diff -p -r1.47 jv-lang.c
*** jv-lang.c	13 Jun 2007 17:30:01 -0000	1.47
--- jv-lang.c	2 Aug 2007 21:29:07 -0000
*************** java_link_class_type (struct type *type,
*** 351,363 ****
    struct objfile *objfile = get_dynamics_objfile ();
    struct type *tsuper;
  
    unqualified_name = strrchr (name, '.');
    if (unqualified_name == NULL)
      unqualified_name = name;
  
    temp = clas;
    temp = value_struct_elt (&temp, NULL, "superclass", NULL, "structure");
!   if (name != NULL && strcmp (name, "java.lang.Object") == 0)
      {
        tsuper = get_java_object_type ();
        if (tsuper && TYPE_CODE (tsuper) == TYPE_CODE_PTR)
--- 351,364 ----
    struct objfile *objfile = get_dynamics_objfile ();
    struct type *tsuper;
  
+   gdb_assert (name != NULL);
    unqualified_name = strrchr (name, '.');
    if (unqualified_name == NULL)
      unqualified_name = name;
  
    temp = clas;
    temp = value_struct_elt (&temp, NULL, "superclass", NULL, "structure");
!   if (strcmp (name, "java.lang.Object") == 0)
      {
        tsuper = get_java_object_type ();
        if (tsuper && TYPE_CODE (tsuper) == TYPE_CODE_PTR)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: FW: [PATCH] jv-lang, guard against NULL
  2007-08-02 21:30       ` FW: " msnyder
@ 2007-08-02 21:37         ` Daniel Jacobowitz
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2007-08-02 21:37 UTC (permalink / raw)
  To: msnyder; +Cc: gdb-patches

On Thu, Aug 02, 2007 at 02:30:01PM -0700, Michael Snyder wrote:
> Good idea -- except, can we really be sure that name can
> never legitimately be null?  Oh, yeah, I guess the unprotected
> strrchr sort of tells us that, doesn't it?
> 
> OK, how about this?

I've no complaint.  I don't think this sort of assert adds much value,
though.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-08-02 21:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-31 23:29 [PATCH] jv-lang, guard against NULL msnyder
2007-08-02 21:06 ` Daniel Jacobowitz
     [not found]   ` <655C3D4066B7954481633935A40BB36F22BA4C@ussunex02.svl.access-company.com>
     [not found]     ` <655C3D4066B7954481633935A40BB36F22BA4C@ussunex02.svl.access-company.c      om>
2007-08-02 21:30       ` FW: " msnyder
2007-08-02 21:37         ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox