From: Bruno Haible Date: Sat, 21 Jun 2025 23:08:15 +0000 (+0200) Subject: go-format: Accept null precision. X-Git-Tag: v0.26~87 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b5d6f1237196475641c49db0b0522d2434b7a13f;p=thirdparty%2Fgettext.git go-format: Accept null precision. * gettext-tools/src/format-go.c: Clarify comment regarding the precision. (format_parse): Accept a null precision after '.'. * gettext-tools/tests/format-go-1: Add a test case with null precision. --- diff --git a/gettext-tools/src/format-go.c b/gettext-tools/src/format-go.c index dcf88e127..466d6cd62 100644 --- a/gettext-tools/src/format-go.c +++ b/gettext-tools/src/format-go.c @@ -44,7 +44,7 @@ sequence with value <= 1000000, - is optionally followed by '.' and a precision specification: '*' (reads an argument) or '[m]*' (moves to the m-th argument and reads that argument) or - a digit sequence with value <= 1000000, + optionally a nonempty digit sequence with value <= 1000000, - is optionally followed by '[m]', where m is a digit sequence with a positive value <= 1000000, - is finished by a specifier @@ -252,11 +252,12 @@ format_parse (const char *format, bool translated, char *fdi, /* Parse precision. */ if (*format == '.') { - if (format[1] == '[') + format++; + if (*format == '[') { - if (c_isdigit (format[2])) + if (c_isdigit (format[1])) { - const char *f = format + 2; + const char *f = format + 1; unsigned int m = 0; do @@ -312,9 +313,9 @@ format_parse (const char *format, bool translated, char *fdi, } /* Parse precision other than [m]*. */ - if (c_isdigit (format[1])) + if (c_isdigit (*format)) { - const char *f = format + 1; + const char *f = format; unsigned int precision = 0; do @@ -335,7 +336,7 @@ format_parse (const char *format, bool translated, char *fdi, } format = f; } - else if (format[1] == '*') + else if (*format == '*') { unsigned int precision_number = number; @@ -349,7 +350,7 @@ format_parse (const char *format, bool translated, char *fdi, spec.numbered_arg_count++; number++; - format += 2; + format++; } } diff --git a/gettext-tools/tests/format-go-1 b/gettext-tools/tests/format-go-1 index 396fd7c97..1d7cb351c 100755 --- a/gettext-tools/tests/format-go-1 +++ b/gettext-tools/tests/format-go-1 @@ -58,6 +58,8 @@ cat <<\EOF > f-go-1.data "abc%y" # Invalid: flags after width "abc%2#d" +# Valid: null precision +"abc%.f" # Invalid: twice precision "abc%.4.2d" # Valid: three arguments