]> www.infradead.org Git - users/sagi/nvme-cli.git/commit
util: reduce allocation sizes in argconfig_parse()
authorCaleb Sander Mateos <csander@purestorage.com>
Tue, 16 Jul 2024 19:07:23 +0000 (13:07 -0600)
committerDaniel Wagner <wagi@monom.org>
Wed, 17 Jul 2024 14:57:45 +0000 (16:57 +0200)
commit9f9d5582c994ae55ce24e872c54ce0ae097e56cb
tree54e8ade915b1f2a83b9b220a1be1202c08eb403e
parentc8761493bdbbe973456ef8e46bc94f05c4de25dd
util: reduce allocation sizes in argconfig_parse()

long_opts stores up to 1 element per option, plus a help element,
and a zerored final element. So it can be allocated with length
options_count + 2 instead of options_count + 3.
short_opts stores up to 3 characters per option, plus 2 help characters,
and a NUL terminator. So it can be allocated with length
options_count * 3 + 3 instead of options_count * 3 + 5.

Also use the two arguments to calloc() instead of multiplying the sizes.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
util/argconfig.c