Skip to content

Commit

Permalink
Use adequate type for storing the return value of read(2)
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
  • Loading branch information
flx42 committed Jul 8, 2024
1 parent 726f294 commit edf2533
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pyxis_slurmstepd.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ static int read_proc_environ(pid_t pid, char **result, size_t *size)
int fd = -1;
char *buf = NULL;
size_t len = 0, capacity = 1024;
ssize_t n;
char *new_buf = NULL;
int rv = -1;

Expand All @@ -525,8 +526,8 @@ static int read_proc_environ(pid_t pid, char **result, size_t *size)
if (buf == NULL)
goto fail;

while ((ret = read(fd, buf + len, capacity - len)) > 0) {
len += ret;
while ((n = read(fd, buf + len, capacity - len)) > 0) {
len += n;

if (capacity - len == 0) {
/* Grow buffer. */
Expand All @@ -540,7 +541,7 @@ static int read_proc_environ(pid_t pid, char **result, size_t *size)
}
}

if (ret < 0)
if (n < 0)
goto fail;

/* From man 5 proc, there might not be a null byte at the end. */
Expand Down

0 comments on commit edf2533

Please sign in to comment.