Re: [hackers] [sbase] tar: check if reallocarray failed

2021-07-18 Thread Laslo Hunhold
On Sat, 17 Jul 2021 21:04:04 +0200
Hiltjo Posthuma  wrote:

Dear Hiltjo,

> The patch below is for sbase tar:
>
> From 2eec3e07a5bd1ed1fa41ca02865297ab7d8b5fa8 Mon Sep 17 00:00:00 2001
> From: Hiltjo Posthuma 
> Date: Sat, 17 Jul 2021 21:03:27 +0200
> Subject: [PATCH] tar: check if reallocarray failed
> 
> ---
>  tar.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tar.c b/tar.c
> index b74c134..122f30a 100644
> --- a/tar.c
> +++ b/tar.c
> @@ -78,7 +78,7 @@ static const char *filtertools[] = {
>  static void
>  pushdirtime(char *name, time_t mtime)
>  {
> - dirtimes = reallocarray(dirtimes, dirtimeslen + 1,
> sizeof(*dirtimes));
> + dirtimes = ereallocarray(dirtimes, dirtimeslen + 1,
> sizeof(*dirtimes)); dirtimes[dirtimeslen].name = strdup(name);
>   dirtimes[dirtimeslen].mtime = mtime;
>   dirtimeslen++;

ah yes, good catch! While at it, we might also want to check the
strdup() in the consecutive line, right?

With best regards

Laslo



[hackers] [sbase] tar: check if reallocarray failed

2021-07-17 Thread Hiltjo Posthuma
Hi,

The patch below is for sbase tar:


>From 2eec3e07a5bd1ed1fa41ca02865297ab7d8b5fa8 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma 
Date: Sat, 17 Jul 2021 21:03:27 +0200
Subject: [PATCH] tar: check if reallocarray failed

---
 tar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tar.c b/tar.c
index b74c134..122f30a 100644
--- a/tar.c
+++ b/tar.c
@@ -78,7 +78,7 @@ static const char *filtertools[] = {
 static void
 pushdirtime(char *name, time_t mtime)
 {
-   dirtimes = reallocarray(dirtimes, dirtimeslen + 1, sizeof(*dirtimes));
+   dirtimes = ereallocarray(dirtimes, dirtimeslen + 1, sizeof(*dirtimes));
dirtimes[dirtimeslen].name = strdup(name);
dirtimes[dirtimeslen].mtime = mtime;
dirtimeslen++;
-- 
2.32.0

-- 
Kind regards,
Hiltjo