Skip to content

Commit

Permalink
coverity: Fix Sizeof not portable (SIZEOF_MISMATCH)
Browse files Browse the repository at this point in the history
Coverity reports that passing argument 'sizeof (ctx->attrs)' to calloc and
then casting the return value to 'char **' looks suspicious. In fact, this
is just plain wrong. It happens to work, in this particular case since
sizeof (char ** const) happens to be equal to sizeof (char *), but this is
not a portable assumption.

So fix that by using 'sizeof (*ctx->attrs)'

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Jun 2, 2020
1 parent 58f3017 commit c9250c0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions context.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ char * iio_context_create_xml(const struct iio_context *ctx)
len += sizeof(" description=\"\"") - 1;
}

ctx_attrs = calloc(ctx->nb_attrs, sizeof(ctx->attrs));
ctx_attrs = calloc(ctx->nb_attrs, sizeof(*ctx->attrs));
if (!ctx_attrs) {
errno = ENOMEM;
return NULL;
}
ctx_values = calloc(ctx->nb_attrs, sizeof(ctx->values));
ctx_values = calloc(ctx->nb_attrs, sizeof(*ctx->values));
if (!ctx_values) {
errno = ENOMEM;
goto err_free_ctx_attrs;
Expand Down

0 comments on commit c9250c0

Please sign in to comment.