summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Pankov <yuri.pankov@nexenta.com>2018-04-29 21:28:12 +0300
committerHans Rosenfeld <hans.rosenfeld@joyent.com>2018-05-16 12:03:43 +0200
commit804635d7bfa86d5f677fada06cb30420313f1159 (patch)
tree06785df23dd5e2ac2febed8901c51a4403067b85
parent4540c8e2f029ecd3f040b27b7489b1c9f2d920c0 (diff)
downloadillumos-joyent-804635d7bfa86d5f677fada06cb30420313f1159.tar.gz
9511 printf family isn't aware of multibyte decimal point characters
Reviewed by: Dan McDonald <danmcd@joyent.com> Approved by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
-rw-r--r--usr/src/lib/libc/port/print/doprnt.c46
-rw-r--r--usr/src/pkg/manifests/system-test-libctest.mf3
-rw-r--r--usr/src/test/libc-tests/doc/README10
-rw-r--r--usr/src/test/libc-tests/runfiles/default.run2
-rw-r--r--usr/src/test/libc-tests/tests/Makefile1
-rw-r--r--usr/src/test/libc-tests/tests/printf-9511.c70
6 files changed, 114 insertions, 18 deletions
diff --git a/usr/src/lib/libc/port/print/doprnt.c b/usr/src/lib/libc/port/print/doprnt.c
index 0c0fe0cacb..b6e8ceef0a 100644
--- a/usr/src/lib/libc/port/print/doprnt.c
+++ b/usr/src/lib/libc/port/print/doprnt.c
@@ -195,11 +195,11 @@ static const wchar_t widenullstr[] = L"(null)";
#define CHAR 0x2000 /* hh for char */
#ifdef _WIDE
-static wchar_t *
-insert_thousands_sep(wchar_t *bp, wchar_t *ep);
+static wchar_t *insert_decimal_point(wchar_t *ep);
+static wchar_t *insert_thousands_sep(wchar_t *bp, wchar_t *ep);
#else /* _WIDE */
-static char *
-insert_thousands_sep(char *bp, char *ep);
+static char *insert_decimal_point(char *ep);
+static char *insert_thousands_sep(char *bp, char *ep);
#endif /* _WIDE */
static int _rec_scrswidth(wchar_t *, ssize_t);
@@ -571,8 +571,6 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag)
/* arglst[1] is the second arg, etc */
int starflg = 0; /* set to 1 if * format specifier seen */
- struct lconv *locptr = localeconv();
- char decimal_point = *locptr->decimal_point;
/*
* Initialize args and sargs to the start of the argument list.
@@ -1344,11 +1342,11 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag)
p = &buf[0];
*p++ = (*bp != '\0') ? *bp++ : '0';
- /* put in a decimal point if needed */
+ /* Put in a decimal point if needed */
if (prec != 0 || (flagword & FSHARP))
- *p++ = decimal_point;
+ p = insert_decimal_point(p);
- /* create the rest of the mantissa */
+ /* Create the rest of the mantissa */
rz = prec;
if (fcode == 'A') {
for (; rz > 0 && *bp != '\0'; --rz) {
@@ -1452,7 +1450,7 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag)
/* Put in a decimal point if needed */
if (prec != 0 || (flagword & FSHARP))
- *p++ = decimal_point;
+ p = insert_decimal_point(p);
/* Create the rest of the mantissa */
rz = prec;
@@ -1575,9 +1573,9 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag)
if (quote)
p = insert_thousands_sep(buf, p);
- /* Decide whether we need a decimal point */
- if ((flagword & FSHARP) || prec > 0)
- *p++ = decimal_point;
+ /* Put in a decimal point if needed */
+ if (prec != 0 || (flagword & FSHARP))
+ p = insert_decimal_point(p);
/* Digits (if any) after the decimal point */
nn = min(prec, MAXFCVT);
@@ -2662,6 +2660,28 @@ insert_thousands_sep(char *bp, char *ep)
return (ep);
}
+#ifdef _WIDE
+static wchar_t *
+insert_decimal_point(wchar_t *ep)
+#else
+static char *
+insert_decimal_point(char *ep)
+#endif
+{
+ struct lconv *locptr = localeconv();
+ char *dp = locptr->decimal_point;
+#ifdef _WIDE
+ wchar_t wdp;
+
+ (void) mbtowc(&wdp, dp, MB_CUR_MAX);
+ *ep = wdp;
+ return (ep + 1);
+#else
+ (void) memcpy(ep, dp, strlen(dp));
+ return (ep + strlen(dp));
+#endif
+}
+
/*
* Recovery scrswidth function -
diff --git a/usr/src/pkg/manifests/system-test-libctest.mf b/usr/src/pkg/manifests/system-test-libctest.mf
index 32cb761128..f2eb069681 100644
--- a/usr/src/pkg/manifests/system-test-libctest.mf
+++ b/usr/src/pkg/manifests/system-test-libctest.mf
@@ -98,6 +98,8 @@ file path=opt/libc-tests/tests/nl_langinfo_test mode=0555
file path=opt/libc-tests/tests/nl_langinfo_test.$(ARCH) mode=0555
file path=opt/libc-tests/tests/nl_langinfo_test.$(ARCH64) mode=0555
file path=opt/libc-tests/tests/printf-6961.64 mode=0555
+file path=opt/libc-tests/tests/printf-9511.32 mode=0555
+file path=opt/libc-tests/tests/printf-9511.64 mode=0555
file path=opt/libc-tests/tests/priv_gettext mode=0555
file path=opt/libc-tests/tests/psignal mode=0555
file path=opt/libc-tests/tests/psignal-5097.32 mode=0555
@@ -202,6 +204,7 @@ hardlink path=opt/libc-tests/tests/symbols/wctype_h target=setup
license lic_CDDL license=lic_CDDL
license usr/src/test/libc-tests/tests/regex/THIRDPARTYLICENSE \
license=usr/src/test/libc-tests/tests/regex/THIRDPARTYLICENSE
+depend fmri=locale/ar type=require
depend fmri=locale/de type=require
depend fmri=locale/en type=require
depend fmri=locale/en-extra type=require
diff --git a/usr/src/test/libc-tests/doc/README b/usr/src/test/libc-tests/doc/README
index f5640c58dd..e74f398ec1 100644
--- a/usr/src/test/libc-tests/doc/README
+++ b/usr/src/test/libc-tests/doc/README
@@ -49,16 +49,16 @@ install the Utils Unit Test Suite.
Note, the framework will be installed automatically, as this test suite
depends on it.
-Additionally some text locales are required, specifically, en_US.UTF-8,
-de_DE.UTF-8, ja_JP.UTF-8, and ru_RU.UTF-8. Again, these are listed as
-dependencies and will be automatically installed.
+Additionally some text locales are required, specifically, ar_AE.UTF-8,
+de_DE.UTF-8, en_US.UTF-8, ja_JP.UTF-8, and ru_RU.UTF-8. Again, these are
+listed as dependencies and will be automatically installed.
3. Running this Unit Test Suite
The pre-requisites for running the this Unit Test Suite are:
- Any user may perform these tests.
- - The en_US.UTF-8, en_GB.ISO8859-15, ja_JP.UTF-8, de_DE.UTF-8, and
- ru_RU.UTF-8 locales must be installed.
+ - The ar_AE.UTF-8, de_DE.UTF-8, en_US.UTF-8, en_GB.ISO8859-15,
+ ja_JP.UTF-8, and ru_RU.UTF-8 locales must be installed.
Once the pre-requisites are satisfied, simply run the libctest script:
diff --git a/usr/src/test/libc-tests/runfiles/default.run b/usr/src/test/libc-tests/runfiles/default.run
index a58c46d6c8..15e3d60d69 100644
--- a/usr/src/test/libc-tests/runfiles/default.run
+++ b/usr/src/test/libc-tests/runfiles/default.run
@@ -80,6 +80,8 @@ timeout = 600
[/opt/libc-tests/tests/quick_exit]
[/opt/libc-tests/tests/psignal]
[/opt/libc-tests/tests/printf-6961.64]
+[/opt/libc-tests/tests/printf-9511.32]
+[/opt/libc-tests/tests/printf-9511.64]
[/opt/libc-tests/tests/priv_gettext]
[/opt/libc-tests/tests/strerror]
[/opt/libc-tests/tests/timespec_get.32]
diff --git a/usr/src/test/libc-tests/tests/Makefile b/usr/src/test/libc-tests/tests/Makefile
index f9b80255f0..68bd817ed4 100644
--- a/usr/src/test/libc-tests/tests/Makefile
+++ b/usr/src/test/libc-tests/tests/Makefile
@@ -38,6 +38,7 @@ PROGS = \
endian \
env-7076 \
fnmatch \
+ printf-9511 \
psignal-5097 \
quick_exit_order \
quick_exit_status \
diff --git a/usr/src/test/libc-tests/tests/printf-9511.c b/usr/src/test/libc-tests/tests/printf-9511.c
new file mode 100644
index 0000000000..98823f0d10
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/printf-9511.c
@@ -0,0 +1,70 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2018 Nexenta Systems, Inc.
+ */
+
+/*
+ * Note that this file is easiest edited with a UTF-8 capable editor,
+ * as there are embedded UTF-8 symbols in some of the strings.
+ */
+
+#include <err.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+
+struct {
+ const char *locale;
+ const char *convspec;
+ const float fp;
+ const char *expected;
+} fpconv[] = {
+ "C", "%a", 3.2, "0x1.99999a0000000p+1",
+ "C", "%e", 3.2, "3.200000e+00",
+ "C", "%f", 3.2, "3.200000",
+ "C", "%g", 3.2, "3.2",
+ "ar_AE.UTF-8", "%a", 3.2, "0x1٫99999a0000000p+1",
+ "ar_AE.UTF-8", "%e", 3.2, "3٫200000e+00",
+ "ar_AE.UTF-8", "%f", 3.2, "3٫200000",
+ "ar_AE.UTF-8", "%g", 3.2, "3٫2",
+ "en_US.UTF-8", "%a", 3.2, "0x1.99999a0000000p+1",
+ "en_US.UTF-8", "%e", 3.2, "3.200000e+00",
+ "en_US.UTF-8", "%f", 3.2, "3.200000",
+ "en_US.UTF-8", "%g", 3.2, "3.2",
+ "ru_RU.UTF-8", "%a", 3.2, "0x1,99999a0000000p+1",
+ "ru_RU.UTF-8", "%e", 3.2, "3,200000e+00",
+ "ru_RU.UTF-8", "%f", 3.2, "3,200000",
+ "ru_RU.UTF-8", "%g", 3.2, "3,2",
+ NULL, NULL, 0, NULL
+};
+
+int
+main(void)
+{
+ char buf[100];
+ int i;
+
+ for (i = 0; fpconv[i].locale != NULL; i++) {
+ if (setlocale(LC_ALL, fpconv[i].locale) == NULL)
+ err(1, "failed to set locale to %s", fpconv[i].locale);
+
+ (void) sprintf(buf, fpconv[i].convspec, fpconv[i].fp);
+ if (strcmp(fpconv[i].expected, buf) != 0) {
+ errx(1, "locale=%s, convspec=%s, expected=%s, got=%s",
+ fpconv[i].locale, fpconv[i].convspec,
+ fpconv[i].expected, buf);
+ }
+ }
+
+ return (0);
+}