Skip to content

Commit

Permalink
Use calloc properly
Browse files Browse the repository at this point in the history
Addressing:

/home/jcerny/work/git/openscap/src/source/bz2.c: In function ‘bz2_mem_open’:
/home/jcerny/work/git/openscap/src/source/bz2.c:127:43: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
  127 |         struct bz2_mem *b = calloc(sizeof(struct bz2_mem), 1);
      |                                           ^~~~~~
/home/jcerny/work/git/openscap/src/source/bz2.c:127:43: note: earlier argument should specify number of elements, later size of each element
/home/jcerny/work/git/openscap/src/source/bz2.c:128:35: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
  128 |         b->stream = calloc(sizeof(bz_stream), 1);
      |                                   ^~~~~~~~~
/home/jcerny/work/git/openscap/src/source/bz2.c:128:35: note: earlier argument should specify number of elements, later size of each element
  • Loading branch information
jan-cerny committed Jun 3, 2024
1 parent 4930d2a commit 890170d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/source/bz2.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ static void bz2_mem_free(struct bz2_mem *bzmem)

static struct bz2_mem *bz2_mem_open(const char *buffer, size_t size)
{
struct bz2_mem *b = calloc(sizeof(struct bz2_mem), 1);
b->stream = calloc(sizeof(bz_stream), 1);
struct bz2_mem *b = calloc(1, sizeof(struct bz2_mem));
b->stream = calloc(1, sizeof(bz_stream));
// next_in should point at the compressed data
b->stream->next_in = (char *) buffer;
// and avail_in should indicate how many bytes the library may read
Expand Down

0 comments on commit 890170d

Please sign in to comment.