diff mbox

Fix -Wstrict-null-sentinel warnings

Message ID 5588f044-4f8b-ff32-070a-aacf7932671f@suse.de
State New
Headers show

Commit Message

Tom de Vries Feb. 10, 2020, 10:18 a.m. UTC
[ was: Re: [PATCH][gdb] Mention CU offset for <artifical> if verbose ]

On 09-02-2020 14:35, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> +      debug_filename.reset (concat (artificial, "@",
> Tom> +				    sect_offset_str (per_cu->sect_off), NULL));
> 
> When passing NULL to concat, you either need nullptr or (char *) NULL.

Fixed in attached patch.

OK for trunk?

Thanks,
- Tom

Comments

Simon Marchi Feb. 10, 2020, 2:08 p.m. UTC | #1
On 2020-02-10 5:18 a.m., Tom de Vries wrote:
> [ was: Re: [PATCH][gdb] Mention CU offset for <artifical> if verbose ]
> 
> On 09-02-2020 14:35, Tom Tromey wrote:
>>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
>>
>> Tom> +      debug_filename.reset (concat (artificial, "@",
>> Tom> +				    sect_offset_str (per_cu->sect_off), NULL));
>>
>> When passing NULL to concat, you either need nullptr or (char *) NULL.
> 
> Fixed in attached patch.
> 
> OK for trunk?

I think we usually put a space after the cast:

  (char *) NULL

Also, if we want to enforce this warning, it should be added to gdb/warning.m4.  Makefiles
in gdb/ and gdbserver/ should be re-generated.  gdbsupport/ doesn't use AM_GDB_WARNINGS at
the moment.

Simon
Tom de Vries Feb. 10, 2020, 2:19 p.m. UTC | #2
On 10-02-2020 15:08, Simon Marchi wrote:
> On 2020-02-10 5:18 a.m., Tom de Vries wrote:
>> [ was: Re: [PATCH][gdb] Mention CU offset for <artifical> if verbose ]
>>
>> On 09-02-2020 14:35, Tom Tromey wrote:
>>>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
>>>
>>> Tom> +      debug_filename.reset (concat (artificial, "@",
>>> Tom> +				    sect_offset_str (per_cu->sect_off), NULL));
>>>
>>> When passing NULL to concat, you either need nullptr or (char *) NULL.
>>
>> Fixed in attached patch.
>>
>> OK for trunk?
> 
> I think we usually put a space after the cast:
> 
>   (char *) NULL
> 

Ack, committed with that fixed.

Thanks,
- Tom

> Also, if we want to enforce this warning, it should be added to gdb/warning.m4.  Makefiles
> in gdb/ and gdbserver/ should be re-generated.  gdbsupport/ doesn't use AM_GDB_WARNINGS at
> the moment.
Tom Tromey Feb. 11, 2020, 2:49 p.m. UTC | #3
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

Simon> Also, if we want to enforce this warning, it should be added to
Simon> gdb/warning.m4.  Makefiles in gdb/ and gdbserver/ should be
Simon> re-generated.

I have a patch for this that I will send shortly.

I didn't know about this warning, or I would have added it earlier :-)

Tom
diff mbox

Patch

[gdb] Fix -Wstrict-null-sentinel warnings

When passed in CXXFLAGS, -Wstrict-null-sentinel triggers twice in a
gdb/gdbserver build.

Fix the two occurrences.

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-02-10  Tom de Vries  <tdevries@suse.de>

	* dwarf2/read.c (process_psymtab_comp_unit_reader): Cast concat NULL
	sentinel to char *.

gdbsupport/ChangeLog:

2020-02-10  Tom de Vries  <tdevries@suse.de>

	* environ.c (gdb_environ::set): Cast concat NULL sentinel to char *.

---
 gdb/dwarf2/read.c    | 3 ++-
 gdbsupport/environ.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 9e66e613cd..a7646c87f3 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7260,7 +7260,8 @@  process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
   else if (strcmp (filename, artificial) == 0)
     {
       debug_filename.reset (concat (artificial, "@",
-				    sect_offset_str (per_cu->sect_off), NULL));
+				    sect_offset_str (per_cu->sect_off),
+				    (char *)NULL));
       filename = debug_filename.get ();
     }
 
diff --git a/gdbsupport/environ.c b/gdbsupport/environ.c
index 55d0a74c37..a618cf0f6f 100644
--- a/gdbsupport/environ.c
+++ b/gdbsupport/environ.c
@@ -105,7 +105,7 @@  gdb_environ::get (const char *var) const
 void
 gdb_environ::set (const char *var, const char *value)
 {
-  char *fullvar = concat (var, "=", value, NULL);
+  char *fullvar = concat (var, "=", value, (char *)NULL);
 
   /* We have to unset the variable in the vector if it exists.  */
   unset (var, false);