+2023-01-28 Bruno Haible <bruno@clisp.org>
+
+ unistdio/*printf: Fix negative width handling for %U, %lU, %llU.
+ * lib/vasnprintf.c (VASNPRINTF): In the code for %U, %lU, %llU, test for
+ the FLAG_LEFT bit in the flags variable.
+ * tests/unistdio/test-u8-printf1.h (test_xfunction): Add tests for width
+ given as argument for the directives %U, %lU, %llU, %s, %a, %f, %e, %g.
+ * tests/unistdio/test-u16-printf1.h (test_xfunction): Likewise.
+ * tests/unistdio/test-u32-printf1.h (test_xfunction): Likewise.
+ * tests/unistdio/test-ulc-printf1.h (test_xfunction): Likewise.
+
2023-01-28 Bruno Haible <bruno@clisp.org>
vasnprintf-posix: Fix possible bug with negative width handling for %lc.
characters = 0;
}
- if (characters < width && !(dp->flags & FLAG_LEFT))
+ if (characters < width && !(flags & FLAG_LEFT))
{
size_t n = width - characters;
ENSURE_ALLOCATION (xsum (length, n));
}
# endif
- if (characters < width && (dp->flags & FLAG_LEFT))
+ if (characters < width && (flags & FLAG_LEFT))
{
size_t n = width - characters;
ENSURE_ALLOCATION (xsum (length, n));
characters = 0;
}
- if (characters < width && !(dp->flags & FLAG_LEFT))
+ if (characters < width && !(flags & FLAG_LEFT))
{
size_t n = width - characters;
ENSURE_ALLOCATION (xsum (length, n));
}
# endif
- if (characters < width && (dp->flags & FLAG_LEFT))
+ if (characters < width && (flags & FLAG_LEFT))
{
size_t n = width - characters;
ENSURE_ALLOCATION (xsum (length, n));
characters = 0;
}
- if (characters < width && !(dp->flags & FLAG_LEFT))
+ if (characters < width && !(flags & FLAG_LEFT))
{
size_t n = width - characters;
ENSURE_ALLOCATION (xsum (length, n));
}
# endif
- if (characters < width && (dp->flags & FLAG_LEFT))
+ if (characters < width && (flags & FLAG_LEFT))
{
size_t n = width - characters;
ENSURE_ALLOCATION (xsum (length, n));
ASSERT (u16_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*U %d", 10, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*U %d", -10, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint16_t *result =
my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55);
ASSERT (u16_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*lU %d", 10, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*lU %d", -10, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint16_t *result =
my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55);
ASSERT (u16_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*llU %d", 10, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*llU %d", -10, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint16_t *result =
my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("Mr. %*s %d", 20, "Ronald Reagan", 33, 44, 55);
+ static const uint16_t expected[] =
+ { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e',
+ 'a', 'g', 'a', 'n', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("Mr. %*s %d", -20, "Ronald Reagan", 33, 44, 55);
+ static const uint16_t expected[] =
+ { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd',
+ ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ',
+ ' ', ' ', ' ', ' ', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* FLAG_LEFT. */
uint16_t *result =
my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*a %d", 10, 1.75, 33, 44, 55);
+ static const uint16_t expected1[] =
+ { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 };
+ static const uint16_t expected2[] =
+ { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 };
+ static const uint16_t expected3[] =
+ { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 };
+ static const uint16_t expected4[] =
+ { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected1) == 0
+ || u16_strcmp (result, expected2) == 0
+ || u16_strcmp (result, expected3) == 0
+ || u16_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*a %d", -10, 1.75, 33, 44, 55);
+ static const uint16_t expected1[] =
+ { '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint16_t expected2[] =
+ { '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint16_t expected3[] =
+ { '0', 'x', '7', 'p', '-', '2', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint16_t expected4[] =
+ { '0', 'x', 'e', 'p', '-', '3', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected1) == 0
+ || u16_strcmp (result, expected2) == 0
+ || u16_strcmp (result, expected3) == 0
+ || u16_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
{ /* Small precision. */
uint16_t *result =
my_xasprintf ("%.10a %d", 1.75, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*La %d", 10, 1.75L, 33, 44, 55);
+ static const uint16_t expected1[] =
+ { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 };
+ static const uint16_t expected2[] =
+ { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 };
+ static const uint16_t expected3[] =
+ { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 };
+ static const uint16_t expected4[] =
+ { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected1) == 0
+ || u16_strcmp (result, expected2) == 0
+ || u16_strcmp (result, expected3) == 0
+ || u16_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*La %d", -10, 1.75L, 33, 44, 55);
+ static const uint16_t expected1[] =
+ { '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint16_t expected2[] =
+ { '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint16_t expected3[] =
+ { '0', 'x', '7', 'p', '-', '2', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint16_t expected4[] =
+ { '0', 'x', 'e', 'p', '-', '3', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected1) == 0
+ || u16_strcmp (result, expected2) == 0
+ || u16_strcmp (result, expected3) == 0
+ || u16_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
{ /* Small precision. */
uint16_t *result =
my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*f %d", 10, 1.75, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*f %d", -10, 1.75, 33, 44, 55);
+ static const uint16_t expected[] =
+ { '1', '.', '7', '5', '0', '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint16_t *result =
my_xasprintf ("%.f %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*Lf %d", 10, 1.75L, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*Lf %d", -10, 1.75L, 33, 44, 55);
+ static const uint16_t expected[] =
+ { '1', '.', '7', '5', '0', '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint16_t *result =
my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*e %d", 15, 1.75, 33, 44, 55);
+ static const uint16_t expected1[] =
+ { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0',
+ '0', 'e', '+', '0', '0', ' ', '3', '3', 0
+ };
+ static const uint16_t expected2[] =
+ { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0',
+ 'e', '+', '0', '0', '0', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected1) == 0
+ || u16_strcmp (result, expected2) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*e %d", -15, 1.75, 33, 44, 55);
+ static const uint16_t expected1[] =
+ { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+',
+ '0', '0', ' ', ' ', ' ', ' ', '3', '3', 0
+ };
+ static const uint16_t expected2[] =
+ { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+',
+ '0', '0', '0', ' ', ' ', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected1) == 0
+ || u16_strcmp (result, expected2) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint16_t *result =
my_xasprintf ("%.e %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*Le %d", 15, 1.75L, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0',
+ '0', 'e', '+', '0', '0', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*Le %d", -15, 1.75L, 33, 44, 55);
+ static const uint16_t expected[] =
+ { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+',
+ '0', '0', ' ', ' ', ' ', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint16_t *result =
my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*g %d", 10, 1.75, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*g %d", -10, 1.75, 33, 44, 55);
+ static const uint16_t expected[] =
+ { '1', '.', '7', '5', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint16_t *result =
my_xasprintf ("%.g %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*Lg %d", 10, 1.75L, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*Lg %d", -10, 1.75L, 33, 44, 55);
+ static const uint16_t expected[] =
+ { '1', '.', '7', '5', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint16_t *result =
my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55);
ASSERT (u16_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*U %d", 20, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
+ 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*U %d", -20, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
+ 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint16_t *result =
my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55);
ASSERT (u16_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*lU %d", 20, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
+ 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*lU %d", -20, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
+ 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint16_t *result =
my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55);
ASSERT (u16_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint16_t *result =
+ my_xasprintf ("%*llU %d", 20, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
+ 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint16_t *result =
+ my_xasprintf ("%*llU %d", -20, unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
+ 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint16_t *result =
my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55);
ASSERT (u32_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*U %d", 10, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*U %d", -10, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint32_t *result =
my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55);
ASSERT (u32_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*lU %d", 10, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*lU %d", -10, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint32_t *result =
my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55);
ASSERT (u32_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*llU %d", 10, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*llU %d", -10, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint32_t *result =
my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("Mr. %*s %d", 20, "Ronald Reagan", 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e',
+ 'a', 'g', 'a', 'n', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("Mr. %*s %d", -20, "Ronald Reagan", 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd',
+ ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ',
+ ' ', ' ', ' ', ' ', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* FLAG_LEFT. */
uint32_t *result =
my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*a %d", 10, 1.75, 33, 44, 55);
+ static const uint32_t expected1[] =
+ { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 };
+ static const uint32_t expected2[] =
+ { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 };
+ static const uint32_t expected3[] =
+ { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 };
+ static const uint32_t expected4[] =
+ { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected1) == 0
+ || u32_strcmp (result, expected2) == 0
+ || u32_strcmp (result, expected3) == 0
+ || u32_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*a %d", -10, 1.75, 33, 44, 55);
+ static const uint32_t expected1[] =
+ { '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint32_t expected2[] =
+ { '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint32_t expected3[] =
+ { '0', 'x', '7', 'p', '-', '2', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint32_t expected4[] =
+ { '0', 'x', 'e', 'p', '-', '3', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected1) == 0
+ || u32_strcmp (result, expected2) == 0
+ || u32_strcmp (result, expected3) == 0
+ || u32_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
{ /* Small precision. */
uint32_t *result =
my_xasprintf ("%.10a %d", 1.75, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*La %d", 10, 1.75L, 33, 44, 55);
+ static const uint32_t expected1[] =
+ { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 };
+ static const uint32_t expected2[] =
+ { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 };
+ static const uint32_t expected3[] =
+ { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 };
+ static const uint32_t expected4[] =
+ { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected1) == 0
+ || u32_strcmp (result, expected2) == 0
+ || u32_strcmp (result, expected3) == 0
+ || u32_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*La %d", -10, 1.75L, 33, 44, 55);
+ static const uint32_t expected1[] =
+ { '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint32_t expected2[] =
+ { '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint32_t expected3[] =
+ { '0', 'x', '7', 'p', '-', '2', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ static const uint32_t expected4[] =
+ { '0', 'x', 'e', 'p', '-', '3', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected1) == 0
+ || u32_strcmp (result, expected2) == 0
+ || u32_strcmp (result, expected3) == 0
+ || u32_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
{ /* Small precision. */
uint32_t *result =
my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*f %d", 10, 1.75, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*f %d", -10, 1.75, 33, 44, 55);
+ static const uint32_t expected[] =
+ { '1', '.', '7', '5', '0', '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint32_t *result =
my_xasprintf ("%.f %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*Lf %d", 10, 1.75L, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*Lf %d", -10, 1.75L, 33, 44, 55);
+ static const uint32_t expected[] =
+ { '1', '.', '7', '5', '0', '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint32_t *result =
my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*e %d", 15, 1.75, 33, 44, 55);
+ static const uint32_t expected1[] =
+ { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0',
+ '0', 'e', '+', '0', '0', ' ', '3', '3', 0
+ };
+ static const uint32_t expected2[] =
+ { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0',
+ 'e', '+', '0', '0', '0', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected1) == 0
+ || u32_strcmp (result, expected2) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*e %d", -15, 1.75, 33, 44, 55);
+ static const uint32_t expected1[] =
+ { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+',
+ '0', '0', ' ', ' ', ' ', ' ', '3', '3', 0
+ };
+ static const uint32_t expected2[] =
+ { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+',
+ '0', '0', '0', ' ', ' ', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected1) == 0
+ || u32_strcmp (result, expected2) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint32_t *result =
my_xasprintf ("%.e %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*Le %d", 15, 1.75L, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0',
+ '0', 'e', '+', '0', '0', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*Le %d", -15, 1.75L, 33, 44, 55);
+ static const uint32_t expected[] =
+ { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+',
+ '0', '0', ' ', ' ', ' ', ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint32_t *result =
my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*g %d", 10, 1.75, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*g %d", -10, 1.75, 33, 44, 55);
+ static const uint32_t expected[] =
+ { '1', '.', '7', '5', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint32_t *result =
my_xasprintf ("%.g %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*Lg %d", 10, 1.75L, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*Lg %d", -10, 1.75L, 33, 44, 55);
+ static const uint32_t expected[] =
+ { '1', '.', '7', '5', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint32_t *result =
my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55);
ASSERT (u32_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*U %d", 20, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
+ 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*U %d", -20, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
+ 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint32_t *result =
my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55);
ASSERT (u32_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*lU %d", 20, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
+ 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*lU %d", -20, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
+ 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint32_t *result =
my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55);
ASSERT (u32_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint32_t *result =
+ my_xasprintf ("%*llU %d", 20, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ',
+ 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint32_t *result =
+ my_xasprintf ("%*llU %d", -20, unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z',
+ 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint32_t *result =
my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55);
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*U %d", 10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*U %d", -10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55);
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*lU %d", 10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*lU %d", -10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55);
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*llU %d", 10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*llU %d", -10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("Mr. %*s %d", 20, "Ronald Reagan", 33, 44, 55);
+ static const uint8_t expected[] = "Mr. Ronald Reagan 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("Mr. %*s %d", -20, "Ronald Reagan", 33, 44, 55);
+ static const uint8_t expected[] = "Mr. Ronald Reagan 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*a %d", 10, 1.75, 33, 44, 55);
+ static const uint8_t expected1[] = " 0x1.cp+0 33";
+ static const uint8_t expected2[] = " 0x3.8p-1 33";
+ static const uint8_t expected3[] = " 0x7p-2 33";
+ static const uint8_t expected4[] = " 0xep-3 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0
+ || u8_strcmp (result, expected3) == 0
+ || u8_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*a %d", -10, 1.75, 33, 44, 55);
+ static const uint8_t expected1[] = "0x1.cp+0 33";
+ static const uint8_t expected2[] = "0x3.8p-1 33";
+ static const uint8_t expected3[] = "0x7p-2 33";
+ static const uint8_t expected4[] = "0xep-3 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0
+ || u8_strcmp (result, expected3) == 0
+ || u8_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
{ /* Small precision. */
uint8_t *result =
my_xasprintf ("%.10a %d", 1.75, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*La %d", 10, 1.75L, 33, 44, 55);
+ static const uint8_t expected1[] = " 0x1.cp+0 33";
+ static const uint8_t expected2[] = " 0x3.8p-1 33";
+ static const uint8_t expected3[] = " 0x7p-2 33";
+ static const uint8_t expected4[] = " 0xep-3 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0
+ || u8_strcmp (result, expected3) == 0
+ || u8_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*La %d", -10, 1.75L, 33, 44, 55);
+ static const uint8_t expected1[] = "0x1.cp+0 33";
+ static const uint8_t expected2[] = "0x3.8p-1 33";
+ static const uint8_t expected3[] = "0x7p-2 33";
+ static const uint8_t expected4[] = "0xep-3 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0
+ || u8_strcmp (result, expected3) == 0
+ || u8_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
{ /* Small precision. */
uint8_t *result =
my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*f %d", 10, 1.75, 33, 44, 55);
+ static const uint8_t expected[] = " 1.750000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*f %d", -10, 1.75, 33, 44, 55);
+ static const uint8_t expected[] = "1.750000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.f %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*Lf %d", 10, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = " 1.750000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*Lf %d", -10, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = "1.750000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*e %d", 15, 1.75, 33, 44, 55);
+ static const uint8_t expected1[] = " 1.750000e+00 33";
+ static const uint8_t expected2[] = " 1.750000e+000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*e %d", -15, 1.75, 33, 44, 55);
+ static const uint8_t expected1[] = "1.750000e+00 33";
+ static const uint8_t expected2[] = "1.750000e+000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.e %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*Le %d", 15, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = " 1.750000e+00 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*Le %d", -15, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = "1.750000e+00 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*g %d", 10, 1.75, 33, 44, 55);
+ static const uint8_t expected[] = " 1.75 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*g %d", -10, 1.75, 33, 44, 55);
+ static const uint8_t expected[] = "1.75 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.g %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*Lg %d", 10, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = " 1.75 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*Lg %d", -10, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = "1.75 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55);
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*U %d", 20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*U %d", -20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55);
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*lU %d", 20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*lU %d", -20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55);
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*llU %d", 20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*llU %d", -20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55);
ASSERT (strcmp (result, " Hello 33") == 0);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("%*U %d", 10, unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " Hello 33") == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("%*U %d", -10, unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "Hello 33") == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
char *result =
my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55);
ASSERT (strcmp (result, " Hello 33") == 0);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("%*lU %d", 10, unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " Hello 33") == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("%*lU %d", -10, unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "Hello 33") == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
char *result =
my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55);
ASSERT (strcmp (result, " Hello 33") == 0);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("%*llU %d", 10, unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " Hello 33") == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("%*llU %d", -10, unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "Hello 33") == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
char *result =
my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("Mr. %*s %d", 20, "Ronald Reagan", 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "Mr. Ronald Reagan 33") == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("Mr. %*s %d", -20, "Ronald Reagan", 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "Mr. Ronald Reagan 33") == 0);
+ free (result);
+ }
+
{ /* FLAG_LEFT. */
char *result =
my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("%*a %d", 10, 1.75, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
+ || strcmp (result, " 0x3.8p-1 33") == 0
+ || strcmp (result, " 0x7p-2 33") == 0
+ || strcmp (result, " 0xep-3 33") == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("%*a %d", -10, 1.75, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "0x1.cp+0 33") == 0
+ || strcmp (result, "0x3.8p-1 33") == 0
+ || strcmp (result, "0x7p-2 33") == 0
+ || strcmp (result, "0xep-3 33") == 0);
+ free (result);
+ }
+
{ /* Small precision. */
char *result =
my_xasprintf ("%.10a %d", 1.75, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("%*La %d", 10, 1.75L, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
+ || strcmp (result, " 0x3.8p-1 33") == 0
+ || strcmp (result, " 0x7p-2 33") == 0
+ || strcmp (result, " 0xep-3 33") == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("%*La %d", -10, 1.75L, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "0x1.cp+0 33") == 0
+ || strcmp (result, "0x3.8p-1 33") == 0
+ || strcmp (result, "0x7p-2 33") == 0
+ || strcmp (result, "0xep-3 33") == 0);
+ free (result);
+ }
+
{ /* Small precision. */
char *result =
my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("%*f %d", 10, 1.75, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " 1.750000 33") == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("%*f %d", -10, 1.75, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "1.750000 33") == 0);
+ free (result);
+ }
+
{ /* Precision. */
char *result =
my_xasprintf ("%.f %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("%*Lf %d", 10, 1.75L, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " 1.750000 33") == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("%*Lf %d", -10, 1.75L, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "1.750000 33") == 0);
+ free (result);
+ }
+
{ /* Precision. */
char *result =
my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("%*e %d", 15, 1.75, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " 1.750000e+00 33") == 0
+ || strcmp (result, " 1.750000e+000 33") == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("%*e %d", -15, 1.75, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "1.750000e+00 33") == 0
+ || strcmp (result, "1.750000e+000 33") == 0);
+ free (result);
+ }
+
{ /* Precision. */
char *result =
my_xasprintf ("%.e %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("%*Le %d", 15, 1.75L, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " 1.750000e+00 33") == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("%*Le %d", -15, 1.75L, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "1.750000e+00 33") == 0);
+ free (result);
+ }
+
{ /* Precision. */
char *result =
my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("%*g %d", 10, 1.75, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " 1.75 33") == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("%*g %d", -10, 1.75, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "1.75 33") == 0);
+ free (result);
+ }
+
{ /* Precision. */
char *result =
my_xasprintf ("%.g %d", 1234.0, 33, 44, 55);
free (result);
}
+ { /* Width given as argument. */
+ char *result =
+ my_xasprintf ("%*Lg %d", 10, 1.75L, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " 1.75 33") == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ char *result =
+ my_xasprintf ("%*Lg %d", -10, 1.75L, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "1.75 33") == 0);
+ free (result);
+ }
+
{ /* Precision. */
char *result =
my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55);