Modifying and using a variable without an intervening sequence point
is undefined behaviour, which causes an error in the GCC build.
Details
Details
- Reviewers
des glebius emaste harti - Commits
- rG250bb6793a2b: bsnmp: fix undefined behaviour
Diff Detail
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Skipped - Unit
Tests Skipped - Build Status
Buildable 65776 Build 62659: arc lint + arc unit
Event Timeline
Comment Actions
Interesting, Clang can provide a similar warning, but it doesn't work w/ the array. For example,
fn.c:10:18: warning: unsequenced modification and access to 'p' [-Wunsequenced] 10 | return (port1 = ++p + strlen(p)); | ^ ~
contrib/bsnmp/lib/snmpclient.c | ||
---|---|---|
2102 | Alternatively, return (port[1] = strchr(++port[0], '\0')); |
contrib/bsnmp/lib/snmpclient.c | ||
---|---|---|
2102 | this was why i split it into 3 lines: aside from being UB, it's also very difficult to read. des's version is slightly better than the original, but i see no reason to condense all this onto a single line. |