From: Bruno Haible Date: Thu, 19 Oct 2006 11:56:15 +0000 (+0000) Subject: Avoid a few gcc warnings. X-Git-Tag: 0.16.x-branchpoint~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81b4a81232eab750fc6ceed0bb2ff5b458317dbe;p=thirdparty%2Fgettext.git Avoid a few gcc warnings. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 221cba960..6015c2258 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,22 @@ +2006-10-18 Bruno Haible + + * 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 * lang-table.c (language_table): Add the most important languages that diff --git a/gettext-tools/src/msgl-cat.c b/gettext-tools/src/msgl-cat.c index 7cd92c6d7..02ffe730a 100644 --- a/gettext-tools/src/msgl-cat.c +++ b/gettext-tools/src/msgl-cat.c @@ -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; } diff --git a/gettext-tools/src/msgl-check.c b/gettext-tools/src/msgl-check.c index efca51b99..4d7a5c1eb 100644 --- a/gettext-tools/src/msgl-check.c +++ b/gettext-tools/src/msgl-check.c @@ -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, diff --git a/gettext-tools/src/po-error.h b/gettext-tools/src/po-error.h index c7564ee10..71e6a1425 100644 --- a/gettext-tools/src/po-error.h +++ b/gettext-tools/src/po-error.h @@ -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 , 2004. This program is free software; you can redistribute it and/or modify @@ -19,6 +19,19 @@ #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, diff --git a/gettext-tools/src/po-lex.h b/gettext-tools/src/po-lex.h index 17adace66..b6321f2b3 100644 --- a/gettext-tools/src/po-lex.h +++ b/gettext-tools/src/po-lex.h @@ -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 @@ -28,6 +28,19 @@ #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. */ diff --git a/gettext-tools/src/read-stringtable.c b/gettext-tools/src/read-stringtable.c index 771ce1988..c1cb64647 100644 --- a/gettext-tools/src/read-stringtable.c +++ b/gettext-tools/src/read-stringtable.c @@ -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, diff --git a/gettext-tools/src/write-po.c b/gettext-tools/src/write-po.c index 631f2047b..2d8b49d6e 100644 --- a/gettext-tools/src/write-po.c +++ b/gettext-tools/src/write-po.c @@ -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) diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index 97d423004..48f96435f 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -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. */