Skip to content

Commit

Permalink
calloc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed Dec 1, 2024
1 parent 2c9efec commit 19fceff
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion contrib/elftoolchain/libdwarf/libdwarf_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ _dwarf_alloc(Dwarf_Debug *ret_dbg, int mode, Dwarf_Error *error)
{
Dwarf_Debug dbg;

if ((dbg = calloc(sizeof(struct _Dwarf_Debug), 1)) == NULL) {
if ((dbg = calloc(1, sizeof(struct _Dwarf_Debug))) == NULL) {
DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
return (DW_DLE_MEMORY);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/libcasper/services/cap_dns/cap_dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ hostent_unpack(const nvlist_t *nvl, struct hostent *hp)
hp->h_length = (int)nvlist_get_number(nvl, "length");

nitems = (unsigned int)nvlist_get_number(nvl, "naliases");
hp->h_aliases = calloc(sizeof(hp->h_aliases[0]), nitems + 1);
hp->h_aliases = calloc(nitems + 1, sizeof(hp->h_aliases[0]));
if (hp->h_aliases == NULL)
goto fail;
for (ii = 0; ii < nitems; ii++) {
Expand All @@ -98,7 +98,7 @@ hostent_unpack(const nvlist_t *nvl, struct hostent *hp)
hp->h_aliases[ii] = NULL;

nitems = (unsigned int)nvlist_get_number(nvl, "naddrs");
hp->h_addr_list = calloc(sizeof(hp->h_addr_list[0]), nitems + 1);
hp->h_addr_list = calloc(nitems + 1, sizeof(hp->h_addr_list[0]));
if (hp->h_addr_list == NULL)
goto fail;
for (ii = 0; ii < nitems; ii++) {
Expand Down
4 changes: 2 additions & 2 deletions lib/libcasper/services/cap_net/cap_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ hostent_unpack(const nvlist_t *nvl, struct hostent *hp)
hp->h_length = (int)nvlist_get_number(nvl, "length");

nitems = (unsigned int)nvlist_get_number(nvl, "naliases");
hp->h_aliases = calloc(sizeof(hp->h_aliases[0]), nitems + 1);
hp->h_aliases = calloc(nitems + 1, sizeof(hp->h_aliases[0]));
if (hp->h_aliases == NULL)
goto fail;
for (ii = 0; ii < nitems; ii++) {
Expand All @@ -119,7 +119,7 @@ hostent_unpack(const nvlist_t *nvl, struct hostent *hp)
hp->h_aliases[ii] = NULL;

nitems = (unsigned int)nvlist_get_number(nvl, "naddrs");
hp->h_addr_list = calloc(sizeof(hp->h_addr_list[0]), nitems + 1);
hp->h_addr_list = calloc(nitems + 1, sizeof(hp->h_addr_list[0]));
if (hp->h_addr_list == NULL)
goto fail;
for (ii = 0; ii < nitems; ii++) {
Expand Down
2 changes: 1 addition & 1 deletion lib/libgeom/geom_xml2tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ geom_xml2tree(struct gmesh *gmp, char *p)
free(mt);
return (error);
}
gmp->lg_ident = calloc(sizeof *gmp->lg_ident, mt->nident + 1);
gmp->lg_ident = calloc(mt->nident + 1, sizeof(*gmp->lg_ident));
free(mt);
if (gmp->lg_ident == NULL)
return (ENOMEM);
Expand Down

0 comments on commit 19fceff

Please sign in to comment.