bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

unistdio/*printf: Fix negative width handling for %U, %lU, %llU


From: Bruno Haible
Subject: unistdio/*printf: Fix negative width handling for %U, %lU, %llU
Date: Sat, 28 Jan 2023 19:40:18 +0100

The same bug as mentioned in
  <https://lists.gnu.org/archive/html/bug-gnulib/2023-01/msg00231.html>
exists also in the code that handles Unicode strings (packaged as part of
GNU libunistring). When I add some unit tests and create a testdir with
the modules

  unistdio/ulc-asnprintf
  unistdio/ulc-vasnprintf
  unistdio/ulc-vasprintf
  unistdio/ulc-vsnprintf
  unistdio/ulc-vsprintf
  unistdio/u8-asnprintf
  unistdio/u8-vasnprintf
  unistdio/u8-vasprintf
  unistdio/u8-vsnprintf
  unistdio/u8-vsprintf
  unistdio/u16-asnprintf
  unistdio/u16-vasnprintf
  unistdio/u16-vasprintf
  unistdio/u16-vsnprintf
  unistdio/u16-vsprintf
  unistdio/u32-asnprintf
  unistdio/u32-vasnprintf
  unistdio/u32-vasprintf
  unistdio/u32-vsnprintf
  unistdio/u32-vsprintf

I get test failures:

FAIL: test-u16-vasnprintf1
FAIL: unistdio/test-u16-vasnprintf2.sh
FAIL: unistdio/test-u16-vasnprintf3.sh
FAIL: test-u16-vasprintf1
FAIL: test-u16-vsnprintf1
FAIL: test-u16-vsprintf1
FAIL: test-u32-vasnprintf1
FAIL: unistdio/test-u32-vasnprintf2.sh
FAIL: unistdio/test-u32-vasnprintf3.sh
FAIL: test-u32-vasprintf1
FAIL: test-u32-vsnprintf1
FAIL: test-u32-vsprintf1
FAIL: test-u8-vasnprintf1
FAIL: unistdio/test-u8-vasnprintf2.sh
FAIL: unistdio/test-u8-vasnprintf3.sh
FAIL: test-u8-vasprintf1
FAIL: test-u8-vsnprintf1
FAIL: test-u8-vsprintf1
FAIL: test-ulc-vasnprintf1
FAIL: unistdio/test-ulc-vasnprintf2.sh
FAIL: unistdio/test-ulc-vasnprintf3.sh
FAIL: test-ulc-vasprintf1
FAIL: test-ulc-vsnprintf1
FAIL: test-ulc-vsprintf1

This patch fixes them.


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.

diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 0e6220ae18..72b8cdbfa6 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -2130,7 +2130,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                           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));
@@ -2175,7 +2175,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       }
 # endif
 
-                      if (characters < width && (dp->flags & FLAG_LEFT))
+                      if (characters < width && (flags & FLAG_LEFT))
                         {
                           size_t n = width - characters;
                           ENSURE_ALLOCATION (xsum (length, n));
@@ -2232,7 +2232,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                           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));
@@ -2277,7 +2277,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       }
 # endif
 
-                      if (characters < width && (dp->flags & FLAG_LEFT))
+                      if (characters < width && (flags & FLAG_LEFT))
                         {
                           size_t n = width - characters;
                           ENSURE_ALLOCATION (xsum (length, n));
@@ -2334,7 +2334,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                           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));
@@ -2379,7 +2379,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       }
 # endif
 
-                      if (characters < width && (dp->flags & FLAG_LEFT))
+                      if (characters < width && (flags & FLAG_LEFT))
                         {
                           size_t n = width - characters;
                           ENSURE_ALLOCATION (xsum (length, n));
diff --git a/tests/unistdio/test-u16-printf1.h 
b/tests/unistdio/test-u16-printf1.h
index 54fce5630c..843b2f7c20 100644
--- a/tests/unistdio/test-u16-printf1.h
+++ b/tests/unistdio/test-u16-printf1.h
@@ -83,6 +83,24 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -123,6 +141,24 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -163,6 +199,24 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -211,6 +265,32 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -278,6 +358,44 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -402,6 +520,44 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -502,6 +658,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -532,6 +708,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -620,6 +816,40 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -657,6 +887,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -689,6 +943,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -722,6 +996,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -795,6 +1089,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -850,6 +1168,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -905,6 +1247,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, 
...))
       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);
diff --git a/tests/unistdio/test-u32-printf1.h 
b/tests/unistdio/test-u32-printf1.h
index 9d2107b852..7737c11a1f 100644
--- a/tests/unistdio/test-u32-printf1.h
+++ b/tests/unistdio/test-u32-printf1.h
@@ -83,6 +83,24 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -123,6 +141,24 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -163,6 +199,24 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -211,6 +265,32 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -278,6 +358,44 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -402,6 +520,44 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -502,6 +658,26 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -532,6 +708,26 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -620,6 +816,40 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -657,6 +887,30 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -689,6 +943,26 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -722,6 +996,26 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -795,6 +1089,30 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -850,6 +1168,30 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -905,6 +1247,30 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, 
...))
       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);
diff --git a/tests/unistdio/test-u8-printf1.h b/tests/unistdio/test-u8-printf1.h
index 96673ba1ac..796499cac1 100644
--- a/tests/unistdio/test-u8-printf1.h
+++ b/tests/unistdio/test-u8-printf1.h
@@ -77,6 +77,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -113,6 +129,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -149,6 +181,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -187,6 +235,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -238,6 +304,36 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -298,6 +394,36 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -348,6 +474,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -375,6 +519,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -446,6 +608,28 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -475,6 +659,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -504,6 +706,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -533,6 +753,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
     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);
@@ -596,6 +834,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -636,6 +890,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
       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);
@@ -676,6 +946,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, 
...))
       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);
diff --git a/tests/unistdio/test-ulc-printf1.h 
b/tests/unistdio/test-ulc-printf1.h
index cd6c66bf82..698b4c7218 100644
--- a/tests/unistdio/test-ulc-printf1.h
+++ b/tests/unistdio/test-ulc-printf1.h
@@ -71,6 +71,20 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
       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);
@@ -103,6 +117,20 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
       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);
@@ -135,6 +163,20 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
       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);
@@ -169,6 +211,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
     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);
@@ -210,6 +268,28 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
     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);
@@ -254,6 +334,28 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
     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);
@@ -294,6 +396,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
     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);
@@ -318,6 +436,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
     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);
@@ -380,6 +514,24 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
     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);
@@ -405,6 +557,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
     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);
@@ -431,6 +599,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
     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);
@@ -456,6 +640,22 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...))
     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);






reply via email to

[Prev in Thread] Current Thread [Next in Thread]