On Sun, Sep 5, 2021 at 5:39 PM Rene Kita <[email protected]> wrote:
>
> On Sat, Sep 04, 2021 at 09:16:57PM +0000, [email protected] wrote:
> > This is an automated email from Gerrit.
> >
> > "Antonio Borneo <[email protected]>" just uploaded a new patch set 
> > to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/6539
> >
> > -- gerrit
> >
> > commit bed671d274408c4347facda48840b25a63b8f51a
> > Author: Antonio Borneo <[email protected]>
> > Date:   Sat Sep 4 23:01:09 2021 +0200
> >
> >     openocd: remove last NULL comparisons
> >
> >     The NULL pointers preceded by cast where not detected by the
> >     scripting tools looking for NULL pointer comparison.
> >
> >     Remove them and, while there, further simplify the code and apply
> >     the other coding style rules.
> >
> >     Change-Id: Ia7406122e07ef56ef311579ab0ee7ddb22c8e4b5
> >     Signed-off-by: Antonio Borneo <[email protected]>
> >
> > diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c
> > index 63bcda1f4..319ca380a 100644
> > --- a/src/jtag/drivers/jlink.c
> > +++ b/src/jtag/drivers/jlink.c
> > @@ -573,7 +573,7 @@ static int jlink_open_device(uint32_t ifaces, bool 
> > *found_device)
> >               return ERROR_JTAG_INIT_FAILED;
> >       }
> >
> > -     use_usb_location = (jtag_usb_get_location() != NULL);
> > +     use_usb_location = !!jtag_usb_get_location();
>                            ^^
>
> Is this intentional? Shouldn't it be '!jtag_usb_get_location()'?

Yes, it's intentional.

if (x != NULL) {...}
should be written as
if (x) {...}

Here we have an assignment
bool a = (x != NULL);
If written as
bool a = x;
it's correct but the compiler considers it as an assignment of a
pointer to a bool (actually to an integer), and triggers a warning.
The logic negation converts the pointer's value to a bool, but in this
case a double negation is required.

Antonio

Reply via email to