[Libguestfs] [libnbd PATCH 6/6] common/include: Fix MIN and MAX macros so they can be nested [finish port]

Laszlo Ersek lersek at redhat.com
Wed Mar 1 11:40:27 UTC 2023


From: "Richard W.M. Jones" <rjones at redhat.com>

Original commit message:

Thanks: Eric Blake

Porting notes:

We already have the nesting fix in the "common/include/minmax.h" header
file, from nbdkit commit 9f462af12e3b ("common/include: Fix MIN and MAX
macros so they can be nested", 2022-02-22), via libnbd commit
2f25695212db5. However, that port didn't include the update to the test
case. Do it now.

Signed-off-by: Laszlo Ersek <lersek at redhat.com>
(cherry picked from nbdkit commit 9f462af12e3b8b9840435a266d7e6e7d45ed70bf)
---
 common/include/test-minmax.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/common/include/test-minmax.c b/common/include/test-minmax.c
index 285f8074e503..095c91491acc 100644
--- a/common/include/test-minmax.c
+++ b/common/include/test-minmax.c
@@ -154,5 +154,19 @@ main (void)
   SIGNED_TEST (f, -FLT_MAX, FLT_MAX);
   SIGNED_TEST (d, -DBL_MAX, DBL_MAX);
 
+  /* Test that MIN and MAX can be nested.  This is really a compile
+   * test, but we do check the answer.
+   */
+  assert (MIN (MIN (1, 2), 3) == 1);
+  assert (MAX (MIN (1, 2), 3) == 3);
+  assert (MIN (MAX (1, 2), 3) == 2);
+  assert (MAX (MAX (1, 4), 3) == 4);
+  assert (MIN (3, MIN (1, 2)) == 1);
+  assert (MAX (3, MIN (1, 2)) == 3);
+  assert (MIN (3, MAX (1, 2)) == 2);
+  assert (MAX (3, MAX (1, 4)) == 4);
+  assert (MIN (MIN (1, MIN (2, 3)), 4) == 1);
+  assert (MAX (MAX (1, MAX (2, 3)), 4) == 4);
+
   exit (EXIT_SUCCESS);
 }


More information about the Libguestfs mailing list