aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2023-08-07 14:31:30 +0200
committerDmitry V. Levin <ldv@strace.io>2023-08-07 13:10:27 +0000
commitdbe68128a079ee6869dc42aee37bf403e137218b (patch)
treec24b33ce1bc1ffc80f83d4989093b91472d99ab6 /modules
parent54e97c027e52eec39220cc08b62ab480095ac5d7 (diff)
downloadpam-dbe68128a079ee6869dc42aee37bf403e137218b.tar.gz
pam-dbe68128a079ee6869dc42aee37bf403e137218b.tar.bz2
pam-dbe68128a079ee6869dc42aee37bf403e137218b.zip
pam_env: remove allocator sizeof operator mismatch
An array of strings is allocated (into a pointer) so the single array element to be allocated is char*. Since sizeof(char**) should be always equal to sizeof(char*) this caused no issues so far. Reported by Clang analyzer: pam_env.c:391:14: warning: Result of 'malloc' is converted to a pointer of type 'char *', which is incompatible with sizeof operand type 'char **' [unix.MallocSizeof] 391 | *lines = malloc((i + 1)* sizeof(char**)); | ^~~~~~ ~~~~~~~~~~~~~~ pam_env.c:401:13: warning: Result of 'realloc' is converted to a pointer of type 'char *', which is incompatible with sizeof operand type 'char **' [unix.MallocSizeof] 401 | tmp = realloc(*lines, (++i + 1) * sizeof(char**)); | ^~~~~~~ ~~~~~~~~~~~~~~
Diffstat (limited to 'modules')
-rw-r--r--modules/pam_env/pam_env.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/modules/pam_env/pam_env.c b/modules/pam_env/pam_env.c
index d2d12ad6..01c707fd 100644
--- a/modules/pam_env/pam_env.c
+++ b/modules/pam_env/pam_env.c
@@ -388,7 +388,7 @@ static int read_file(const pam_handle_t *pamh, const char*filename, char ***line
}
size_t i = 0;
- *lines = malloc((i + 1)* sizeof(char**));
+ *lines = malloc((i + 1)* sizeof(char*));
if (*lines == NULL) {
pam_syslog(pamh, LOG_ERR, "Cannot allocate memory.");
(void) fclose(conf);
@@ -398,7 +398,7 @@ static int read_file(const pam_handle_t *pamh, const char*filename, char ***line
while (_assemble_line(conf, buffer, BUF_SIZE) > 0) {
char **tmp = NULL;
D(("Read line: %s", buffer));
- tmp = realloc(*lines, (++i + 1) * sizeof(char**));
+ tmp = realloc(*lines, (++i + 1) * sizeof(char*));
if (tmp == NULL) {
pam_syslog(pamh, LOG_ERR, "Cannot allocate memory.");
(void) fclose(conf);