[4/8] locale/programs/locarchive.c: 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
Fix unused result warnings, detected when _FORTIFY_SOURCE is enabled in
glibc.
---
locale/programs/locarchive.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
Comments
On 2023-04-18 08:11, Frédéric Bérat via Libc-alpha wrote:
> Fix unused result warnings, detected when _FORTIFY_SOURCE is enabled in
> glibc.
> ---
> locale/programs/locarchive.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
> index 87d2d9b1b2..4e13bb9ce9 100644
> --- a/locale/programs/locarchive.c
> +++ b/locale/programs/locarchive.c
> @@ -1154,10 +1154,11 @@ 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 ?: "",
> - (mask & XPG_NORM_CODESET) ? normalized_codeset : codeset,
> - modifier == NULL ? "" : "@", modifier ?: "");
> + if (asprintf (&normalized_name, "%s%s%s.%s%s%s",
> + language, territory == NULL ? "" : "_", territory ?: "",
> + (mask & XPG_NORM_CODESET) ? normalized_codeset : codeset,
> + modifier == NULL ? "" : "@", modifier ?: "") < 0)
> + return -1;
Wouldn't this leak normalized_codeset?
Also, this is within if (mask & XPG_NORM_CODESET), so the:
(mask & XPG_NORM_CODESET) ? normalized_codeset : codeset
looks unnecessary, doesn't it? I know that's how the original code is,
but maybe it's worth cleaning up while you're there. In a separate
patch though please.
>
> /* This call does the main work. */
> locrec_offset = add_locale (ah, normalized_name ?: name, data, replace);
> @@ -1188,10 +1189,11 @@ 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)
> + return -1;
Likewise.
>
> add_alias (ah, normalized_codeset_name, replace,
> normalized_name ?: name, &locrec_offset);
@@ -1154,10 +1154,11 @@ 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 ?: "",
- (mask & XPG_NORM_CODESET) ? normalized_codeset : codeset,
- modifier == NULL ? "" : "@", modifier ?: "");
+ if (asprintf (&normalized_name, "%s%s%s.%s%s%s",
+ language, territory == NULL ? "" : "_", territory ?: "",
+ (mask & XPG_NORM_CODESET) ? normalized_codeset : codeset,
+ modifier == NULL ? "" : "@", modifier ?: "") < 0)
+ return -1;
/* This call does the main work. */
locrec_offset = add_locale (ah, normalized_name ?: name, data, replace);
@@ -1188,10 +1189,11 @@ 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)
+ return -1;
add_alias (ah, normalized_codeset_name, replace,
normalized_name ?: name, &locrec_offset);