target/ppc/int_helper.c:2806: strange expression ?

Bug #1655708 reported by dcb
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
QEMU
Fix Released
Undecided
ziviani

Bug Description

target/ppc/int_helper.c:2806:25: warning: ‘*’ in boolean context, suggest ‘&&’ instead [-Wint-in-bool-context]

Source code is

       zone_digit = (i * 2) ? b->u8[BCD_DIG_BYTE(i * 2)] >> 4 : zone_lead;

Which I read as

       zone_digit = (i * 2) ? (b->u8[BCD_DIG_BYTE(i * 2)] >> 4) : zone_lead;

so I think the compiler warning is for the i * 2 lhs of the ?.

I am not sure what to suggest as a bugfix.

Revision history for this message
Eric Blake (eblake) wrote : Re: [Qemu-devel] [Bug 1655708] [NEW] target/ppc/int_helper.c:2806: strange expression ?

On 01/11/2017 10:41 AM, dcb wrote:
> Public bug reported:
>
> target/ppc/int_helper.c:2806:25: warning: ‘*’ in boolean context,
> suggest ‘&&’ instead [-Wint-in-bool-context]
>
> Source code is
>
> zone_digit = (i * 2) ? b->u8[BCD_DIG_BYTE(i * 2)] >> 4 :
> zone_lead;

Also, looking at BCD_DIG_BYTE():

#if defined(HOST_WORDS_BIGENDIAN)
#define BCD_DIG_BYTE(n) (15 - (n/2))
#else
#define BCD_DIG_BYTE(n) (n/2)
#endif

Oops. n is under-parenthesized, and will cause invalid expansions for
some expressions. Let's fix that as well.

> so I think the compiler warning is for the i * 2 lhs of the ?.

Yes - the compiler is complaining that 'i * 2' can only be non-zero if
'i' was non-zero (given that the code occurs in a loop for i between 0
and 16), so it is just as easy to write 'i ? ...' instead of the weirder
'(i * 2) ? ...'.

--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

ziviani (jrziviani)
Changed in qemu:
assignee: nobody → Jose R. Ziviani (jrziviani)
Revision history for this message
dcb (dcb314) wrote :

> so it is just as easy to write 'i ? ...' instead of the weirder
> '(i * 2) ? ...'.

I suspect it is just possible that the i * 2 expression is a typo
for something else, perhaps i & 2 or i << 2 or i >> 2 or something else.

I don't know the code so I am unable to offer better guidance.

Revision history for this message
Thomas Huth (th-huth) wrote :
Changed in qemu:
status: New → In Progress
Revision history for this message
Thomas Huth (th-huth) wrote :
Changed in qemu:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.