#9 Conditional operator with conflicting types

open
nobody
None
5
2013-02-11
2012-10-02
No

Hi,

While building your package using our research compiler infrastructure we noticed that the conditional operator as used in src/io.c, line 476, does not typecheck:

The return type of io_trace is void, but the third argument is NULL. Yet 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.

The best way to fix this is likely replacing

IF_DEBUG(DBG_TERSE,
((chan == 0)?
io_trace("input overflow, %ld bytes written.", count):
NULL));

by

IF_DEBUG(DBG_TERSE,
({ if(chan == 0)
io_trace("input overflow, %ld bytes written.", count); }));

Best,
Michael

Discussion