Page MenuHomeFreeBSD

bsnmp: fix undefined behaviour
ClosedPublic

Authored by ivy on Sun, Jul 27, 5:58 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Aug 15, 1:16 PM
Unknown Object (File)
Wed, Aug 13, 1:40 PM
Unknown Object (File)
Fri, Aug 1, 2:29 PM
Unknown Object (File)
Fri, Aug 1, 2:29 PM
Unknown Object (File)
Tue, Jul 29, 10:23 AM
Unknown Object (File)
Tue, Jul 29, 8:46 AM
Unknown Object (File)
Tue, Jul 29, 8:38 AM
Unknown Object (File)
Mon, Jul 28, 8:43 PM
Subscribers

Details

Summary

Modifying and using a variable without an intervening sequence point
is undefined behaviour, which causes an error in the GCC build.

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

ivy requested review of this revision.Sun, Jul 27, 5:58 PM
emaste added a subscriber: emaste.

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));
      |                         ^            ~
This revision is now accepted and ready to land.Wed, Jul 30, 4:57 PM
contrib/bsnmp/lib/snmpclient.c
2102

Alternatively,

return (port[1] = strchr(++port[0], '\0'));
contrib/bsnmp/lib/snmpclient.c
2102

That's valid, but at least for me I find it more confusing than @ivy's version

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.

This revision was automatically updated to reflect the committed changes.