]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libgettextpo: Remove static variable 'result.0'.
authorBruno Haible <bruno@clisp.org>
Sat, 11 Nov 2023 15:48:13 +0000 (16:48 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 11 Nov 2023 15:48:13 +0000 (16:48 +0100)
* 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.

gettext-tools/src/write-po.c
gettext-tools/src/write-po.h
gettext-tools/src/write-stringtable.c

index 875ced539648cdbcaf00f388085b1fef13b3a363..1c03b2932f5a15828a5db62ea9c82de5db0d5fdb 100644 (file)
 /* 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;
           }
 
index 47dd7b19057c19d0500e1a413c9068c13071a5d6..49ae1c024157973bc8294a649f97efcbd58c0de8 100644 (file)
@@ -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);
 
index bff51818f917bab74c53453fe8c48492126cce2a..a86c9d9a78d4264dc739a3176a471a1950ada7a7 100644 (file)
@@ -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 <bruno@clisp.org>, 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");
         }
   }