summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2004-05-14 04:58:19 +0000
committerTor Lillqvist <tml@src.gnome.org>2004-05-14 04:58:19 +0000
commit267009b913f89507814ebfdcac8e274bc77105ac (patch)
tree1fd0899cb85ea762a94b0ddda264f793d17e1da7
parent52e231144f5522b188f50a6a7b90bd8dd18c2ae6 (diff)
Handle empty digit string for precision correctly. (#142400)
2004-05-14 Tor Lillqvist <tml@iki.fi> * glib/gnulib/vasnprintf.c (vasnprintf): Handle empty digit string for precision correctly. (#142400) For backward compatibility with the Trio implementation, make "ll" format modifer work on Win32, too. Change into "I64" before passing to the system printf. (#142433) * tests/printf-test.c (main): Add tests for the above.
-rw-r--r--ChangeLog11
-rw-r--r--ChangeLog.pre-2-1011
-rw-r--r--ChangeLog.pre-2-1211
-rw-r--r--ChangeLog.pre-2-611
-rw-r--r--ChangeLog.pre-2-811
-rw-r--r--glib/gnulib/vasnprintf.c12
-rw-r--r--tests/printf-test.c24
7 files changed, 84 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index f82906cd9..9873505a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-05-14 Tor Lillqvist <tml@iki.fi>
+
+ * glib/gnulib/vasnprintf.c (vasnprintf): Handle empty digit string
+ for precision correctly. (#142400)
+
+ For backward compatibility with the Trio implementation, make "ll"
+ format modifer work on Win32, too. Change into "I64" before
+ passing to the system printf. (#142433)
+
+ * tests/printf-test.c (main): Add tests for the above.
+
2004-05-10 Matthias Clasen <mclasen@redhat.com>
Merge from 2.4:
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index f82906cd9..9873505a8 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,14 @@
+2004-05-14 Tor Lillqvist <tml@iki.fi>
+
+ * glib/gnulib/vasnprintf.c (vasnprintf): Handle empty digit string
+ for precision correctly. (#142400)
+
+ For backward compatibility with the Trio implementation, make "ll"
+ format modifer work on Win32, too. Change into "I64" before
+ passing to the system printf. (#142433)
+
+ * tests/printf-test.c (main): Add tests for the above.
+
2004-05-10 Matthias Clasen <mclasen@redhat.com>
Merge from 2.4:
diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12
index f82906cd9..9873505a8 100644
--- a/ChangeLog.pre-2-12
+++ b/ChangeLog.pre-2-12
@@ -1,3 +1,14 @@
+2004-05-14 Tor Lillqvist <tml@iki.fi>
+
+ * glib/gnulib/vasnprintf.c (vasnprintf): Handle empty digit string
+ for precision correctly. (#142400)
+
+ For backward compatibility with the Trio implementation, make "ll"
+ format modifer work on Win32, too. Change into "I64" before
+ passing to the system printf. (#142433)
+
+ * tests/printf-test.c (main): Add tests for the above.
+
2004-05-10 Matthias Clasen <mclasen@redhat.com>
Merge from 2.4:
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index f82906cd9..9873505a8 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,14 @@
+2004-05-14 Tor Lillqvist <tml@iki.fi>
+
+ * glib/gnulib/vasnprintf.c (vasnprintf): Handle empty digit string
+ for precision correctly. (#142400)
+
+ For backward compatibility with the Trio implementation, make "ll"
+ format modifer work on Win32, too. Change into "I64" before
+ passing to the system printf. (#142433)
+
+ * tests/printf-test.c (main): Add tests for the above.
+
2004-05-10 Matthias Clasen <mclasen@redhat.com>
Merge from 2.4:
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index f82906cd9..9873505a8 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,14 @@
+2004-05-14 Tor Lillqvist <tml@iki.fi>
+
+ * glib/gnulib/vasnprintf.c (vasnprintf): Handle empty digit string
+ for precision correctly. (#142400)
+
+ For backward compatibility with the Trio implementation, make "ll"
+ format modifer work on Win32, too. Change into "I64" before
+ passing to the system printf. (#142433)
+
+ * tests/printf-test.c (main): Add tests for the above.
+
2004-05-10 Matthias Clasen <mclasen@redhat.com>
Merge from 2.4:
diff --git a/glib/gnulib/vasnprintf.c b/glib/gnulib/vasnprintf.c
index dd9fca649..b95e119eb 100644
--- a/glib/gnulib/vasnprintf.c
+++ b/glib/gnulib/vasnprintf.c
@@ -405,9 +405,8 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
const char *digitp = dp->precision_start + 1;
precision = 0;
- do
+ while (digitp != dp->precision_end)
precision = precision * 10 + (*digitp++ - '0');
- while (digitp != dp->precision_end);
}
}
@@ -626,9 +625,18 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
#ifdef HAVE_LONG_LONG
case TYPE_LONGLONGINT:
case TYPE_ULONGLONGINT:
+#ifdef HAVE_INT64_AND_I64 /* The system (sn)printf uses %I64. Also assume
+ * that long long == __int64.
+ */
+ *p++ = 'I';
+ *p++ = '6';
+ *p++ = '4';
+ break;
+#else
*p++ = 'l';
/*FALLTHROUGH*/
#endif
+#endif
case TYPE_LONGINT:
case TYPE_ULONGINT:
#ifdef HAVE_WINT_T
diff --git a/tests/printf-test.c b/tests/printf-test.c
index 10a7846ce..085c69d1e 100644
--- a/tests/printf-test.c
+++ b/tests/printf-test.c
@@ -81,6 +81,7 @@ main (int argc,
TEST (NULL, g_snprintf (buf, 128, "%d", 0) == 1 && !strcmp (buf, "0"));
TEST (NULL, g_snprintf (buf, 128, "%.0d", 0) == 0 && !strcmp (buf, ""));
TEST (NULL, g_snprintf (buf, 128, "%.0d", 1) == 1 && !strcmp (buf, "1"));
+ TEST (NULL, g_snprintf (buf, 128, "%.d", 2) == 1 && !strcmp (buf, "2"));
TEST (NULL, g_snprintf (buf, 128, "%d", -1) == 2 && !strcmp (buf, "-1"));
TEST (NULL, g_snprintf (buf, 128, "%.3d", 5) == 3 && !strcmp (buf, "005"));
TEST (NULL, g_snprintf (buf, 128, "%.3d", -5) == 4 && !strcmp (buf, "-005"));
@@ -159,6 +160,8 @@ main (int argc,
TEST (NULL, g_snprintf (buf, 128, "%f", G_PI) == 8 && !strncmp (buf, "3.14159", 7));
TEST (NULL, g_snprintf (buf, 128, "%.8f", G_PI) == 10 && !strncmp (buf, "3.1415926", 9));
TEST (NULL, g_snprintf (buf, 128, "%.0f", G_PI) == 1 && !strcmp (buf, "3"));
+ TEST (NULL, g_snprintf (buf, 128, "%1.f", G_PI) == 1 && !strcmp (buf, "3"));
+ TEST (NULL, g_snprintf (buf, 128, "%3.f", G_PI) == 3 && !strcmp (buf, " 3"));
/* %f, flags */
TEST (NULL, g_snprintf (buf, 128, "%+f", G_PI) == 9 && !strncmp (buf, "+3.14159", 8));
TEST (NULL, g_snprintf (buf, 128, "% f", G_PI) == 9 && !strncmp (buf, " 3.14159", 8));
@@ -220,11 +223,22 @@ main (int argc,
TEST (NULL, g_snprintf (buf, 128, "%" G_GINT64_MODIFIER "x", (gint64)123456) == 5 && !strcmp (buf, "1e240"));
TEST (NULL, g_snprintf (buf, 128, "%#" G_GINT64_MODIFIER "x", (gint64)123456) == 7 && !strcmp (buf, "0x1e240"));
TEST (NULL, g_snprintf (buf, 128, "%" G_GINT64_MODIFIER "X", (gint64)123456) == 5 && !strcmp (buf, "1E240"));
+#ifdef G_OS_WIN32
+ /* On Win32, test that the "ll" modifier also works, for backward
+ * compatibility. One really should use the G_GINT64_MODIFIER (which
+ * on Win32 is the "I64" that the (msvcrt) C library's printf uses),
+ * but "ll" used to work with the "trio" g_printf implementation in
+ * GLib 2.2, so it's best if it continues to work.
+ */
+ TEST (NULL, g_snprintf (buf, 128, "%" "lli", (gint64)123456) == 6 && !strcmp (buf, "123456"));
+ TEST (NULL, g_snprintf (buf, 128, "%" "lli", (gint64)-123456) == 7 && !strcmp (buf, "-123456"));
+ TEST (NULL, g_snprintf (buf, 128, "%" "llu", (guint64)123456) == 6 && !strcmp (buf, "123456"));
+ TEST (NULL, g_snprintf (buf, 128, "%" "ll" "o", (gint64)123456) == 6 && !strcmp (buf, "361100"));
+ TEST (NULL, g_snprintf (buf, 128, "%#" "ll" "o", (gint64)123456) == 7 && !strcmp (buf, "0361100"));
+ TEST (NULL, g_snprintf (buf, 128, "%" "ll" "x", (gint64)123456) == 5 && !strcmp (buf, "1e240"));
+ TEST (NULL, g_snprintf (buf, 128, "%#" "ll" "x", (gint64)123456) == 7 && !strcmp (buf, "0x1e240"));
+ TEST (NULL, g_snprintf (buf, 128, "%" "ll" "X", (gint64)123456) == 5 && !strcmp (buf, "1E240"));
+#endif
return any_failed;
}
-
-
-
-
-