[v4,02/15] locale/programs/locarchive.c: fix warn unused result

Message ID 20230428122142.928135-3-fberat@redhat.com
State Committed
Commit d4ad86a0e1ca45517298307bd6ea47a27bd7a346
Delegated to: Siddhesh Poyarekar
Headers
Series Fix warn unused result |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Frederic Berat April 28, 2023, 12:21 p.m. UTC
  Changes since v2:
 - Freeing normalized_codeset before returning.

Changes since v3:
 - Rebased on master
--8<--

Fix unused result warnings, detected when _FORTIFY_SOURCE is enabled in
glibc.
---
 locale/programs/locarchive.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
  

Comments

Siddhesh Poyarekar May 24, 2023, 10:49 p.m. UTC | #1
On 2023-04-28 08:21, Frédéric Bérat wrote:
> Changes since v2:
>   - Freeing normalized_codeset before returning.
> 
> Changes since v3:
>   - Rebased on master
> --8<--
> 
> Fix unused result warnings, detected when _FORTIFY_SOURCE is enabled in
> glibc.
> ---
>   locale/programs/locarchive.c | 24 ++++++++++++++++--------
>   1 file changed, 16 insertions(+), 8 deletions(-)

LGTM.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

PS: Put the bits you don't want in the git commit (e.g. the changelog 
for your patch) after the --- above.  I've never been able to get the 
scissors to work correctly.

> 
> diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
> index 8d7d51af6c..71fd9f34fa 100644
> --- a/locale/programs/locarchive.c
> +++ b/locale/programs/locarchive.c
> @@ -1154,10 +1154,14 @@ add_locale_to_archive (struct locarhandle *ah, const char *name,
>     if (mask & XPG_NORM_CODESET)
>       /* This name contains a codeset in unnormalized form.
>          We will store it in the archive with a normalized name.  */
> -    asprintf (&normalized_name, "%s%s%s.%s%s%s",
> -	      language, territory == NULL ? "" : "_", territory ?: "",
> -	      normalized_codeset,
> -	      modifier == NULL ? "" : "@", modifier ?: "");
> +    if (asprintf (&normalized_name, "%s%s%s.%s%s%s",
> +		  language, territory == NULL ? "" : "_", territory ?: "",
> +		  normalized_codeset,
> +		  modifier == NULL ? "" : "@", modifier ?: "") < 0)
> +      {
> +	free ((char *) normalized_codeset);
> +	return -1;
> +      }
>   
>     /* This call does the main work.  */
>     locrec_offset = add_locale (ah, normalized_name ?: name, data, replace);
> @@ -1188,10 +1192,14 @@ add_locale_to_archive (struct locarhandle *ah, const char *name,
>         normalized_codeset = _nl_normalize_codeset (codeset, strlen (codeset));
>         mask |= XPG_NORM_CODESET;
>   
> -      asprintf (&normalized_codeset_name, "%s%s%s.%s%s%s",
> -		language, territory == NULL ? "" : "_", territory ?: "",
> -		normalized_codeset,
> -		modifier == NULL ? "" : "@", modifier ?: "");
> +      if (asprintf (&normalized_codeset_name, "%s%s%s.%s%s%s",
> +		    language, territory == NULL ? "" : "_", territory ?: "",
> +		    normalized_codeset,
> +		    modifier == NULL ? "" : "@", modifier ?: "") < 0)
> +	{
> +	  free ((char *) normalized_codeset);
> +	  return -1;
> +	}
>   
>         add_alias (ah, normalized_codeset_name, replace,
>   		 normalized_name ?: name, &locrec_offset);
  

Patch

diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
index 8d7d51af6c..71fd9f34fa 100644
--- a/locale/programs/locarchive.c
+++ b/locale/programs/locarchive.c
@@ -1154,10 +1154,14 @@  add_locale_to_archive (struct locarhandle *ah, const char *name,
   if (mask & XPG_NORM_CODESET)
     /* This name contains a codeset in unnormalized form.
        We will store it in the archive with a normalized name.  */
-    asprintf (&normalized_name, "%s%s%s.%s%s%s",
-	      language, territory == NULL ? "" : "_", territory ?: "",
-	      normalized_codeset,
-	      modifier == NULL ? "" : "@", modifier ?: "");
+    if (asprintf (&normalized_name, "%s%s%s.%s%s%s",
+		  language, territory == NULL ? "" : "_", territory ?: "",
+		  normalized_codeset,
+		  modifier == NULL ? "" : "@", modifier ?: "") < 0)
+      {
+	free ((char *) normalized_codeset);
+	return -1;
+      }
 
   /* This call does the main work.  */
   locrec_offset = add_locale (ah, normalized_name ?: name, data, replace);
@@ -1188,10 +1192,14 @@  add_locale_to_archive (struct locarhandle *ah, const char *name,
       normalized_codeset = _nl_normalize_codeset (codeset, strlen (codeset));
       mask |= XPG_NORM_CODESET;
 
-      asprintf (&normalized_codeset_name, "%s%s%s.%s%s%s",
-		language, territory == NULL ? "" : "_", territory ?: "",
-		normalized_codeset,
-		modifier == NULL ? "" : "@", modifier ?: "");
+      if (asprintf (&normalized_codeset_name, "%s%s%s.%s%s%s",
+		    language, territory == NULL ? "" : "_", territory ?: "",
+		    normalized_codeset,
+		    modifier == NULL ? "" : "@", modifier ?: "") < 0)
+	{
+	  free ((char *) normalized_codeset);
+	  return -1;
+	}
 
       add_alias (ah, normalized_codeset_name, replace,
 		 normalized_name ?: name, &locrec_offset);