Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [commit] linespec.c, decode_line_1, check for null.
@ 2011-03-01 20:57 Michael Snyder
  2011-03-01 21:25 ` Pedro Alves
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Snyder @ 2011-03-01 20:57 UTC (permalink / raw)
  To: gdb-patches

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

If it's worth checking for null, it's worth doing so before the first 
dereference.

Checked in.


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

2011-03-01  Michael Snyder  <msnyder@vmware.com>

	* linespec.c (decode_line_1): Check for null before dereference.

Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.110
diff -u -p -u -p -r1.110 linespec.c
--- linespec.c	1 Mar 2011 00:26:14 -0000	1.110
+++ linespec.c	1 Mar 2011 20:53:54 -0000
@@ -726,7 +726,7 @@ decode_line_1 (char **argptr, int funfir
   char *copy;
   /* This says whether or not something in *ARGPTR is quoted with
      completer_quotes (i.e. with single quotes).  */
-  int is_quoted;
+  int is_quoted = 0;
   /* Is *ARGPTR is enclosed in double quotes?  */
   int is_quote_enclosed;
   int is_objc_method = 0;
@@ -745,12 +745,15 @@ decode_line_1 (char **argptr, int funfir
   
   /* See if arg is *PC.  */
 
-  if (**argptr == '*')
-    return decode_indirect (argptr);
+  if (*argptr)
+    {
+      if (**argptr == '*')
+	return decode_indirect (argptr);
+
+      is_quoted = (strchr (get_gdb_completer_quote_characters (),
+			   **argptr) != NULL);
+    }
 
-  is_quoted = (*argptr
-	       && strchr (get_gdb_completer_quote_characters (),
-			  **argptr) != NULL);
   if (is_quoted)
     end_quote = skip_quoted (*argptr);
 

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

* Re: [commit] linespec.c, decode_line_1, check for null.
  2011-03-01 20:57 [commit] linespec.c, decode_line_1, check for null Michael Snyder
@ 2011-03-01 21:25 ` Pedro Alves
  2011-03-01 21:43   ` Michael Snyder
  0 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2011-03-01 21:25 UTC (permalink / raw)
  To: gdb-patches; +Cc: Michael Snyder

On Tuesday 01 March 2011 20:57:30, Michael Snyder wrote:
> If it's worth checking for null, it's worth doing so before the first 
> dereference.

Well, then it may not be worth checking for null.  How old is
that code?  

> 
> Checked in.
> 
> 

-- 
Pedro Alves


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

* Re: [commit] linespec.c, decode_line_1, check for null.
  2011-03-01 21:25 ` Pedro Alves
@ 2011-03-01 21:43   ` Michael Snyder
  2011-03-01 21:50     ` Pedro Alves
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Snyder @ 2011-03-01 21:43 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves wrote:
> On Tuesday 01 March 2011 20:57:30, Michael Snyder wrote:
>> If it's worth checking for null, it's worth doing so before the first 
>> dereference.
> 
> Well, then it may not be worth checking for null.  How old is
> that code?  

It predates me, and I've been on gdb since 1995.   ;-)


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

* Re: [commit] linespec.c, decode_line_1, check for null.
  2011-03-01 21:43   ` Michael Snyder
@ 2011-03-01 21:50     ` Pedro Alves
  2011-03-01 22:03       ` Michael Snyder
  0 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2011-03-01 21:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Michael Snyder

On Tuesday 01 March 2011 21:43:27, Michael Snyder wrote:
> Pedro Alves wrote:
> > On Tuesday 01 March 2011 20:57:30, Michael Snyder wrote:
> >> If it's worth checking for null, it's worth doing so before the first 
> >> dereference.
> > 
> > Well, then it may not be worth checking for null.  How old is
> > that code?  
> 
> It predates me, and I've been on gdb since 1995.   ;-)

:-)

Then I think it's safe to say that if we haven't seen
a NULL-dereference crash in over 15 years, it's because it's
not really necessary.

-- 
Pedro Alves


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

* Re: [commit] linespec.c, decode_line_1, check for null.
  2011-03-01 21:50     ` Pedro Alves
@ 2011-03-01 22:03       ` Michael Snyder
  2011-03-01 22:08         ` Pedro Alves
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Snyder @ 2011-03-01 22:03 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

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

Pedro Alves wrote:
> On Tuesday 01 March 2011 21:43:27, Michael Snyder wrote:
>> Pedro Alves wrote:
>>> On Tuesday 01 March 2011 20:57:30, Michael Snyder wrote:
>>>> If it's worth checking for null, it's worth doing so before the first 
>>>> dereference.
>>> Well, then it may not be worth checking for null.  How old is
>>> that code?  
>> It predates me, and I've been on gdb since 1995.   ;-)
> 
> :-)
> 
> Then I think it's safe to say that if we haven't seen
> a NULL-dereference crash in over 15 years, it's because it's
> not really necessary.
> 

Ok then -- you'd prefer it like this?



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

2011-03-01  Michael Snyder  <msnyder@vmware.com>

	* linespec.c (decode_line_1): Remove unnecessary null check.

Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.111
diff -u -p -u -p -r1.111 linespec.c
--- linespec.c	1 Mar 2011 20:57:52 -0000	1.111
+++ linespec.c	1 Mar 2011 22:01:07 -0000
@@ -726,7 +726,7 @@ decode_line_1 (char **argptr, int funfir
   char *copy;
   /* This says whether or not something in *ARGPTR is quoted with
      completer_quotes (i.e. with single quotes).  */
-  int is_quoted = 0;
+  int is_quoted;
   /* Is *ARGPTR is enclosed in double quotes?  */
   int is_quote_enclosed;
   int is_objc_method = 0;
@@ -745,14 +745,11 @@ decode_line_1 (char **argptr, int funfir
   
   /* See if arg is *PC.  */
 
-  if (*argptr)
-    {
-      if (**argptr == '*')
-	return decode_indirect (argptr);
+  if (**argptr == '*')
+    return decode_indirect (argptr);
 
-      is_quoted = (strchr (get_gdb_completer_quote_characters (),
-			   **argptr) != NULL);
-    }
+  is_quoted = (strchr (get_gdb_completer_quote_characters (),
+		       **argptr) != NULL);
 
   if (is_quoted)
     end_quote = skip_quoted (*argptr);

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

* Re: [commit] linespec.c, decode_line_1, check for null.
  2011-03-01 22:03       ` Michael Snyder
@ 2011-03-01 22:08         ` Pedro Alves
  0 siblings, 0 replies; 6+ messages in thread
From: Pedro Alves @ 2011-03-01 22:08 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches

On Tuesday 01 March 2011 22:03:22, Michael Snyder wrote:
> Pedro Alves wrote:
> > On Tuesday 01 March 2011 21:43:27, Michael Snyder wrote:
> >> Pedro Alves wrote:
> >>> On Tuesday 01 March 2011 20:57:30, Michael Snyder wrote:
> >>>> If it's worth checking for null, it's worth doing so before the first 
> >>>> dereference.
> >>> Well, then it may not be worth checking for null.  How old is
> >>> that code?  
> >> It predates me, and I've been on gdb since 1995.   ;-)
> > 
> > :-)
> > 
> > Then I think it's safe to say that if we haven't seen
> > a NULL-dereference crash in over 15 years, it's because it's
> > not really necessary.
> > 
> 
> Ok then -- you'd prefer it like this?

Yep.  Thanks.

-- 
Pedro Alves


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

end of thread, other threads:[~2011-03-01 22:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-01 20:57 [commit] linespec.c, decode_line_1, check for null Michael Snyder
2011-03-01 21:25 ` Pedro Alves
2011-03-01 21:43   ` Michael Snyder
2011-03-01 21:50     ` Pedro Alves
2011-03-01 22:03       ` Michael Snyder
2011-03-01 22:08         ` Pedro Alves

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