diff --git a/internal/cgen/base/image-public.h b/internal/cgen/base/image-public.h index 9be4ed6d..37fc8061 100644 --- a/internal/cgen/base/image-public.h +++ b/internal/cgen/base/image-public.h @@ -650,15 +650,20 @@ wuffs_base__pixel_config__set(wuffs_base__pixel_config* c, return; } if (pixfmt_repr) { - uint64_t wh = ((uint64_t)width) * ((uint64_t)height); - // TODO: handle things other than 1 byte per pixel. - if (wh <= ((uint64_t)SIZE_MAX)) { + do { +#if SIZE_MAX < UINT64_MAX + uint64_t wh = ((uint64_t)width) * ((uint64_t)height); + // TODO: handle things other than 1 byte per pixel. + if (wh > ((uint64_t)SIZE_MAX)) { + break; + } +#endif c->private_impl.pixfmt.repr = pixfmt_repr; c->private_impl.pixsub.repr = pixsub_repr; c->private_impl.width = width; c->private_impl.height = height; return; - } + } while (0); } c->private_impl.pixfmt.repr = 0; diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 689e0507..5196dc2e 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -4598,15 +4598,20 @@ wuffs_base__pixel_config__set(wuffs_base__pixel_config* c, return; } if (pixfmt_repr) { - uint64_t wh = ((uint64_t)width) * ((uint64_t)height); - // TODO: handle things other than 1 byte per pixel. - if (wh <= ((uint64_t)SIZE_MAX)) { + do { +#if SIZE_MAX < UINT64_MAX + uint64_t wh = ((uint64_t)width) * ((uint64_t)height); + // TODO: handle things other than 1 byte per pixel. + if (wh > ((uint64_t)SIZE_MAX)) { + break; + } +#endif c->private_impl.pixfmt.repr = pixfmt_repr; c->private_impl.pixsub.repr = pixsub_repr; c->private_impl.width = width; c->private_impl.height = height; return; - } + } while (0); } c->private_impl.pixfmt.repr = 0;