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
F101991320: D46013.id141154.diff
Wed, Nov 6, 6:50 AM
F101991317: D46013.id.diff
Wed, Nov 6, 6:49 AM
F101990626: D46013.diff
Wed, Nov 6, 6:35 AM
Unknown Object (File)
Mon, Oct 21, 3:14 PM
Unknown Object (File)
Oct 2 2024, 11:57 AM
Unknown Object (File)
Sep 29 2024, 7:39 AM
Unknown Object (File)
Sep 29 2024, 7:39 AM
Unknown Object (File)
Sep 29 2024, 7:39 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.