Paul Eggert wrote:
>  #define xtimes(N, ELSIZE) \
> -  ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX)
> +  ((N) <= SIZE_MAX / (ELSIZE) ? sizeof "" * (N) * (ELSIZE) : SIZE_MAX)

Ouch. This is another instance of intentional obfuscation, that I'm heavily
opposed to [1].

Since you started to use compound initializers instead of casts in some
other places, and this is relatively understandable, let's use this
approach here as well.

[1] https://lists.gnu.org/archive/html/bug-gnulib/2026-03/msg00130.html


2026-05-08  Bruno Haible  <[email protected]>

        Revisit some -Wuseless-cast changes.
        * lib/xsize.h (xtimes): Use a compound literal instead of sizeof "".

diff --git a/lib/xsize.h b/lib/xsize.h
index a54cc179aa..17bdb9c2b4 100644
--- a/lib/xsize.h
+++ b/lib/xsize.h
@@ -108,12 +108,12 @@ xmax (size_t size1, size_t size2)
    The count must be >= 0 and the element size must be > 0.
    Arguments should not have side effects.
    The element size's type should be no wider than size_t.
-   The 'sizeof "" *' widens N's value if necessary, to avoid overflow;
+   The '(size_t) { (N) }' widens N's value to size_t, to avoid overflow;
    unlike a cast to size_t, this pacifies -Wuseless-cast.
    This is a macro, not a function, so that it works correctly even
    when N is of a wider type and N > SIZE_MAX.  */
 #define xtimes(N, ELSIZE) \
-  ((N) <= SIZE_MAX / (ELSIZE) ? sizeof "" * (N) * (ELSIZE) : SIZE_MAX)
+  ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) { (N) } * (ELSIZE) : SIZE_MAX)
 
 /* Check for overflow.  */
 #define size_overflow_p(SIZE) \




Reply via email to