[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fix two regressions in vasnprintf
From: |
Bruno Haible |
Subject: |
fix two regressions in vasnprintf |
Date: |
Sat, 27 Mar 2021 01:23:54 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-203-generic; KDE/5.18.0; x86_64; ; ) |
> commit e639e557f1b09a4f5589377705a30c4014b76924
> Author: Akim Demaille <akim.demaille@gmail.com>
> Date: Fri Mar 26 06:40:06 2021 +0100
>
> fprintf-posix: fix typo
>
> * modules/fprintf-posix (Depends-on): Fix typo.
There were also two regressions in yesterday's patch. Fixed through the
following:
2021-03-26 Bruno Haible <bruno@clisp.org>
vasnprintf: Fix memory leak (regression from yesterday).
* lib/vasnprintf.c (VASNPRINTF): Restore omitted CLEANUP invocation.
Some more simplifications of errno around free().
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 3fc9be5..272fe2a 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -1859,6 +1859,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
/* errno is already set. */
return NULL;
+ /* Frees the memory allocated by this function. Preserves errno. */
#define CLEANUP() \
if (d.dir != d.direct_alloc_dir) \
free (d.dir); \
@@ -2187,6 +2188,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
+ CLEANUP ();
return NULL;
}
if (converted != result + length)
@@ -2306,13 +2308,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
# endif
if (converted == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
if (converted != result + length)
@@ -2432,13 +2432,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
# endif
if (converted == NULL)
{
- int saved_errno = errno;
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
if (converted != result + length)
@@ -2849,14 +2847,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
NULL, &tmpdst_len);
if (tmpdst == NULL)
{
- int saved_errno = errno;
free (tmpsrc);
if (!(result == resultbuf || result == NULL))
free (result);
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
free (tmpsrc);
@@ -5444,15 +5440,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
/* Attempt to handle failure. */
if (count < 0)
{
- /* SNPRINTF or sprintf failed. Save and use the errno
- that it has set, if any. */
- int saved_errno = errno;
- if (saved_errno == 0)
+ /* SNPRINTF or sprintf failed. Use the errno that it
+ has set, if any. */
+ if (errno == 0)
{
if (dp->conversion == 'c' || dp->conversion == 's')
- saved_errno = EILSEQ;
+ errno = EILSEQ;
else
- saved_errno = EINVAL;
+ errno = EINVAL;
}
if (!(result == resultbuf || result == NULL))
@@ -5461,7 +5456,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
free (buf_malloced);
CLEANUP ();
- errno = saved_errno;
return NULL;
}
2021-03-26 Bruno Haible <bruno@clisp.org>
unistdio/*-vasnprintf: Fix errno value (regression from yesterday).
* modules/unistdio/u8-vasnprintf (Depends-on): Add free-posix.
* modules/unistdio/u8-u8-vasnprintf (Depends-on): Likewise.
* modules/unistdio/u16-vasnprintf (Depends-on): Likewise.
* modules/unistdio/u16-u16-vasnprintf (Depends-on): Likewise.
* modules/unistdio/u32-vasnprintf (Depends-on): Likewise.
* modules/unistdio/u32-u32-vasnprintf (Depends-on): Likewise.
* modules/unistdio/ulc-vasnprintf (Depends-on): Likewise.
diff --git a/modules/unistdio/u16-u16-vasnprintf
b/modules/unistdio/u16-u16-vasnprintf
index cae6372..d5ca9c2 100644
--- a/modules/unistdio/u16-u16-vasnprintf
+++ b/modules/unistdio/u16-u16-vasnprintf
@@ -44,6 +44,7 @@ alloca-opt
localcharset
xsize
errno
+free-posix
memchr
multiarch
verify
diff --git a/modules/unistdio/u16-vasnprintf b/modules/unistdio/u16-vasnprintf
index 940ff2e..aad9cd8b 100644
--- a/modules/unistdio/u16-vasnprintf
+++ b/modules/unistdio/u16-vasnprintf
@@ -44,6 +44,7 @@ alloca-opt
localcharset
xsize
errno
+free-posix
memchr
multiarch
verify
diff --git a/modules/unistdio/u32-u32-vasnprintf
b/modules/unistdio/u32-u32-vasnprintf
index 358cb73..861eef2 100644
--- a/modules/unistdio/u32-u32-vasnprintf
+++ b/modules/unistdio/u32-u32-vasnprintf
@@ -44,6 +44,7 @@ alloca-opt
localcharset
xsize
errno
+free-posix
memchr
multiarch
verify
diff --git a/modules/unistdio/u32-vasnprintf b/modules/unistdio/u32-vasnprintf
index 2167c47..847ffd2 100644
--- a/modules/unistdio/u32-vasnprintf
+++ b/modules/unistdio/u32-vasnprintf
@@ -44,6 +44,7 @@ alloca-opt
localcharset
xsize
errno
+free-posix
memchr
multiarch
verify
diff --git a/modules/unistdio/u8-u8-vasnprintf
b/modules/unistdio/u8-u8-vasnprintf
index 6ac98b6..4a953fb 100644
--- a/modules/unistdio/u8-u8-vasnprintf
+++ b/modules/unistdio/u8-u8-vasnprintf
@@ -44,6 +44,7 @@ alloca-opt
localcharset
xsize
errno
+free-posix
memchr
multiarch
verify
diff --git a/modules/unistdio/u8-vasnprintf b/modules/unistdio/u8-vasnprintf
index 7a66540..592b2c0 100644
--- a/modules/unistdio/u8-vasnprintf
+++ b/modules/unistdio/u8-vasnprintf
@@ -44,6 +44,7 @@ alloca-opt
localcharset
xsize
errno
+free-posix
memchr
multiarch
verify
diff --git a/modules/unistdio/ulc-vasnprintf b/modules/unistdio/ulc-vasnprintf
index 9c8f48f..a09a14c 100644
--- a/modules/unistdio/ulc-vasnprintf
+++ b/modules/unistdio/ulc-vasnprintf
@@ -42,6 +42,7 @@ alloca-opt
localcharset
xsize
errno
+free-posix
memchr
multiarch
verify