diff mbox series

[v2] tst_tmpdir: Do not SegFault when .needs_tmpdir was not set

Message ID 20240724092238.6774-1-chrubis@suse.cz
State Accepted
Headers show
Series [v2] tst_tmpdir: Do not SegFault when .needs_tmpdir was not set | expand

Commit Message

Cyril Hrubis July 24, 2024, 9:22 a.m. UTC
Print TBROK message about the missing .needs_tmpdir flag instead.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
v2: Fix warning about undefined tst_brk() this is an old library
    file hence we need tst_brkm().

 lib/tst_tmpdir.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Li Wang July 24, 2024, 12:49 p.m. UTC | #1
On Wed, Jul 24, 2024 at 5:23 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> Print TBROK message about the missing .needs_tmpdir flag instead.
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
>

Reviewed-by: Li Wang <liwang@redhat.com>

---
> v2: Fix warning about undefined tst_brk() this is an old library
>     file hence we need tst_brkm().
>
>  lib/tst_tmpdir.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/lib/tst_tmpdir.c b/lib/tst_tmpdir.c
> index 1fb1bd698..7986f1bc0 100644
> --- a/lib/tst_tmpdir.c
> +++ b/lib/tst_tmpdir.c
> @@ -358,6 +358,9 @@ char *tst_tmpdir_path(void)
>  {
>         static char *tmpdir;
>
> +       if (!TESTDIR)
> +               tst_brkm(TBROK, NULL, ".needs_tmpdir must be set!");
> +
>         if (tmpdir)
>                 return tmpdir;
>
> @@ -368,11 +371,16 @@ char *tst_tmpdir_path(void)
>
>  char *tst_tmpdir_mkpath(const char *fmt, ...)
>  {
> -       size_t testdir_len = strlen(TESTDIR);
> -       size_t path_len = testdir_len;
> +       size_t testdir_len, path_len;
>         va_list va, vac;
>         char *ret;
>
> +       if (!TESTDIR)
> +               tst_brkm(TBROK, NULL, ".needs_tmpdir must be set!");
> +
> +       testdir_len = strlen(TESTDIR);
> +       path_len = testdir_len;
> +
>         va_start(va, fmt);
>         va_copy(vac, va);
>         path_len += vsnprintf(NULL, 0, fmt, va) + 2;
> --
> 2.44.2
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>
Petr Vorel July 25, 2024, 10:12 a.m. UTC | #2
Hi Cyril,

thanks a lot for fixing this, I dared to merge it.

Kind regards,
Petr
diff mbox series

Patch

diff --git a/lib/tst_tmpdir.c b/lib/tst_tmpdir.c
index 1fb1bd698..7986f1bc0 100644
--- a/lib/tst_tmpdir.c
+++ b/lib/tst_tmpdir.c
@@ -358,6 +358,9 @@  char *tst_tmpdir_path(void)
 {
 	static char *tmpdir;
 
+	if (!TESTDIR)
+		tst_brkm(TBROK, NULL, ".needs_tmpdir must be set!");
+
 	if (tmpdir)
 		return tmpdir;
 
@@ -368,11 +371,16 @@  char *tst_tmpdir_path(void)
 
 char *tst_tmpdir_mkpath(const char *fmt, ...)
 {
-	size_t testdir_len = strlen(TESTDIR);
-	size_t path_len = testdir_len;
+	size_t testdir_len, path_len;
 	va_list va, vac;
 	char *ret;
 
+	if (!TESTDIR)
+		tst_brkm(TBROK, NULL, ".needs_tmpdir must be set!");
+
+	testdir_len = strlen(TESTDIR);
+	path_len = testdir_len;
+
 	va_start(va, fmt);
 	va_copy(vac, va);
 	path_len += vsnprintf(NULL, 0, fmt, va) + 2;