* [PATCH] ada-lang.c, null pointer
@ 2007-08-11 20:29 msnyder
2007-08-11 20:31 ` msnyder
0 siblings, 1 reply; 5+ messages in thread
From: msnyder @ 2007-08-11 20:29 UTC (permalink / raw)
To: gdb-patches; +Cc: brobecker
[-- Attachment #1: Type: text/plain, Size: 111 bytes --]
According to the first line of the function, name may be null.
In which case, we'll crash on the next line.
[-- Attachment #2: 55.txt --]
[-- Type: application/octet-stream, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ada-lang.c, null pointer
2007-08-11 20:29 [PATCH] ada-lang.c, null pointer msnyder
@ 2007-08-11 20:31 ` msnyder
2007-08-14 4:19 ` Joel Brobecker
0 siblings, 1 reply; 5+ messages in thread
From: msnyder @ 2007-08-11 20:31 UTC (permalink / raw)
To: msnyder; +Cc: gdb-patches, brobecker
[-- Attachment #1: Type: text/plain, Size: 139 bytes --]
> According to the first line of the function, name may be null.
> In which case, we'll crash on the next line.
Err, here's the patch...
[-- Attachment #2: 55.txt --]
[-- Type: text/plain, Size: 812 bytes --]
2007-08-11 Michael Snyder <msnyder@access-company.com>
* ada-lang.c (field_alignment): Guard against NULL.
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.100
diff -p -r1.100 ada-lang.c
*** ada-lang.c 6 Aug 2007 20:07:44 -0000 1.100
--- ada-lang.c 11 Aug 2007 20:25:00 -0000
*************** field_alignment (struct type *type, int
*** 6119,6125 ****
int len = (name == NULL) ? 0 : strlen (name);
int align_offset;
! if (!isdigit (name[len - 1]))
return 1;
if (isdigit (name[len - 2]))
--- 6119,6125 ----
int len = (name == NULL) ? 0 : strlen (name);
int align_offset;
! if (name == NULL || !isdigit (name[len - 1]))
return 1;
if (isdigit (name[len - 2]))
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ada-lang.c, null pointer
2007-08-11 20:31 ` msnyder
@ 2007-08-14 4:19 ` Joel Brobecker
2007-08-14 5:49 ` Michael Snyder
0 siblings, 1 reply; 5+ messages in thread
From: Joel Brobecker @ 2007-08-14 4:19 UTC (permalink / raw)
To: msnyder; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1181 bytes --]
Hi Michael,
> 2007-08-11 Michael Snyder <msnyder@access-company.com>
>
> * ada-lang.c (field_alignment): Guard against NULL.
Thanks again for your patch.
May I propose another patch that is very close in spirit? The diff
is slightly bigger, but it makes the code check for a null name
only once, and allows us to know at a glance what we do in this case.
Let me know what you think.
(proposed patch reg-tested)
> Index: ada-lang.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/ada-lang.c,v
> retrieving revision 1.100
> diff -p -r1.100 ada-lang.c
> *** ada-lang.c 6 Aug 2007 20:07:44 -0000 1.100
> --- ada-lang.c 11 Aug 2007 20:25:00 -0000
> *************** field_alignment (struct type *type, int
> *** 6119,6125 ****
> int len = (name == NULL) ? 0 : strlen (name);
> int align_offset;
>
> ! if (!isdigit (name[len - 1]))
> return 1;
>
> if (isdigit (name[len - 2]))
> --- 6119,6125 ----
> int len = (name == NULL) ? 0 : strlen (name);
> int align_offset;
>
> ! if (name == NULL || !isdigit (name[len - 1]))
> return 1;
>
> if (isdigit (name[len - 2]))
--
Joel
[-- Attachment #2: ada-lang.c.diff --]
[-- Type: text/plain, Size: 789 bytes --]
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.100
diff -u -p -r1.100 ada-lang.c
--- ada-lang.c 6 Aug 2007 20:07:44 -0000 1.100
+++ ada-lang.c 14 Aug 2007 03:45:04 -0000
@@ -6116,9 +6116,17 @@ static unsigned int
field_alignment (struct type *type, int f)
{
const char *name = TYPE_FIELD_NAME (type, f);
- int len = (name == NULL) ? 0 : strlen (name);
+ int len;
int align_offset;
+ /* The field name should never be null, unless the debugging information
+ is somehow malformed. In this case, we assume the field does not
+ require any alignment. */
+ if (name == NULL)
+ return 1;
+
+ len = strlen (name);
+
if (!isdigit (name[len - 1]))
return 1;
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ada-lang.c, null pointer
2007-08-14 4:19 ` Joel Brobecker
@ 2007-08-14 5:49 ` Michael Snyder
2007-08-14 20:21 ` Joel Brobecker
0 siblings, 1 reply; 5+ messages in thread
From: Michael Snyder @ 2007-08-14 5:49 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
> Hi Michael,
>
> > 2007-08-11 Michael Snyder <msnyder@access-company.com>
> >
> > * ada-lang.c (field_alignment): Guard against NULL.
>
> Thanks again for your patch.
>
> May I propose another patch that is very close in spirit? The diff
> is slightly bigger, but it makes the code check for a null name
> only once, and allows us to know at a glance what we do in this case.
>
> Let me know what you think.
> (proposed patch reg-tested)
Yeah, Joel, that looks fine to me. You want to check it in?
Michael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ada-lang.c, null pointer
2007-08-14 5:49 ` Michael Snyder
@ 2007-08-14 20:21 ` Joel Brobecker
0 siblings, 0 replies; 5+ messages in thread
From: Joel Brobecker @ 2007-08-14 20:21 UTC (permalink / raw)
To: Michael Snyder; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 299 bytes --]
> Yeah, Joel, that looks fine to me. You want to check it in?
Cool!
2007-08-14 Joel Brobecker <brobecker@adacore.com>
Michael Snyder <msnyder@access-company.com>
* ada-lang.c (field_alignment): Guard against NULL.
I have checked this in.
Thanks again, Michael.
--
Joel
[-- Attachment #2: ada-lang.c.diff --]
[-- Type: text/plain, Size: 789 bytes --]
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.100
diff -u -p -r1.100 ada-lang.c
--- ada-lang.c 6 Aug 2007 20:07:44 -0000 1.100
+++ ada-lang.c 14 Aug 2007 03:45:04 -0000
@@ -6116,9 +6116,17 @@ static unsigned int
field_alignment (struct type *type, int f)
{
const char *name = TYPE_FIELD_NAME (type, f);
- int len = (name == NULL) ? 0 : strlen (name);
+ int len;
int align_offset;
+ /* The field name should never be null, unless the debugging information
+ is somehow malformed. In this case, we assume the field does not
+ require any alignment. */
+ if (name == NULL)
+ return 1;
+
+ len = strlen (name);
+
if (!isdigit (name[len - 1]))
return 1;
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-08-14 20:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-11 20:29 [PATCH] ada-lang.c, null pointer msnyder
2007-08-11 20:31 ` msnyder
2007-08-14 4:19 ` Joel Brobecker
2007-08-14 5:49 ` Michael Snyder
2007-08-14 20:21 ` Joel Brobecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox