Page MenuHomeFreeBSD

bsnmp: fix undefined behaviour
ClosedPublic

Authored by ivy on Jul 27 2025, 5:58 PM.
Tags
None
Referenced Files
F132411359: D51576.diff
Thu, Oct 16, 5:22 PM
F132392782: D51576.id159558.diff
Thu, Oct 16, 12:59 PM
Unknown Object (File)
Mon, Oct 13, 11:51 AM
Unknown Object (File)
Sun, Oct 12, 11:12 PM
Unknown Object (File)
Sun, Oct 12, 11:12 PM
Unknown Object (File)
Sun, Oct 12, 11:46 AM
Unknown Object (File)
Mon, Oct 6, 5:35 PM
Unknown Object (File)
Sep 16 2025, 6:46 AM
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 Not Applicable
Unit
Tests Not Applicable

Event Timeline

ivy requested review of this revision.Jul 27 2025, 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.Jul 30 2025, 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.