Skip to content

Commit c9250c0

Browse files
committed
coverity: Fix Sizeof not portable (SIZEOF_MISMATCH)
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]>
1 parent 58f3017 commit c9250c0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

context.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ char * iio_context_create_xml(const struct iio_context *ctx)
6262
len += sizeof(" description=\"\"") - 1;
6363
}
6464

65-
ctx_attrs = calloc(ctx->nb_attrs, sizeof(ctx->attrs));
65+
ctx_attrs = calloc(ctx->nb_attrs, sizeof(*ctx->attrs));
6666
if (!ctx_attrs) {
6767
errno = ENOMEM;
6868
return NULL;
6969
}
70-
ctx_values = calloc(ctx->nb_attrs, sizeof(ctx->values));
70+
ctx_values = calloc(ctx->nb_attrs, sizeof(*ctx->values));
7171
if (!ctx_values) {
7272
errno = ENOMEM;
7373
goto err_free_ctx_attrs;

0 commit comments

Comments
 (0)