diff options
| author | Thomas Weißschuh <thomas@t-8ch.de> | 2023-09-22 11:56:42 +0200 |
|---|---|---|
| committer | Thomas Weißschuh <thomas@t-8ch.de> | 2023-09-22 11:56:42 +0200 |
| commit | 64d6d400f601dd20f65d66539fdecf536e4d52b5 (patch) | |
| tree | 140b19901b6b6eca466b9a135b129890230ccd68 /lib/loopdev.c | |
| parent | 1e0ad14b3ac08d855cda6de346a65f9b834e00db (diff) | |
| download | util-linux-64d6d400f601dd20f65d66539fdecf536e4d52b5.tar.gz | |
treewide: use (x)reallocarray() when applicable
reallocarray() prevents overflow of the multiplication.
It also avoids issues with operator precedence like in libmount/src/context.c:
pids = realloc(cxt->children, sizeof(pid_t) * cxt->nchildren + 1);
This only allocated one additional byte, and not enough space for
another child.
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
Diffstat (limited to 'lib/loopdev.c')
| -rw-r--r-- | lib/loopdev.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/loopdev.c b/lib/loopdev.c index 323f7bd50d..dae499f256 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -495,7 +495,7 @@ static int loop_scandir(const char *dirname, int **ary, int hasprefix) arylen += 1; - tmp = realloc(*ary, arylen * sizeof(int)); + tmp = reallocarray(*ary, arylen, sizeof(int)); if (!tmp) { free(*ary); *ary = NULL; |
