Re: [commit] py-prettyprint.c, val may be null

Michael Snyder
2011-03-01T21:41:06Z

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

Pedro Alves wrote:
> On Tuesday 01 March 2011 21:04:49, Michael Snyder wrote:
>> 2011-03-01 Michael Snyder <msnyder@vmware.com>
>>
>> * python/py-prettyprint.c (apply_val_pretty_printer): VAL may
>> be null.
>
> How?

Coverity assumes it may be null if it's checked for null.

> I think it could a while ago, but not anymore. I've recently
> made sure val_print always gets a non-NULL value, and we'd now
> crash elsewhere otherwise.
>

In that case, the later check for null is superfluous.
Is this better?

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

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

* python/py-prettyprint.c (apply_val_pretty_printer): Remove
superfluous null check.

Index: python/py-prettyprint.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-prettyprint.c,v
retrieving revision 1.22
diff -u -p -u -p -r1.22 py-prettyprint.c
--- python/py-prettyprint.c 1 Mar 2011 21:03:22 -0000 1.22
+++ python/py-prettyprint.c 1 Mar 2011 21:38:59 -0000
@@ -692,8 +692,7 @@ apply_val_pretty_printer (struct type *t
enum string_repr_result print_result;

/* No pretty-printer support for unavailable values. */
- if (val && !value_bytes_available (val, embedded_offset,
- TYPE_LENGTH (type)))
+ if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
return 0;

cleanups = ensure_python_env (gdbarch, language);
@@ -703,16 +702,14 @@ apply_val_pretty_printer (struct type *t
valaddr += embedded_offset;
value = value_from_contents_and_address (type, valaddr,
address + embedded_offset);
- if (val != NULL)
- {
- set_value_component_location (value, val);
- /* set_value_component_location resets the address, so we may
- need to set it again. */
- if (VALUE_LVAL (value) != lval_internalvar
- && VALUE_LVAL (value) != lval_internalvar_component
- && VALUE_LVAL (value) != lval_computed)
- set_value_address (value, address + embedded_offset);
- }
+
+ set_value_component_location (value, val);
+ /* set_value_component_location resets the address, so we may
+ need to set it again. */
+ if (VALUE_LVAL (value) != lval_internalvar
+ && VALUE_LVAL (value) != lval_internalvar_component
+ && VALUE_LVAL (value) != lval_computed)
+ set_value_address (value, address + embedded_offset);

val_obj = value_to_value_object (value);
if (! val_obj)