Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: msnyder@sonic.net
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] ada-lang.c, null pointer
Date: Tue, 14 Aug 2007 04:19:00 -0000	[thread overview]
Message-ID: <20070814042242.GA11498@adacore.com> (raw)
In-Reply-To: <25376.12.7.175.2.1186864263.squirrel@webmail.sonic.net>

[-- 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;
 

  reply	other threads:[~2007-08-14  4:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-11 20:29 msnyder
2007-08-11 20:31 ` msnyder
2007-08-14  4:19   ` Joel Brobecker [this message]
2007-08-14  5:49     ` Michael Snyder
2007-08-14 20:21       ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070814042242.GA11498@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=msnyder@sonic.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox