Page MenuHomeFreeBSD

hdb_add_current_keys_to_history: pass correct `size` to calloc
AbandonedPublic

Authored by ngie on Tue, Feb 3, 8:20 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Feb 4, 11:17 AM
Unknown Object (File)
Tue, Feb 3, 11:40 PM
Unknown Object (File)
Tue, Feb 3, 10:32 PM
Unknown Object (File)
Tue, Feb 3, 10:31 PM
Unknown Object (File)
Tue, Feb 3, 9:57 PM
Subscribers

Details

Summary

The size being passed to calloc prior to this change was incorrectly
calculated. The value passed should have been the type, not a
dereferenced pointer to a scalar value that happens to be the type.

This also avoids a NULL pointer dereference, which would have resulted
in a crash.

This fixes a -Wfree-nonheap-object issue cited by gcc 14.

MFC after: 3 days
PR: 292916

Test Plan

The code compiles/links without warnings with gcc14 on :main after this change.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 70379
Build 67262: arc lint + arc unit

Event Timeline

ngie requested review of this revision.Tue, Feb 3, 8:20 PM
ngie added reviewers: rmacklem, cy.
ngie retitled this revision from hdb_add_current_keys_to_history: pass correct memory size to calloc to hdb_add_current_keys_to_history: pass correct `size` to calloc.
ngie added a subscriber: jhb.

I can't understand the problem. If structure is known sizeof(*ext) results in the same value as sizeof(struct HDB_extension). If the structure is not known and has only forward declaration, compilation should fail with: invalid application of 'sizeof' to an incomplete type.

I can't understand the problem. If structure is known sizeof(*ext) results in the same value as sizeof(struct HDB_extension). If the structure is not known and has only forward declaration, compilation should fail with: invalid application of 'sizeof' to an incomplete type.

Yeah, you're right. This change doesn't do anything difference net-wise (and TIL re: dereferencing points in this way). Abandoning...