Skip to content

Commit c3368f6

Browse files
cfriedtdkalowsk
authored andcommitted
posix: env: use sizeof void ptr instead of char ptr ptr
Coverity regularly raised a CID with every release that it found `sizeof(char **)` confusing and somehow nonportable. With every release, it needed to be marked as a false positive. Change `sizeof(char **)` to `sizeof(void *)` to silence the CID warnings. Signed-off-by: Chris Friedt <[email protected]>
1 parent 44c76ee commit c3368f6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/posix/options/env_common.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ int z_setenv(const char *name, const char *val, int overwrite)
151151
} else {
152152
/* name was not found in environ -> add new entry */
153153
esize = environ_size();
154-
envp = realloc(environ, sizeof(char **) *
155-
(esize + 1 /* new entry */ + 1 /* NULL */));
154+
envp = realloc(environ,
155+
sizeof(void *) * (esize + 1 /* new entry */ + 1 /* NULL */));
156156
if (envp == NULL) {
157157
ret = -ENOMEM;
158158
SYS_SEM_LOCK_BREAK;
159159
}
160160

161161
if (TRACK_ALLOC) {
162-
allocated += sizeof(char **) * (esize + 2);
162+
allocated += sizeof(void *) * (esize + 2);
163163
LOG_DBG("realloc %zu bytes (allocated: %zu)",
164-
sizeof(char **) * (esize + 2), allocated);
164+
sizeof(void *) * (esize + 2), allocated);
165165
}
166166

167167
environ = envp;
@@ -238,7 +238,7 @@ int z_unsetenv(const char *name)
238238
free(environ);
239239
environ = NULL;
240240
} else {
241-
envp = realloc(environ, (esize + 1 /* NULL */) * sizeof(char **));
241+
envp = realloc(environ, (esize + 1 /* NULL */) * sizeof(void *));
242242
if (envp != NULL) {
243243
environ = envp;
244244
}
@@ -247,7 +247,7 @@ int z_unsetenv(const char *name)
247247

248248
if (TRACK_ALLOC) {
249249
/* recycle nsize here */
250-
nsize = ((esize == 0) ? 2 : 1) * sizeof(char **);
250+
nsize = ((esize == 0) ? 2 : 1) * sizeof(void *);
251251
allocated -= nsize;
252252
LOG_DBG("free %zu bytes (allocated: %zu)", nsize, allocated);
253253
}

0 commit comments

Comments
 (0)