From: Bruno Haible Date: Sat, 11 Nov 2023 15:48:13 +0000 (+0100) Subject: libgettextpo: Remove static variable 'result.0'. X-Git-Tag: v0.23~311 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ae99bae8bdac6e7f192682823ac9db3a21bd483;p=thirdparty%2Fgettext.git libgettextpo: Remove static variable 'result.0'. * gettext-tools/src/write-po.h (make_format_description_string): Change return type to 'char *'. * gettext-tools/src/write-po.c (make_format_description_string): Return a freshly allocated string. (message_print_comment_flags, message_print_obsolete): Free the result of make_format_description_string when done. * gettext-tools/src/write-stringtable.c (write_message): Likewise. --- diff --git a/gettext-tools/src/write-po.c b/gettext-tools/src/write-po.c index 875ced539..1c03b2932 100644 --- a/gettext-tools/src/write-po.c +++ b/gettext-tools/src/write-po.c @@ -62,33 +62,34 @@ /* Convert IS_FORMAT in the context of programming language LANG to a flag string for use in #, flags. */ -const char * +char * make_format_description_string (enum is_format is_format, const char *lang, bool debug) { - static char result[100]; + char *result; switch (is_format) { case possible: if (debug) { - sprintf (result, "possible-%s-format", lang); + result = xasprintf ("possible-%s-format", lang); break; } FALLTHROUGH; case yes_according_to_context: case yes: - sprintf (result, "%s-format", lang); + result = xasprintf ("%s-format", lang); break; case no: - sprintf (result, "no-%s-format", lang); + result = xasprintf ("no-%s-format", lang); break; default: /* The others have already been filtered out by significant_format_p. */ abort (); } + assume (result != NULL); return result; } @@ -486,15 +487,17 @@ message_print_comment_flags (const message_ty *mp, ostream_t stream, bool debug) for (i = 0; i < NFORMATS; i++) if (significant_format_p (mp->is_format[i])) { + char *string; + if (!first_flag) ostream_write_str (stream, ","); ostream_write_str (stream, " "); begin_css_class (stream, class_flag); - ostream_write_str (stream, - make_format_description_string (mp->is_format[i], - format_language[i], - debug)); + string = make_format_description_string (mp->is_format[i], + format_language[i], debug); + ostream_write_str (stream, string); + free (string); end_css_class (stream, class_flag); first_flag = false; } @@ -1482,14 +1485,16 @@ message_print_obsolete (const message_ty *mp, ostream_t stream, for (i = 0; i < NFORMATS; i++) if (significant_format_p (mp->is_format[i])) { + char *string; + if (!first_flag) ostream_write_str (stream, ","); ostream_write_str (stream, " "); - ostream_write_str (stream, - make_format_description_string (mp->is_format[i], - format_language[i], - debug)); + string = make_format_description_string (mp->is_format[i], + format_language[i], debug); + ostream_write_str (stream, string); + free (string); first_flag = false; } diff --git a/gettext-tools/src/write-po.h b/gettext-tools/src/write-po.h index 47dd7b190..49ae1c024 100644 --- a/gettext-tools/src/write-po.h +++ b/gettext-tools/src/write-po.h @@ -40,9 +40,10 @@ enum filepos_comment_type }; /* These functions are used to output a #, flags line. */ -extern const char * +extern char * make_format_description_string (enum is_format is_format, - const char *lang, bool debug); + const char *lang, bool debug) + ATTRIBUTE_MALLOC; extern bool significant_format_p (enum is_format is_format); diff --git a/gettext-tools/src/write-stringtable.c b/gettext-tools/src/write-stringtable.c index bff51818f..a86c9d9a7 100644 --- a/gettext-tools/src/write-stringtable.c +++ b/gettext-tools/src/write-stringtable.c @@ -1,5 +1,5 @@ /* Writing NeXTstep/GNUstep .strings files. - Copyright (C) 2003, 2006-2008, 2019, 2021 Free Software Foundation, Inc. + Copyright (C) 2003-2023 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software: you can redistribute it and/or modify @@ -216,11 +216,13 @@ write_message (ostream_t stream, const message_ty *mp, for (i = 0; i < NFORMATS; i++) if (significant_format_p (mp->is_format[i])) { + char *string; + ostream_write_str (stream, "/* Flag: "); - ostream_write_str (stream, - make_format_description_string (mp->is_format[i], - format_language[i], - debug)); + string = make_format_description_string (mp->is_format[i], + format_language[i], debug); + ostream_write_str (stream, string); + free (string); ostream_write_str (stream, " */\n"); } }