From: Stefan Sperling Subject: Re: s/malloc/calloc in lib/object_create.c To: Omar Polo Cc: gameoftrees@openbsd.org Date: Sat, 11 Feb 2023 14:38:35 +0100 On Sat, Feb 11, 2023 at 02:32:55PM +0100, Omar Polo wrote: > not a big deal as of now, but once we'll grow the got_object_id struct > it'd be nice to know that all the fields will be zeroed. > > ok? yes > diff /home/op/w/got > commit - 4f152e84c01e22799218a449a85a105ff94fdf9d > path + /home/op/w/got > blob - 8fa42a873d1dd3feb591275a17e1bd546c3dab59 > file + lib/object_create.c > --- lib/object_create.c > +++ lib/object_create.c > @@ -198,9 +198,9 @@ got_object_blob_file_create(struct got_object_id **id, > break; > } > > - *id = malloc(sizeof(**id)); > + *id = calloc(1, sizeof(**id)); > if (*id == NULL) { > - err = got_error_from_errno("malloc"); > + err = got_error_from_errno("calloc"); > goto done; > } > SHA1Final((*id)->sha1, &sha1_ctx); > @@ -392,9 +392,9 @@ got_object_tree_create(struct got_object_id **id, > treesize += n; > } > > - *id = malloc(sizeof(**id)); > + *id = calloc(1, sizeof(**id)); > if (*id == NULL) { > - err = got_error_from_errno("malloc"); > + err = got_error_from_errno("calloc"); > goto done; > } > SHA1Final((*id)->sha1, &sha1_ctx); > @@ -581,9 +581,9 @@ got_object_commit_create(struct got_object_id **id, > } > commitsize += n; > > - *id = malloc(sizeof(**id)); > + *id = calloc(1, sizeof(**id)); > if (*id == NULL) { > - err = got_error_from_errno("malloc"); > + err = got_error_from_errno("calloc"); > goto done; > } > SHA1Final((*id)->sha1, &sha1_ctx); > @@ -848,9 +848,9 @@ got_object_tag_create(struct got_object_id **id, > tagsize += n; > } > > - *id = malloc(sizeof(**id)); > + *id = calloc(1, sizeof(**id)); > if (*id == NULL) { > - err = got_error_from_errno("malloc"); > + err = got_error_from_errno("calloc"); > goto done; > } > SHA1Final((*id)->sha1, &sha1_ctx); > >