···113113#define unsigned_mult_overflows(a, b) \
114114 ((a) && (b) > maximum_unsigned_value_of_type(a) / (a))
115115116116+/*
117117+ * Returns true if the left shift of "a" by "shift" bits will
118118+ * overflow. The type of "a" must be unsigned.
119119+ */
120120+#define unsigned_left_shift_overflows(a, shift) \
121121+ ((shift) < bitsizeof(a) && \
122122+ (a) > maximum_unsigned_value_of_type(a) >> (shift))
123123+116124#ifdef __GNUC__
117125#define TYPEOF(x) (__typeof__(x))
118126#else
···857865 die("size_t underflow: %"PRIuMAX" - %"PRIuMAX,
858866 (uintmax_t)a, (uintmax_t)b);
859867 return a - b;
868868+}
869869+870870+static inline size_t st_left_shift(size_t a, unsigned shift)
871871+{
872872+ if (unsigned_left_shift_overflows(a, shift))
873873+ die("size_t overflow: %"PRIuMAX" << %u",
874874+ (uintmax_t)a, shift);
875875+ return a << shift;
876876+}
877877+878878+static inline unsigned long cast_size_t_to_ulong(size_t a)
879879+{
880880+ if (a != (unsigned long)a)
881881+ die("object too large to read on this platform: %"
882882+ PRIuMAX" is cut off to %lu",
883883+ (uintmax_t)a, (unsigned long)a);
884884+ return (unsigned long)a;
860885}
861886862887#ifdef HAVE_ALLOCA_H