From 5d69840f8e7ca481551b02c7e8d4c5fb69521bb9 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 12 Aug 2024 22:33:33 +1000 Subject: [PATCH] cgen: swap calloc args For calloc(nmemb, size), multiplication is commutative, but this still fixes a -Werror=calloc-transposed-args failure with coreboot's compiler. --- internal/cgen/auxiliary/image.cc | 4 +- internal/cgen/cgen.go | 2 +- release/c/wuffs-unsupported-snapshot.c | 58 +++++++++++++------------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/internal/cgen/auxiliary/image.cc b/internal/cgen/auxiliary/image.cc index f42290c2..980f4b64 100644 --- a/internal/cgen/auxiliary/image.cc +++ b/internal/cgen/auxiliary/image.cc @@ -140,7 +140,7 @@ DecodeImageCallbacks::AllocPixbuf(const wuffs_base__image_config& image_config, return AllocPixbufResult(DecodeImage_UnsupportedPixelConfiguration); } void* ptr = - allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1); + allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len); if (!ptr) { return AllocPixbufResult(DecodeImage_OutOfMemory); } @@ -165,7 +165,7 @@ DecodeImageCallbacks::AllocWorkbuf(wuffs_base__range_ii_u64 len_range, return AllocWorkbufResult(DecodeImage_OutOfMemory); } void* ptr = - allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1); + allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len); if (!ptr) { return AllocWorkbufResult(DecodeImage_OutOfMemory); } diff --git a/internal/cgen/cgen.go b/internal/cgen/cgen.go index eba6ce99..8c9134c1 100644 --- a/internal/cgen/cgen.go +++ b/internal/cgen/cgen.go @@ -1535,7 +1535,7 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error { return err } b.writes(" {\n") - b.printf("%s%s* x =\n(%s%s*)(calloc(sizeof(%s%s), 1));\n", + b.printf("%s%s* x =\n(%s%s*)(calloc(1, sizeof(%s%s)));\n", g.pkgPrefix, structName, g.pkgPrefix, structName, g.pkgPrefix, structName) b.writes("if (!x) {\nreturn NULL;\n}\n") b.printf("if (%s%s__initialize(\nx, sizeof(%s%s), "+ diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 8ca2471e..4096f1d8 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -30853,7 +30853,7 @@ wuffs_adler32__hasher__initialize( wuffs_adler32__hasher* wuffs_adler32__hasher__alloc(void) { wuffs_adler32__hasher* x = - (wuffs_adler32__hasher*)(calloc(sizeof(wuffs_adler32__hasher), 1)); + (wuffs_adler32__hasher*)(calloc(1, sizeof(wuffs_adler32__hasher))); if (!x) { return NULL; } @@ -31459,7 +31459,7 @@ wuffs_bmp__decoder__initialize( wuffs_bmp__decoder* wuffs_bmp__decoder__alloc(void) { wuffs_bmp__decoder* x = - (wuffs_bmp__decoder*)(calloc(sizeof(wuffs_bmp__decoder), 1)); + (wuffs_bmp__decoder*)(calloc(1, sizeof(wuffs_bmp__decoder))); if (!x) { return NULL; } @@ -34225,7 +34225,7 @@ wuffs_bzip2__decoder__initialize( wuffs_bzip2__decoder* wuffs_bzip2__decoder__alloc(void) { wuffs_bzip2__decoder* x = - (wuffs_bzip2__decoder*)(calloc(sizeof(wuffs_bzip2__decoder), 1)); + (wuffs_bzip2__decoder*)(calloc(1, sizeof(wuffs_bzip2__decoder))); if (!x) { return NULL; } @@ -35783,7 +35783,7 @@ wuffs_cbor__decoder__initialize( wuffs_cbor__decoder* wuffs_cbor__decoder__alloc(void) { wuffs_cbor__decoder* x = - (wuffs_cbor__decoder*)(calloc(sizeof(wuffs_cbor__decoder), 1)); + (wuffs_cbor__decoder*)(calloc(1, sizeof(wuffs_cbor__decoder))); if (!x) { return NULL; } @@ -37095,7 +37095,7 @@ wuffs_crc32__ieee_hasher__initialize( wuffs_crc32__ieee_hasher* wuffs_crc32__ieee_hasher__alloc(void) { wuffs_crc32__ieee_hasher* x = - (wuffs_crc32__ieee_hasher*)(calloc(sizeof(wuffs_crc32__ieee_hasher), 1)); + (wuffs_crc32__ieee_hasher*)(calloc(1, sizeof(wuffs_crc32__ieee_hasher))); if (!x) { return NULL; } @@ -37930,7 +37930,7 @@ wuffs_crc64__ecma_hasher__initialize( wuffs_crc64__ecma_hasher* wuffs_crc64__ecma_hasher__alloc(void) { wuffs_crc64__ecma_hasher* x = - (wuffs_crc64__ecma_hasher*)(calloc(sizeof(wuffs_crc64__ecma_hasher), 1)); + (wuffs_crc64__ecma_hasher*)(calloc(1, sizeof(wuffs_crc64__ecma_hasher))); if (!x) { return NULL; } @@ -38481,7 +38481,7 @@ wuffs_deflate__decoder__initialize( wuffs_deflate__decoder* wuffs_deflate__decoder__alloc(void) { wuffs_deflate__decoder* x = - (wuffs_deflate__decoder*)(calloc(sizeof(wuffs_deflate__decoder), 1)); + (wuffs_deflate__decoder*)(calloc(1, sizeof(wuffs_deflate__decoder))); if (!x) { return NULL; } @@ -40896,7 +40896,7 @@ wuffs_gif__decoder__initialize( wuffs_gif__decoder* wuffs_gif__decoder__alloc(void) { wuffs_gif__decoder* x = - (wuffs_gif__decoder*)(calloc(sizeof(wuffs_gif__decoder), 1)); + (wuffs_gif__decoder*)(calloc(1, sizeof(wuffs_gif__decoder))); if (!x) { return NULL; } @@ -43807,7 +43807,7 @@ wuffs_gzip__decoder__initialize( wuffs_gzip__decoder* wuffs_gzip__decoder__alloc(void) { wuffs_gzip__decoder* x = - (wuffs_gzip__decoder*)(calloc(sizeof(wuffs_gzip__decoder), 1)); + (wuffs_gzip__decoder*)(calloc(1, sizeof(wuffs_gzip__decoder))); if (!x) { return NULL; } @@ -44913,7 +44913,7 @@ wuffs_jpeg__decoder__initialize( wuffs_jpeg__decoder* wuffs_jpeg__decoder__alloc(void) { wuffs_jpeg__decoder* x = - (wuffs_jpeg__decoder*)(calloc(sizeof(wuffs_jpeg__decoder), 1)); + (wuffs_jpeg__decoder*)(calloc(1, sizeof(wuffs_jpeg__decoder))); if (!x) { return NULL; } @@ -51605,7 +51605,7 @@ wuffs_json__decoder__initialize( wuffs_json__decoder* wuffs_json__decoder__alloc(void) { wuffs_json__decoder* x = - (wuffs_json__decoder*)(calloc(sizeof(wuffs_json__decoder), 1)); + (wuffs_json__decoder*)(calloc(1, sizeof(wuffs_json__decoder))); if (!x) { return NULL; } @@ -53663,7 +53663,7 @@ wuffs_lzma__decoder__initialize( wuffs_lzma__decoder* wuffs_lzma__decoder__alloc(void) { wuffs_lzma__decoder* x = - (wuffs_lzma__decoder*)(calloc(sizeof(wuffs_lzma__decoder), 1)); + (wuffs_lzma__decoder*)(calloc(1, sizeof(wuffs_lzma__decoder))); if (!x) { return NULL; } @@ -56854,7 +56854,7 @@ wuffs_lzip__decoder__initialize( wuffs_lzip__decoder* wuffs_lzip__decoder__alloc(void) { wuffs_lzip__decoder* x = - (wuffs_lzip__decoder*)(calloc(sizeof(wuffs_lzip__decoder), 1)); + (wuffs_lzip__decoder*)(calloc(1, sizeof(wuffs_lzip__decoder))); if (!x) { return NULL; } @@ -57403,7 +57403,7 @@ wuffs_lzw__decoder__initialize( wuffs_lzw__decoder* wuffs_lzw__decoder__alloc(void) { wuffs_lzw__decoder* x = - (wuffs_lzw__decoder*)(calloc(sizeof(wuffs_lzw__decoder), 1)); + (wuffs_lzw__decoder*)(calloc(1, sizeof(wuffs_lzw__decoder))); if (!x) { return NULL; } @@ -58019,7 +58019,7 @@ wuffs_netpbm__decoder__initialize( wuffs_netpbm__decoder* wuffs_netpbm__decoder__alloc(void) { wuffs_netpbm__decoder* x = - (wuffs_netpbm__decoder*)(calloc(sizeof(wuffs_netpbm__decoder), 1)); + (wuffs_netpbm__decoder*)(calloc(1, sizeof(wuffs_netpbm__decoder))); if (!x) { return NULL; } @@ -59159,7 +59159,7 @@ wuffs_nie__decoder__initialize( wuffs_nie__decoder* wuffs_nie__decoder__alloc(void) { wuffs_nie__decoder* x = - (wuffs_nie__decoder*)(calloc(sizeof(wuffs_nie__decoder), 1)); + (wuffs_nie__decoder*)(calloc(1, sizeof(wuffs_nie__decoder))); if (!x) { return NULL; } @@ -60203,7 +60203,7 @@ wuffs_zlib__decoder__initialize( wuffs_zlib__decoder* wuffs_zlib__decoder__alloc(void) { wuffs_zlib__decoder* x = - (wuffs_zlib__decoder*)(calloc(sizeof(wuffs_zlib__decoder), 1)); + (wuffs_zlib__decoder*)(calloc(1, sizeof(wuffs_zlib__decoder))); if (!x) { return NULL; } @@ -61171,7 +61171,7 @@ wuffs_png__decoder__initialize( wuffs_png__decoder* wuffs_png__decoder__alloc(void) { wuffs_png__decoder* x = - (wuffs_png__decoder*)(calloc(sizeof(wuffs_png__decoder), 1)); + (wuffs_png__decoder*)(calloc(1, sizeof(wuffs_png__decoder))); if (!x) { return NULL; } @@ -67321,7 +67321,7 @@ wuffs_qoi__decoder__initialize( wuffs_qoi__decoder* wuffs_qoi__decoder__alloc(void) { wuffs_qoi__decoder* x = - (wuffs_qoi__decoder*)(calloc(sizeof(wuffs_qoi__decoder), 1)); + (wuffs_qoi__decoder*)(calloc(1, sizeof(wuffs_qoi__decoder))); if (!x) { return NULL; } @@ -68558,7 +68558,7 @@ wuffs_sha256__hasher__initialize( wuffs_sha256__hasher* wuffs_sha256__hasher__alloc(void) { wuffs_sha256__hasher* x = - (wuffs_sha256__hasher*)(calloc(sizeof(wuffs_sha256__hasher), 1)); + (wuffs_sha256__hasher*)(calloc(1, sizeof(wuffs_sha256__hasher))); if (!x) { return NULL; } @@ -69191,7 +69191,7 @@ wuffs_tga__decoder__initialize( wuffs_tga__decoder* wuffs_tga__decoder__alloc(void) { wuffs_tga__decoder* x = - (wuffs_tga__decoder*)(calloc(sizeof(wuffs_tga__decoder), 1)); + (wuffs_tga__decoder*)(calloc(1, sizeof(wuffs_tga__decoder))); if (!x) { return NULL; } @@ -70560,7 +70560,7 @@ wuffs_vp8__placeholder__initialize( wuffs_vp8__placeholder* wuffs_vp8__placeholder__alloc(void) { wuffs_vp8__placeholder* x = - (wuffs_vp8__placeholder*)(calloc(sizeof(wuffs_vp8__placeholder), 1)); + (wuffs_vp8__placeholder*)(calloc(1, sizeof(wuffs_vp8__placeholder))); if (!x) { return NULL; } @@ -70708,7 +70708,7 @@ wuffs_wbmp__decoder__initialize( wuffs_wbmp__decoder* wuffs_wbmp__decoder__alloc(void) { wuffs_wbmp__decoder* x = - (wuffs_wbmp__decoder*)(calloc(sizeof(wuffs_wbmp__decoder), 1)); + (wuffs_wbmp__decoder*)(calloc(1, sizeof(wuffs_wbmp__decoder))); if (!x) { return NULL; } @@ -71843,7 +71843,7 @@ wuffs_webp__decoder__initialize( wuffs_webp__decoder* wuffs_webp__decoder__alloc(void) { wuffs_webp__decoder* x = - (wuffs_webp__decoder*)(calloc(sizeof(wuffs_webp__decoder), 1)); + (wuffs_webp__decoder*)(calloc(1, sizeof(wuffs_webp__decoder))); if (!x) { return NULL; } @@ -75578,7 +75578,7 @@ wuffs_xxhash32__hasher__initialize( wuffs_xxhash32__hasher* wuffs_xxhash32__hasher__alloc(void) { wuffs_xxhash32__hasher* x = - (wuffs_xxhash32__hasher*)(calloc(sizeof(wuffs_xxhash32__hasher), 1)); + (wuffs_xxhash32__hasher*)(calloc(1, sizeof(wuffs_xxhash32__hasher))); if (!x) { return NULL; } @@ -75991,7 +75991,7 @@ wuffs_xxhash64__hasher__initialize( wuffs_xxhash64__hasher* wuffs_xxhash64__hasher__alloc(void) { wuffs_xxhash64__hasher* x = - (wuffs_xxhash64__hasher*)(calloc(sizeof(wuffs_xxhash64__hasher), 1)); + (wuffs_xxhash64__hasher*)(calloc(1, sizeof(wuffs_xxhash64__hasher))); if (!x) { return NULL; } @@ -76632,7 +76632,7 @@ wuffs_xz__decoder__initialize( wuffs_xz__decoder* wuffs_xz__decoder__alloc(void) { wuffs_xz__decoder* x = - (wuffs_xz__decoder*)(calloc(sizeof(wuffs_xz__decoder), 1)); + (wuffs_xz__decoder*)(calloc(1, sizeof(wuffs_xz__decoder))); if (!x) { return NULL; } @@ -79659,7 +79659,7 @@ DecodeImageCallbacks::AllocPixbuf(const wuffs_base__image_config& image_config, return AllocPixbufResult(DecodeImage_UnsupportedPixelConfiguration); } void* ptr = - allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1); + allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len); if (!ptr) { return AllocPixbufResult(DecodeImage_OutOfMemory); } @@ -79684,7 +79684,7 @@ DecodeImageCallbacks::AllocWorkbuf(wuffs_base__range_ii_u64 len_range, return AllocWorkbufResult(DecodeImage_OutOfMemory); } void* ptr = - allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1); + allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len); if (!ptr) { return AllocWorkbufResult(DecodeImage_OutOfMemory); }