]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
tests: Check against SIGFPE signal during plural expression evaluation.
authorBruno Haible <bruno@clisp.org>
Sun, 1 Oct 2023 18:18:17 +0000 (20:18 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 6 Oct 2023 14:25:03 +0000 (16:25 +0200)
* gettext-tools/tests/plural-4: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.

gettext-tools/tests/Makefile.am
gettext-tools/tests/plural-4 [new file with mode: 0644]

index 3283811016ec11c418b4f5e8dbc21c6c46d11e67..ed09f3524b4dc5c8a53ee0dab7674ed8b0bae743 100644 (file)
@@ -200,7 +200,7 @@ TESTS = gettext-1 gettext-2 \
        format-sh-1 format-sh-2 \
        format-tcl-1 format-tcl-2 \
        format-ycp-1 format-ycp-2 \
-       plural-1 plural-2 plural-3 \
+       plural-1 plural-2 plural-3 plural-4 \
        gettextpo-1 sentence-1 \
        lang-po \
        lang-c lang-c++ lang-c++20 lang-objc \
diff --git a/gettext-tools/tests/plural-4 b/gettext-tools/tests/plural-4
new file mode 100644 (file)
index 0000000..366075d
--- /dev/null
@@ -0,0 +1,40 @@
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test that ngettext() does not crash when the plural form rule leads to
+# a division by zero.
+
+test -d plural-4-dir || mkdir plural-4-dir
+test -d plural-4-dir/ll || mkdir plural-4-dir/ll
+test -d plural-4-dir/ll/LC_MESSAGES || mkdir plural-4-dir/ll/LC_MESSAGES
+
+cat > plural-4-ll.po <<EOF
+msgid ""
+msgstr ""
+"Project-Id-Version: dummy 0.0\n"
+"PO-Revision-Date: 2023-09-22 12:48:44 CEST\n"
+"Last-Translator: \n"
+"Language-Team: \n"
+"Language: lalala\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=ASCII\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=3; plural=(n!=1)+1/(n!=1666);\n"
+
+msgid "X"
+msgid_plural "Y"
+msgstr[0] "x"
+msgstr[1] "y"
+msgstr[2] "z"
+EOF
+
+: ${MSGFMT=msgfmt}
+# The option '-c' checks the evaluation only for 0 ≤ n ≤ 1000.
+${MSGFMT} -c -o plural-4-dir/ll/LC_MESSAGES/plural.mo plural-4-ll.po || Exit 1
+
+LANGUAGE= TEXTDOMAIN=plural TEXTDOMAINDIR=plural-4-dir \
+$NGETTEXT --env LC_ALL=ll X Y 1666 > dataout
+test $? = 0 || Exit 1
+test x = `cat dataout` || Exit 1
+
+Exit 0