]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Avoid a few gcc warnings.
authorBruno Haible <bruno@clisp.org>
Thu, 19 Oct 2006 11:56:15 +0000 (11:56 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:14:10 +0000 (12:14 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/msgl-cat.c
gettext-tools/src/msgl-check.c
gettext-tools/src/po-error.h
gettext-tools/src/po-lex.h
gettext-tools/src/read-stringtable.c
gettext-tools/src/write-po.c
gettext-tools/src/xgettext.c

index 221cba960c003022f27b6afde169ac725908f0c6..6015c225804cc91084518e21cdb9b45b92f94d44 100644 (file)
@@ -1,3 +1,22 @@
+2006-10-18  Bruno Haible  <bruno@clisp.org>
+
+       * po-error.h (__attribute__, __format__, __printf__): New macros.
+       (po_error, po_error_at_line): Declare format string argument.
+       * po-lex.h (__attribute__, __format__, __printf__): New macros.
+       (po_gram_error, po_gram_error_at_line): Declare format string argument.
+
+       * msgl-cat.c (catenate_msgdomain_list): Avoid "gcc -Wshadow" warning.
+       * msgl-check.c (formatstring_error_logger): Avoid "gcc
+       -Wmissing-format-attribute" warning.
+       (check_pair): Avoid "gcc -Wshadow" warning.
+
+       * read-stringtable.c (stringtable_parse): Pass a mutable string as
+       msgstr to po_callback_message.
+       * write-po.c (msgdomain_list_print_po): Avoid "gcc -Wwrite-strings"
+       warning.
+       * xgettext.c (remember_a_message_plural): Free a temporary string
+       after use.
+
 2006-10-17  Bruno Haible  <bruno@clisp.org>
 
        * lang-table.c (language_table): Add the most important languages that
index 7cd92c6d74cad6633c1e56062bfe5c6782735a2a..02ffe730aa45296514b9bb16dfdb84bf4a2527b1 100644 (file)
@@ -115,7 +115,7 @@ catenate_msgdomain_list (string_list_ty *file_list,
   const char ***identifications;
   msgdomain_list_ty *total_mdlp;
   const char *canon_to_code;
-  size_t n, j, k;
+  size_t n, j;
 
   /* Read input files.  */
   mdlps =
@@ -284,6 +284,7 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s
   for (n = 0; n < nfiles; n++)
     {
       msgdomain_list_ty *mdlp = mdlps[n];
+      size_t k;
 
       for (k = 0; k < mdlp->nitems; k++)
        {
@@ -338,6 +339,7 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s
   for (n = 0; n < nfiles; n++)
     {
       msgdomain_list_ty *mdlp = mdlps[n];
+      size_t k;
 
       for (k = 0; k < mdlp->nitems; k++)
        {
@@ -353,12 +355,16 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s
            canon_charsets[n][k] = NULL;
        }
     }
-  for (k = 0; k < total_mdlp->nitems; k++)
-    {
-      message_list_ty *mlp = total_mdlp->item[k]->messages;
+  {
+    size_t k;
 
-      message_list_remove_if_not (mlp, is_message_selected);
-    }
+    for (k = 0; k < total_mdlp->nitems; k++)
+      {
+       message_list_ty *mlp = total_mdlp->item[k]->messages;
+
+       message_list_remove_if_not (mlp, is_message_selected);
+      }
+  }
 
   /* Determine the common known a-priori encoding, if any.  */
   if (nfiles > 0)
@@ -399,6 +405,7 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s
       for (n = 0; n < nfiles; n++)
        {
          msgdomain_list_ty *mdlp = mdlps[n];
+         size_t k;
 
          for (k = 0; k < mdlp->nitems; k++)
            if (canon_charsets[n][k] != NULL)
@@ -466,6 +473,7 @@ To select a different output encoding, use the --to-code option.\n\
     for (n = 0; n < nfiles; n++)
       {
        msgdomain_list_ty *mdlp = mdlps[n];
+       size_t k;
 
        for (k = 0; k < mdlp->nitems; k++)
          if (canon_charsets[n][k] != NULL)
@@ -493,6 +501,7 @@ UTF-8 encoded from the beginning, i.e. already in your source code files.\n"),
   for (n = 0; n < nfiles; n++)
     {
       msgdomain_list_ty *mdlp = mdlps[n];
+      size_t k;
 
       for (k = 0; k < mdlp->nitems; k++)
        {
@@ -603,154 +612,158 @@ UTF-8 encoded from the beginning, i.e. already in your source code files.\n"),
            }
        }
     }
-  for (k = 0; k < total_mdlp->nitems; k++)
-    {
-      message_list_ty *mlp = total_mdlp->item[k]->messages;
+  {
+    size_t k;
 
-      for (j = 0; j < mlp->nitems; j++)
-       {
-         message_ty *tmp = mlp->item[j];
+    for (k = 0; k < total_mdlp->nitems; k++)
+      {
+       message_list_ty *mlp = total_mdlp->item[k]->messages;
 
-         if (tmp->alternative_count > 0)
-           {
-             /* Test whether all alternative translations are equal.  */
-             struct altstr *first = &tmp->alternative[0];
-             size_t i;
+       for (j = 0; j < mlp->nitems; j++)
+         {
+           message_ty *tmp = mlp->item[j];
 
-             for (i = 0; i < tmp->alternative_count; i++)
-               if (!(tmp->alternative[i].msgstr_len == first->msgstr_len
-                     && memcmp (tmp->alternative[i].msgstr, first->msgstr,
-                                first->msgstr_len) == 0))
-                 break;
+           if (tmp->alternative_count > 0)
+             {
+               /* Test whether all alternative translations are equal.  */
+               struct altstr *first = &tmp->alternative[0];
+               size_t i;
 
-             if (i == tmp->alternative_count)
-               {
-                 /* All alternatives are equal.  */
-                 tmp->msgstr = first->msgstr;
-                 tmp->msgstr_len = first->msgstr_len;
-               }
-             else
-               {
-                 /* Concatenate the alternative msgstrs into a single one,
-                    separated by markers.  */
-                 size_t len;
-                 const char *p;
-                 const char *p_end;
-                 char *new_msgstr;
-                 char *np;
+               for (i = 0; i < tmp->alternative_count; i++)
+                 if (!(tmp->alternative[i].msgstr_len == first->msgstr_len
+                       && memcmp (tmp->alternative[i].msgstr, first->msgstr,
+                                  first->msgstr_len) == 0))
+                   break;
 
-                 len = 0;
-                 for (i = 0; i < tmp->alternative_count; i++)
-                   {
-                     size_t id_len = strlen (tmp->alternative[i].id);
+               if (i == tmp->alternative_count)
+                 {
+                   /* All alternatives are equal.  */
+                   tmp->msgstr = first->msgstr;
+                   tmp->msgstr_len = first->msgstr_len;
+                 }
+               else
+                 {
+                   /* Concatenate the alternative msgstrs into a single one,
+                      separated by markers.  */
+                   size_t len;
+                   const char *p;
+                   const char *p_end;
+                   char *new_msgstr;
+                   char *np;
+
+                   len = 0;
+                   for (i = 0; i < tmp->alternative_count; i++)
+                     {
+                       size_t id_len = strlen (tmp->alternative[i].id);
 
-                     len += tmp->alternative[i].msgstr_len;
+                       len += tmp->alternative[i].msgstr_len;
 
-                     p = tmp->alternative[i].msgstr;
-                     p_end = tmp->alternative[i].msgstr_end;
-                     for (; p < p_end; p += strlen (p) + 1)
-                       len += id_len + 2;
-                   }
+                       p = tmp->alternative[i].msgstr;
+                       p_end = tmp->alternative[i].msgstr_end;
+                       for (; p < p_end; p += strlen (p) + 1)
+                         len += id_len + 2;
+                     }
 
-                 new_msgstr = (char *) xmalloc (len);
-                 np = new_msgstr;
-                 for (;;)
-                   {
-                     /* Test whether there's one more plural form to
-                        process.  */
-                     for (i = 0; i < tmp->alternative_count; i++)
-                       if (tmp->alternative[i].msgstr
-                           < tmp->alternative[i].msgstr_end)
+                   new_msgstr = (char *) xmalloc (len);
+                   np = new_msgstr;
+                   for (;;)
+                     {
+                       /* Test whether there's one more plural form to
+                          process.  */
+                       for (i = 0; i < tmp->alternative_count; i++)
+                         if (tmp->alternative[i].msgstr
+                             < tmp->alternative[i].msgstr_end)
+                           break;
+                       if (i == tmp->alternative_count)
                          break;
-                     if (i == tmp->alternative_count)
-                       break;
 
-                     /* Process next plural form.  */
-                     for (i = 0; i < tmp->alternative_count; i++)
-                       if (tmp->alternative[i].msgstr
-                           < tmp->alternative[i].msgstr_end)
-                         {
-                           if (np > new_msgstr && np[-1] != '\0'
-                               && np[-1] != '\n')
+                       /* Process next plural form.  */
+                       for (i = 0; i < tmp->alternative_count; i++)
+                         if (tmp->alternative[i].msgstr
+                             < tmp->alternative[i].msgstr_end)
+                           {
+                             if (np > new_msgstr && np[-1] != '\0'
+                                 && np[-1] != '\n')
+                               *np++ = '\n';
+
+                             len = strlen (tmp->alternative[i].id);
+                             memcpy (np, tmp->alternative[i].id, len);
+                             np += len;
                              *np++ = '\n';
 
-                           len = strlen (tmp->alternative[i].id);
-                           memcpy (np, tmp->alternative[i].id, len);
-                           np += len;
-                           *np++ = '\n';
+                             len = strlen (tmp->alternative[i].msgstr);
+                             memcpy (np, tmp->alternative[i].msgstr, len);
+                             np += len;
+                             tmp->alternative[i].msgstr += len + 1;
+                           }
 
-                           len = strlen (tmp->alternative[i].msgstr);
-                           memcpy (np, tmp->alternative[i].msgstr, len);
-                           np += len;
-                           tmp->alternative[i].msgstr += len + 1;
-                         }
-
-                     /* Plural forms are separated by NUL bytes.  */
-                     *np++ = '\0';
-                   }
-                 tmp->msgstr = new_msgstr;
-                 tmp->msgstr_len = np - new_msgstr;
-
-                 tmp->is_fuzzy = true;
-               }
+                       /* Plural forms are separated by NUL bytes.  */
+                       *np++ = '\0';
+                     }
+                   tmp->msgstr = new_msgstr;
+                   tmp->msgstr_len = np - new_msgstr;
 
-             /* Test whether all alternative comments are equal.  */
-             for (i = 0; i < tmp->alternative_count; i++)
-               if (tmp->alternative[i].comment == NULL
-                   || !string_list_equal (tmp->alternative[i].comment,
-                                          first->comment))
-                 break;
+                   tmp->is_fuzzy = true;
+                 }
 
-             if (i == tmp->alternative_count)
-               /* All alternatives are equal.  */
-               tmp->comment = first->comment;
-             else
-               /* Concatenate the alternative comments into a single one,
-                  separated by markers.  */
+               /* Test whether all alternative comments are equal.  */
                for (i = 0; i < tmp->alternative_count; i++)
-                 {
-                   string_list_ty *slp = tmp->alternative[i].comment;
+                 if (tmp->alternative[i].comment == NULL
+                     || !string_list_equal (tmp->alternative[i].comment,
+                                            first->comment))
+                   break;
 
-                   if (slp != NULL)
-                     {
-                       size_t l;
+               if (i == tmp->alternative_count)
+                 /* All alternatives are equal.  */
+                 tmp->comment = first->comment;
+               else
+                 /* Concatenate the alternative comments into a single one,
+                    separated by markers.  */
+                 for (i = 0; i < tmp->alternative_count; i++)
+                   {
+                     string_list_ty *slp = tmp->alternative[i].comment;
 
-                       message_comment_append (tmp, tmp->alternative[i].id);
-                       for (l = 0; l < slp->nitems; l++)
-                         message_comment_append (tmp, slp->item[l]);
-                     }
-                 }
+                     if (slp != NULL)
+                       {
+                         size_t l;
 
-             /* Test whether all alternative dot comments are equal.  */
-             for (i = 0; i < tmp->alternative_count; i++)
-               if (tmp->alternative[i].comment_dot == NULL
-                   || !string_list_equal (tmp->alternative[i].comment_dot,
-                                          first->comment_dot))
-                 break;
+                         message_comment_append (tmp, tmp->alternative[i].id);
+                         for (l = 0; l < slp->nitems; l++)
+                           message_comment_append (tmp, slp->item[l]);
+                       }
+                   }
 
-             if (i == tmp->alternative_count)
-               /* All alternatives are equal.  */
-               tmp->comment_dot = first->comment_dot;
-             else
-               /* Concatenate the alternative dot comments into a single one,
-                  separated by markers.  */
+               /* Test whether all alternative dot comments are equal.  */
                for (i = 0; i < tmp->alternative_count; i++)
-                 {
-                   string_list_ty *slp = tmp->alternative[i].comment_dot;
+                 if (tmp->alternative[i].comment_dot == NULL
+                     || !string_list_equal (tmp->alternative[i].comment_dot,
+                                            first->comment_dot))
+                   break;
 
-                   if (slp != NULL)
-                     {
-                       size_t l;
+               if (i == tmp->alternative_count)
+                 /* All alternatives are equal.  */
+                 tmp->comment_dot = first->comment_dot;
+               else
+                 /* Concatenate the alternative dot comments into a single one,
+                    separated by markers.  */
+                 for (i = 0; i < tmp->alternative_count; i++)
+                   {
+                     string_list_ty *slp = tmp->alternative[i].comment_dot;
 
-                       message_comment_dot_append (tmp,
-                                                   tmp->alternative[i].id);
-                       for (l = 0; l < slp->nitems; l++)
-                         message_comment_dot_append (tmp, slp->item[l]);
-                     }
-                 }
-           }
-       }
-    }
+                     if (slp != NULL)
+                       {
+                         size_t l;
+
+                         message_comment_dot_append (tmp,
+                                                     tmp->alternative[i].id);
+                         for (l = 0; l < slp->nitems; l++)
+                           message_comment_dot_append (tmp, slp->item[l]);
+                       }
+                   }
+             }
+         }
+      }
+  }
 
   return total_mdlp;
 }
index efca51b993331719e2e1135b5528dad4b32b42eb..4d7a5c1eb72684e18063c4437d508e84e8e4ba92 100644 (file)
@@ -440,6 +440,9 @@ check_plural (message_list_ty *mlp, unsigned char **plural_distribution)
 static const message_ty *curr_mp;
 static lex_pos_ty curr_msgid_pos;
 static void
+formatstring_error_logger (const char *format, ...)
+     __attribute__ ((__format__ (__printf__, 1, 2)));
+static void
 formatstring_error_logger (const char *format, ...)
 {
   va_list args;
@@ -475,7 +478,6 @@ check_pair (const message_ty *mp,
   int seen_errors;
   int has_newline;
   unsigned int j;
-  const char *p;
 
   /* If the msgid string is empty we have the special entry reserved for
      information about the translation.  */
@@ -491,6 +493,8 @@ check_pair (const message_ty *mp,
 #define TEST_NEWLINE(p) (p[0] == '\n')
       if (msgid_plural != NULL)
        {
+         const char *p;
+
          if (TEST_NEWLINE(msgid_plural) != has_newline)
            {
              po_xerror (PO_SEVERITY_ERROR,
@@ -530,6 +534,8 @@ check_pair (const message_ty *mp,
 #define TEST_NEWLINE(p) (p[0] != '\0' && p[strlen (p) - 1] == '\n')
       if (msgid_plural != NULL)
        {
+         const char *p;
+
          if (TEST_NEWLINE(msgid_plural) != has_newline)
            {
              po_xerror (PO_SEVERITY_ERROR,
index c7564ee1007f933716ed0d7addcd2e5bf357b68e..71e6a14250ae57bb297d3d060d16d40260b9f551 100644 (file)
@@ -1,5 +1,5 @@
 /* Error handling during reading and writing of PO files.
-   Copyright (C) 2004 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2006 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2004.
 
    This program is free software; you can redistribute it and/or modify
 #ifndef _PO_ERROR_H
 #define _PO_ERROR_H
 
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+#  define __attribute__(Spec) /* empty */
+# endif
+/* The __-protected variants of `format' and `printf' attributes
+   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#  define __format__ format
+#  define __printf__ printf
+# endif
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif 
@@ -32,11 +45,13 @@ extern "C" {
 
 extern DLL_VARIABLE
        void (*po_error) (int status, int errnum,
-                        const char *format, ...);
+                        const char *format, ...)
+       __attribute__ ((__format__ (__printf__, 3, 4)));
 extern DLL_VARIABLE
        void (*po_error_at_line) (int status, int errnum,
                                 const char *filename, unsigned int lineno,
-                                const char *format, ...);
+                                const char *format, ...)
+       __attribute__ ((__format__ (__printf__, 5, 6)));
 
 /* Both functions must work like the xerror.h multiline_warning(),
    multiline_error() functions.  In particular,
index 17adace6620e7108d124960294f6d8ac57bd3fed..b6321f2b32eb064828aefe72de3666d446458ea1 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU gettext - internationalization aids
-   Copyright (C) 1995-1998, 2000-2005 Free Software Foundation, Inc.
+   Copyright (C) 1995-1998, 2000-2006 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
 
 #include "xerror.h"
 #include "pos.h"
 
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+#  define __attribute__(Spec) /* empty */
+# endif
+/* The __-protected variants of `format' and `printf' attributes
+   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#  define __format__ format
+#  define __printf__ printf
+# endif
+#endif
+
 
 #ifdef __cplusplus
 extern "C" {
@@ -69,8 +82,10 @@ extern void po_lex_pass_comments (bool flag);
    Switch this on or off.  */
 extern void po_lex_pass_obsolete_entries (bool flag);
 
-extern void po_gram_error (const char *fmt, ...);
-extern void po_gram_error_at_line (const lex_pos_ty *pos, const char *fmt, ...);
+extern void po_gram_error (const char *fmt, ...)
+       __attribute__ ((__format__ (__printf__, 1, 2)));
+extern void po_gram_error_at_line (const lex_pos_ty *pos, const char *fmt, ...)
+       __attribute__ ((__format__ (__printf__, 2, 3)));
 
 
 /* Contains information about the definition of one translation.  */
index 771ce1988528ce28eab863bd83280cefb5df2c80..c1cb64647c08e994422cb7c5887472cc9c6d3d4b 100644 (file)
@@ -877,7 +877,7 @@ stringtable_parse (abstract_catalog_reader_ty *pop, FILE *file,
        {
          /* "key"; is an abbreviation for "key"=""; and does not
             necessarily designate an untranslated entry.  */
-         msgstr = "";
+         msgstr = xstrdup ("");
          msgstr_pos = msgid_pos;
          po_callback_message (NULL, msgid, &msgid_pos, NULL,
                               msgstr, strlen (msgstr) + 1, &msgstr_pos,
index 631f2047bf44db84655cb01c47004388cc32970b..2d8b49d6e43a6c3ba961938ca83e032917a6c999 100644 (file)
@@ -1021,7 +1021,7 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, size_t page_width,
     {
       message_list_ty *mlp;
       const char *header;
-      char *charset;
+      const char *charset;
       char *allocated_charset;
 
       /* If the first domain is the default, don't bother emitting
@@ -1059,9 +1059,10 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, size_t page_width,
 
              charsetstr += strlen ("charset=");
              len = strcspn (charsetstr, " \t\n");
-             charset = allocated_charset = (char *) xallocsa (len + 1);
-             memcpy (charset, charsetstr, len);
-             charset[len] = '\0';
+             allocated_charset = (char *) xallocsa (len + 1);
+             memcpy (allocated_charset, charsetstr, len);
+             allocated_charset[len] = '\0';
+             charset = allocated_charset;
 
              /* Treat the dummy default value as if it were absent.  */
              if (strcmp (charset, "CHARSET") == 0)
index 97d42300484df353285ae9ec8e3964f897c10256..48f96435f2d0860f32615323f9f0da67997b5a83 100644 (file)
@@ -2252,6 +2252,8 @@ remember_a_message_plural (message_ty *mp, char *string,
       memcpy (msgstr + mp->msgstr_len, msgstr1, msgstr1_len);
       mp->msgstr = msgstr;
       mp->msgstr_len = mp->msgstr_len + msgstr1_len;
+      if (msgstr_prefix)
+       free (msgstr1);
 
       /* Determine whether the context specifies that the msgid_plural is a
         format string.  */