From: Bruno Haible Date: Fri, 2 Jun 2023 23:32:23 +0000 (+0200) Subject: Silence "assignment discards ‘const’ qualifier from pointer target type" warnings. X-Git-Tag: v0.22~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29bf698aa374fff53fa302568224ff2648f4aff7;p=thirdparty%2Fgettext.git Silence "assignment discards ‘const’ qualifier from pointer target type" warnings. * gettext-tools/src/msginit.c (language_team_address): New local variable 'result'. (plural_forms): Adjust type of local variable 'dirs'. * gettext-tools/src/xg-message.c (remember_a_message): Reduce scope and adjust type of local variable 'msgstr'. (remember_a_message_plural): New local variable 'msgstr1_malloc'. * gettext-tools/src/xgettext.c (main): New local variable 'defaulted_output_dir'. --- diff --git a/gettext-tools/src/msginit.c b/gettext-tools/src/msginit.c index 21ac4cb4b..511cbb9fa 100644 --- a/gettext-tools/src/msginit.c +++ b/gettext-tools/src/msginit.c @@ -1,5 +1,5 @@ /* Initializes a new PO file. - Copyright (C) 2001-2022 Free Software Foundation, Inc. + Copyright (C) 2001-2023 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -1291,6 +1291,7 @@ language_team_address () char *line; size_t linesize; size_t linelen; + const char *result; int exitstatus; /* Call the team-address shell script. */ @@ -1317,9 +1318,13 @@ language_team_address () line = NULL; linesize = 0; linelen = getline (&line, &linesize, fp); if (linelen == (size_t)(-1)) - line = ""; - else if (linelen > 0 && line[linelen - 1] == '\n') - line[linelen - 1] = '\0'; + result = ""; + else + { + if (linelen > 0 && line[linelen - 1] == '\n') + line[linelen - 1] = '\0'; + result = line; + } fclose (fp); @@ -1332,7 +1337,7 @@ language_team_address () goto failed; } - return line; + return result; } failed: @@ -1434,7 +1439,8 @@ plural_forms () if (gettextcldrdir != NULL && gettextcldrdir[0] != '\0') { const char *gettextlibdir; - char *dirs[3], *last_dir; + const char *dirs[3]; + char *last_dir; const char *argv[4]; pid_t child; int fd[1]; diff --git a/gettext-tools/src/xg-message.c b/gettext-tools/src/xg-message.c index 818b8675f..281768768 100644 --- a/gettext-tools/src/xg-message.c +++ b/gettext-tools/src/xg-message.c @@ -249,7 +249,6 @@ remember_a_message (message_list_ty *mlp, char *msgctxt, char *msgid, enum is_wrap do_wrap; enum is_syntax_check do_syntax_check[NSYNTAXCHECKS]; message_ty *mp; - char *msgstr; size_t i; /* See whether we shall exclude this message. */ @@ -354,6 +353,8 @@ meta information, not the empty string.\n"))); } else { + const char *msgstr; + /* Construct the msgstr from the prefix and suffix, otherwise use the empty string. */ if (msgstr_prefix) @@ -557,10 +558,6 @@ remember_a_message_plural (message_ty *mp, char *string, bool is_utf8, bool comment_is_utf8) { char *msgid_plural; - char *msgstr1; - size_t msgstr1_len; - char *msgstr; - size_t i; msgid_plural = string; @@ -572,14 +569,23 @@ remember_a_message_plural (message_ty *mp, char *string, bool is_utf8, /* See if the message is already a plural message. */ if (mp->msgid_plural == NULL) { + char *msgstr1_malloc = NULL; + const char *msgstr1; + size_t msgstr1_len; + char *msgstr; + size_t i; + mp->msgid_plural = msgid_plural; /* Construct the first plural form from the prefix and suffix, otherwise use the empty string. The translator will have to provide additional plural forms. */ if (msgstr_prefix) - msgstr1 = - xasprintf ("%s%s%s", msgstr_prefix, msgid_plural, msgstr_suffix); + { + msgstr1_malloc = + xasprintf ("%s%s%s", msgstr_prefix, msgid_plural, msgstr_suffix); + msgstr1 = msgstr1_malloc; + } else msgstr1 = ""; msgstr1_len = strlen (msgstr1) + 1; @@ -588,8 +594,7 @@ remember_a_message_plural (message_ty *mp, char *string, bool is_utf8, memcpy (msgstr + mp->msgstr_len, msgstr1, msgstr1_len); mp->msgstr = msgstr; mp->msgstr_len = mp->msgstr_len + msgstr1_len; - if (msgstr_prefix) - free (msgstr1); + free (msgstr1_malloc); /* Determine whether the context specifies that the msgid_plural is a format string. */ diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index f271b5c05..cbfa9fe39 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -765,24 +765,27 @@ xgettext cannot work without keywords to look for")); else if (msgstr_prefix == NULL && msgstr_suffix != NULL) msgstr_prefix = ""; - /* Default output directory is the current directory. */ - if (output_dir == NULL) - output_dir = "."; + { + /* Default output directory is the current directory. */ + const char *defaulted_output_dir = (output_dir != NULL ? output_dir : "."); - /* Construct the name of the output file. If the default domain has - the special name "-" we write to stdout. */ - if (output_file) - { - if (IS_RELATIVE_FILE_NAME (output_file) && strcmp (output_file, "-") != 0) - /* Please do NOT add a .po suffix! */ - file_name = xconcatenated_filename (output_dir, output_file, NULL); - else - file_name = xstrdup (output_file); - } - else if (strcmp (default_domain, "-") == 0) - file_name = "-"; - else - file_name = xconcatenated_filename (output_dir, default_domain, ".po"); + /* Construct the name of the output file. If the default domain has + the special name "-" we write to stdout. */ + if (output_file) + { + if (IS_RELATIVE_FILE_NAME (output_file) && strcmp (output_file, "-") != 0) + /* Please do NOT add a .po suffix! */ + file_name = + xconcatenated_filename (defaulted_output_dir, output_file, NULL); + else + file_name = xstrdup (output_file); + } + else if (strcmp (default_domain, "-") == 0) + file_name = "-"; + else + file_name = + xconcatenated_filename (defaulted_output_dir, default_domain, ".po"); + } /* Determine list of files we have to process. */ if (files_from != NULL)