Page MenuHomeFreeBSD

ctld: Consistently use item count as the first argument to calloc
ClosedPublic

Authored by jhb on Jul 17 2024, 7:16 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Sep 29, 7:39 AM
Unknown Object (File)
Sun, Sep 29, 7:39 AM
Unknown Object (File)
Sun, Sep 29, 7:39 AM
Unknown Object (File)
Sat, Sep 28, 4:59 AM
Unknown Object (File)
Fri, Sep 27, 8:31 PM
Unknown Object (File)
Tue, Sep 24, 6:01 AM
Unknown Object (File)
Tue, Sep 24, 12:04 AM
Unknown Object (File)
Mon, Sep 23, 9:41 AM
Subscribers
None

Details

Summary

Reported by: GCC 14 -Wcalloc-transposed-args

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Jul 17 2024, 7:16 PM
jhb created this revision.

Some of these can be argued either way (is it one buffer of length ir_buflen, or is it a buffer of ir_buflen byte objects) but it's fine to do this just to placate GCC.

This revision is now accepted and ready to land.Jul 17 2024, 7:45 PM

Yes, in general I avoided changing the ones that were an array of bytes (e.g. for strings or opaque buffers) as you can argue it either way (a single opaque buffer, or an array of bytes). In this case GCC only warned about the first one, but here I believe it is obvious that rather than being an opaque buffer, the second one is really allocating a struct isns_hdr object, so the size really should be the second argument there as well.

Also, given the number of changes to be fixed, and that in many cases it made individual files or programs more consistent (e.g. all but a small number of calls were already correct), I think I'd prefer to just leave the calloc warning enabled going forward rather than muting it.