From 0ee87eb94f2caf13bf20be6a1024e18661f8a5fb Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 1 Jan 2025 00:49:01 +0100 Subject: [PATCH] msgfmt: Fix python-brace-format checking. Reported at . * gettext-tools/src/format-python-brace.c (format_check): Fix comment. Do the cmp > 0 check also if equality==false. * gettext-tools/src/format-python.c (format_check): Fix comment. * gettext-tools/src/format-ruby.c (format_check): Likewise. * gettext-tools/src/format-sh.c (format_check): Likewise. --- gettext-tools/src/format-python-brace.c | 24 ++++++++++-------------- gettext-tools/src/format-python.c | 4 ++-- gettext-tools/src/format-ruby.c | 4 ++-- gettext-tools/src/format-sh.c | 4 ++-- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/gettext-tools/src/format-python-brace.c b/gettext-tools/src/format-python-brace.c index 692422075..a0306f61f 100644 --- a/gettext-tools/src/format-python-brace.c +++ b/gettext-tools/src/format-python-brace.c @@ -1,5 +1,5 @@ /* Python brace format strings. - Copyright (C) 2004, 2006-2007, 2013-2014, 2016, 2019, 2023 Free Software Foundation, Inc. + Copyright (C) 2004-2024 Free Software Foundation, Inc. Written by Daiki Ueno , 2013. This program is free software: you can redistribute it and/or modify @@ -462,8 +462,8 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n1 = spec1->named_arg_count; unsigned int n2 = spec2->named_arg_count; - /* Check the argument names in spec1 are contained in those of spec2. - Both arrays are sorted. We search for the differences. */ + /* Check the argument names in spec2 are contained in those of spec1. + Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) { int cmp = (i >= n1 ? 1 : @@ -472,17 +472,13 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, if (cmp > 0) { - if (equality) - { - if (error_logger) - error_logger (error_logger_data, - _("a format specification for argument '%s' doesn't exist in '%s'"), - spec2->named[i].name, pretty_msgid); - err = true; - break; - } - else - j++; + if (error_logger) + error_logger (error_logger_data, + _("a format specification for argument '%s', as in '%s', doesn't exist in '%s'"), + spec2->named[j].name, pretty_msgstr, + pretty_msgid); + err = true; + break; } else if (cmp < 0) { diff --git a/gettext-tools/src/format-python.c b/gettext-tools/src/format-python.c index ebe18d046..79d118b37 100644 --- a/gettext-tools/src/format-python.c +++ b/gettext-tools/src/format-python.c @@ -1,5 +1,5 @@ /* Python format strings. - Copyright (C) 2001-2004, 2006-2009, 2019-2020, 2023 Free Software Foundation, Inc. + Copyright (C) 2001-2024 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -448,7 +448,7 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n1 = spec1->named_arg_count; unsigned int n2 = spec2->named_arg_count; - /* Check that the argument names are the same. + /* Check the argument names in spec2 are contained in those of spec1. Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) { diff --git a/gettext-tools/src/format-ruby.c b/gettext-tools/src/format-ruby.c index 1648c8d2b..8fd277c05 100644 --- a/gettext-tools/src/format-ruby.c +++ b/gettext-tools/src/format-ruby.c @@ -1,5 +1,5 @@ /* Ruby format strings. - Copyright (C) 2001-2004, 2006-2009, 2019-2020, 2023 Free Software Foundation, Inc. + Copyright (C) 2001-2024 Free Software Foundation, Inc. Written by Bruno Haible , 2020. This program is free software: you can redistribute it and/or modify @@ -887,7 +887,7 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n1 = spec1->named_arg_count; unsigned int n2 = spec2->named_arg_count; - /* Check that the argument names are the same. + /* Check the argument names in spec2 are contained in those of spec1. Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) { diff --git a/gettext-tools/src/format-sh.c b/gettext-tools/src/format-sh.c index d20f58bc3..ee50b3641 100644 --- a/gettext-tools/src/format-sh.c +++ b/gettext-tools/src/format-sh.c @@ -1,5 +1,5 @@ /* Shell format strings. - Copyright (C) 2003-2004, 2006-2007, 2009, 2019-2020, 2023 Free Software Foundation, Inc. + Copyright (C) 2003-2024 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software: you can redistribute it and/or modify @@ -283,7 +283,7 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, unsigned int n1 = spec1->named_arg_count; unsigned int n2 = spec2->named_arg_count; - /* Check that the argument names are the same. + /* Check the argument names in spec2 are contained in those of spec1. Both arrays are sorted. We search for the first difference. */ for (i = 0, j = 0; i < n1 || j < n2; ) { -- 2.47.3