Issue Details (XML | Word | Printable)

Key: PCC-403
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Iain Hibbert
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
pcc

#if conditional leaks some information

Created: 25/Aug/12 12:54 PM   Updated: 15/Sep/12 07:13 PM
Component/s: C preprocessor
Affects Version/s: None
Fix Version/s: None

Environment: NetBSD/i386


 Description  « Hide
The #if conditional is leaking some information when the test is expanded from a macro, which carries over to affect the next conditional

the following code demonstrates the issue

#define VAL 5
#define FOO defined(VAL)
#define BAR defined(FOOBAR)

#if FOO
foo: FOO
#endif

#if BAR
bar: BAR
#endif

when compiled with pcc -E, produces (without blank lines)

foo: defined(5)
bar: defined(FOOBAR)

which is clearly wrong.. but if the code is changed to

#if TEST
test: TEST
#endif

#if BAR
bar: BAR
#endif

then it works ok..



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson added a comment - 30/Aug/12 05:59 PM
Hm, 6.10.1 clause 3 says:

" If the token defined is generated as a result of this replacement process or use of the defined unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined. "

So, using defined here enters the "undefined" area...?

Iain Hibbert added a comment - 01/Sep/12 10:36 AM
I have emailed the author of the upstream code that was using this construct (IPF, in the NetBSD sources), will work on it separately..

Iain Hibbert added a comment - 15/Sep/12 07:13 PM
I have fixed this in the upstream code so it is no longer an issue

Iain Hibbert made changes - 15/Sep/12 07:13 PM
Field Original Value New Value
Status Open [ 1 ] Closed [ 6 ]
Resolution Fixed [ 1 ]