Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent types in conditional operator #4

Open
ileanadumitrescu95 opened this issue Sep 14, 2022 · 0 comments
Open

Inconsistent types in conditional operator #4

ileanadumitrescu95 opened this issue Sep 14, 2022 · 0 comments

Comments

@ileanadumitrescu95
Copy link
Contributor

SourceForge bug #193 written by Michael Tautschnig on 2013-03-06

In libvbi/exp-gfx.c PIXEL is declared as follows:

#define PIXEL(d, i, s, j) \ (1 == bpp ? ((uint8_t *)(d))[i] = \ ((const uint8_t *)(s))[j] : \ (2 == bpp ? ((uint16_t *)(d))[i] = \ ((const uint16_t *)(s))[j] : \ (3 == bpp ? memcpy (((uint8_t *)(d)) + (i) * 3, \ ((const uint8_t *)(s)) + (j) * 3, 3) : \ (4 == bpp ? ((uint32_t *)(d))[i] = \ ((const uint32_t *)(s))[j] : \ assert (0)))))

The types within this chain of conditional operators do not match and will
necessarily cause problems if the return value is ever used. With the final assertion,
which could possibly be disabled, this is even worse. The C
standard requires that the second and third argument of the conditional operator
?: are both void or compatible pointer types (there are several other cases, see
6.5.15 of the C Standard). Failing this, the compiler may produce arbitrary
code.

In this case, it seems best to cast each assignment to void to ensure a) consistent types
and b) that the return value can never be used.

Best,
Michael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant