* Re: [PATCH] Avoid pascal crashes for structures having fields without names
[not found] <35800.5107882947$1287069713@news.gmane.org>
@ 2010-10-14 17:48 ` Tom Tromey
2010-10-15 15:44 ` Pierre Muller
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2010-10-14 17:48 UTC (permalink / raw)
To: Pierre Muller; +Cc: gdb-patches
>>>>> "Pierre" == Pierre Muller <pierre.muller@ics-cnrs.unistra.fr> writes:
Pierre> + && TYPE_FIELDS (type) [0].name
I think it is more idiomatic to use the accessors like TYPE_FIELD_NAME.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] Avoid pascal crashes for structures having fields without names
2010-10-14 17:48 ` [PATCH] Avoid pascal crashes for structures having fields without names Tom Tromey
@ 2010-10-15 15:44 ` Pierre Muller
0 siblings, 0 replies; 3+ messages in thread
From: Pierre Muller @ 2010-10-15 15:44 UTC (permalink / raw)
To: 'Tom Tromey'; +Cc: gdb-patches
> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Tom Tromey
> Envoyé : Thursday, October 14, 2010 7:48 PM
> À : Pierre Muller
> Cc : gdb-patches@sourceware.org
> Objet : Re: [PATCH] Avoid pascal crashes for structures having fields
> without names
>
> >>>>> "Pierre" == Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>
> writes:
>
> Pierre> + && TYPE_FIELDS (type) [0].name
>
> I think it is more idiomatic to use the accessors like TYPE_FIELD_NAME.
>
> Tom
Thanks for the suggestion,
I changed the source to adapt to it.
Patch applied,
Pierre Muller
Pascal language support maintainer for GDB
Pierre
2010-10-15 Pierre Muller <muller@ics.u-strasbg.fr>
* p-lang.c (is_pascal_string_type): Use TYPE_FIELD_NAME accessor.
Index: src/gdb/p-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.c,v
retrieving revision 1.56
diff -u -p -r1.56 p-lang.c
--- src/gdb/p-lang.c 14 Oct 2010 15:18:53 -0000 1.56
+++ src/gdb/p-lang.c 15 Oct 2010 15:20:00 -0000
@@ -106,10 +106,10 @@ is_pascal_string_type (struct type *type
/* Old Borland type pascal strings from Free Pascal Compiler. */
/* Two fields: length and st. */
if (TYPE_NFIELDS (type) == 2
- && TYPE_FIELDS (type) [0].name
- && strcmp (TYPE_FIELDS (type)[0].name, "length") == 0
- && TYPE_FIELDS (type) [1].name
- && strcmp (TYPE_FIELDS (type)[1].name, "st") == 0)
+ && TYPE_FIELD_NAME (type, 0)
+ && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
+ && TYPE_FIELD_NAME (type, 1)
+ && strcmp (TYPE_FIELD_NAME (type, 1), "st") == 0)
{
if (length_pos)
*length_pos = TYPE_FIELD_BITPOS (type, 0) / TARGET_CHAR_BIT;
@@ -120,16 +120,16 @@ is_pascal_string_type (struct type *type
if (char_type)
*char_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 1));
if (arrayname)
- *arrayname = TYPE_FIELDS (type)[1].name;
+ *arrayname = TYPE_FIELD_NAME (type, 1);
return 2;
};
/* GNU pascal strings. */
/* Three fields: Capacity, length and schema$ or _p_schema. */
if (TYPE_NFIELDS (type) == 3
- && TYPE_FIELDS (type) [0].name
- && strcmp (TYPE_FIELDS (type)[0].name, "Capacity") == 0
- && TYPE_FIELDS (type) [1].name
- && strcmp (TYPE_FIELDS (type)[1].name, "length") == 0)
+ && TYPE_FIELD_NAME (type, 0)
+ && strcmp (TYPE_FIELD_NAME (type, 0), "Capacity") == 0
+ && TYPE_FIELD_NAME (type, 1)
+ && strcmp (TYPE_FIELD_NAME (type, 1), "length") == 0)
{
if (length_pos)
*length_pos = TYPE_FIELD_BITPOS (type, 1) / TARGET_CHAR_BIT;
@@ -146,7 +146,7 @@ is_pascal_string_type (struct type *type
*char_type = TYPE_TARGET_TYPE (*char_type);
}
if (arrayname)
- *arrayname = TYPE_FIELDS (type)[2].name;
+ *arrayname = TYPE_FIELD_NAME (type, 2);
return 3;
};
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] Avoid pascal crashes for structures having fields without names
@ 2010-10-14 15:21 Pierre Muller
0 siblings, 0 replies; 3+ messages in thread
From: Pierre Muller @ 2010-10-14 15:21 UTC (permalink / raw)
To: gdb-patches
I committed the following patch
to GDB cvs HEAD.
Some Free Pascal classes seem now to have
hidden fields that get no names.
This could lead to crashes by
calling strcmp with a NULL parameter.
Pierre Muller
Pascal language support maintainer for GDB
ChangeLog entry:
2010-10-14 Pierre Muller <muller@ics.u-strasbg.fr>
* p-lang.c (is_pascal_string_type): Avoid crashes on structures
having fields without names.
Index: p-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.c,v
retrieving revision 1.55
diff -u -p -r1.55 p-lang.c
--- p-lang.c 12 Jul 2010 17:07:11 -0000 1.55
+++ p-lang.c 14 Oct 2010 15:17:54 -0000
@@ -105,8 +105,10 @@ is_pascal_string_type (struct type *type
{
/* Old Borland type pascal strings from Free Pascal Compiler. */
/* Two fields: length and st. */
- if (TYPE_NFIELDS (type) == 2
+ if (TYPE_NFIELDS (type) == 2
+ && TYPE_FIELDS (type) [0].name
&& strcmp (TYPE_FIELDS (type)[0].name, "length") == 0
+ && TYPE_FIELDS (type) [1].name
&& strcmp (TYPE_FIELDS (type)[1].name, "st") == 0)
{
if (length_pos)
@@ -124,7 +126,9 @@ is_pascal_string_type (struct type *type
/* GNU pascal strings. */
/* Three fields: Capacity, length and schema$ or _p_schema. */
if (TYPE_NFIELDS (type) == 3
+ && TYPE_FIELDS (type) [0].name
&& strcmp (TYPE_FIELDS (type)[0].name, "Capacity") == 0
+ && TYPE_FIELDS (type) [1].name
&& strcmp (TYPE_FIELDS (type)[1].name, "length") == 0)
{
if (length_pos)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-10-15 15:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <35800.5107882947$1287069713@news.gmane.org>
2010-10-14 17:48 ` [PATCH] Avoid pascal crashes for structures having fields without names Tom Tromey
2010-10-15 15:44 ` Pierre Muller
2010-10-14 15:21 Pierre Muller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox