mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-04-14 14:41:42 +03:00
Fix wrong type for malloc_read_fd return value in prof_stack_range
Used size_t (unsigned) instead of ssize_t for the return value of malloc_read_fd, which returns -1 on error. With size_t, -1 becomes a huge positive value, bypassing the error check and corrupting the remaining byte count.
This commit is contained in:
parent
dd30c91eaa
commit
3f6e63e86a
1 changed files with 10 additions and 4 deletions
|
|
@ -73,17 +73,21 @@ prof_mapping_containing_addr(uintptr_t addr, const char *maps_path,
|
|||
}
|
||||
|
||||
remaining = malloc_read_fd(fd, buf, sizeof(buf));
|
||||
if (remaining <= 0) {
|
||||
if (remaining < 0) {
|
||||
ret = errno;
|
||||
break;
|
||||
} else if (remaining == 0) {
|
||||
break;
|
||||
}
|
||||
line = buf;
|
||||
} else if (line == NULL) {
|
||||
/* case 1: no newline found in buf */
|
||||
remaining = malloc_read_fd(fd, buf, sizeof(buf));
|
||||
if (remaining <= 0) {
|
||||
if (remaining < 0) {
|
||||
ret = errno;
|
||||
break;
|
||||
} else if (remaining == 0) {
|
||||
break;
|
||||
}
|
||||
line = memchr(buf, '\n', remaining);
|
||||
if (line != NULL) {
|
||||
|
|
@ -99,11 +103,13 @@ prof_mapping_containing_addr(uintptr_t addr, const char *maps_path,
|
|||
remaining); /* copy remaining characters to start of buf */
|
||||
line = buf;
|
||||
|
||||
size_t count = malloc_read_fd(
|
||||
ssize_t count = malloc_read_fd(
|
||||
fd, buf + remaining, sizeof(buf) - remaining);
|
||||
if (count <= 0) {
|
||||
if (count < 0) {
|
||||
ret = errno;
|
||||
break;
|
||||
} else if (count == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
remaining +=
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue