Skip to content

Commit 5d69840

Browse files
committed
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.
1 parent 721e574 commit 5d69840

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

internal/cgen/auxiliary/image.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ DecodeImageCallbacks::AllocPixbuf(const wuffs_base__image_config& image_config,
140140
return AllocPixbufResult(DecodeImage_UnsupportedPixelConfiguration);
141141
}
142142
void* ptr =
143-
allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);
143+
allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len);
144144
if (!ptr) {
145145
return AllocPixbufResult(DecodeImage_OutOfMemory);
146146
}
@@ -165,7 +165,7 @@ DecodeImageCallbacks::AllocWorkbuf(wuffs_base__range_ii_u64 len_range,
165165
return AllocWorkbufResult(DecodeImage_OutOfMemory);
166166
}
167167
void* ptr =
168-
allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);
168+
allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len);
169169
if (!ptr) {
170170
return AllocWorkbufResult(DecodeImage_OutOfMemory);
171171
}

internal/cgen/cgen.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
15351535
return err
15361536
}
15371537
b.writes(" {\n")
1538-
b.printf("%s%s* x =\n(%s%s*)(calloc(sizeof(%s%s), 1));\n",
1538+
b.printf("%s%s* x =\n(%s%s*)(calloc(1, sizeof(%s%s)));\n",
15391539
g.pkgPrefix, structName, g.pkgPrefix, structName, g.pkgPrefix, structName)
15401540
b.writes("if (!x) {\nreturn NULL;\n}\n")
15411541
b.printf("if (%s%s__initialize(\nx, sizeof(%s%s), "+

release/c/wuffs-unsupported-snapshot.c

+29-29
Original file line numberDiff line numberDiff line change
@@ -30853,7 +30853,7 @@ wuffs_adler32__hasher__initialize(
3085330853
wuffs_adler32__hasher*
3085430854
wuffs_adler32__hasher__alloc(void) {
3085530855
wuffs_adler32__hasher* x =
30856-
(wuffs_adler32__hasher*)(calloc(sizeof(wuffs_adler32__hasher), 1));
30856+
(wuffs_adler32__hasher*)(calloc(1, sizeof(wuffs_adler32__hasher)));
3085730857
if (!x) {
3085830858
return NULL;
3085930859
}
@@ -31459,7 +31459,7 @@ wuffs_bmp__decoder__initialize(
3145931459
wuffs_bmp__decoder*
3146031460
wuffs_bmp__decoder__alloc(void) {
3146131461
wuffs_bmp__decoder* x =
31462-
(wuffs_bmp__decoder*)(calloc(sizeof(wuffs_bmp__decoder), 1));
31462+
(wuffs_bmp__decoder*)(calloc(1, sizeof(wuffs_bmp__decoder)));
3146331463
if (!x) {
3146431464
return NULL;
3146531465
}
@@ -34225,7 +34225,7 @@ wuffs_bzip2__decoder__initialize(
3422534225
wuffs_bzip2__decoder*
3422634226
wuffs_bzip2__decoder__alloc(void) {
3422734227
wuffs_bzip2__decoder* x =
34228-
(wuffs_bzip2__decoder*)(calloc(sizeof(wuffs_bzip2__decoder), 1));
34228+
(wuffs_bzip2__decoder*)(calloc(1, sizeof(wuffs_bzip2__decoder)));
3422934229
if (!x) {
3423034230
return NULL;
3423134231
}
@@ -35783,7 +35783,7 @@ wuffs_cbor__decoder__initialize(
3578335783
wuffs_cbor__decoder*
3578435784
wuffs_cbor__decoder__alloc(void) {
3578535785
wuffs_cbor__decoder* x =
35786-
(wuffs_cbor__decoder*)(calloc(sizeof(wuffs_cbor__decoder), 1));
35786+
(wuffs_cbor__decoder*)(calloc(1, sizeof(wuffs_cbor__decoder)));
3578735787
if (!x) {
3578835788
return NULL;
3578935789
}
@@ -37095,7 +37095,7 @@ wuffs_crc32__ieee_hasher__initialize(
3709537095
wuffs_crc32__ieee_hasher*
3709637096
wuffs_crc32__ieee_hasher__alloc(void) {
3709737097
wuffs_crc32__ieee_hasher* x =
37098-
(wuffs_crc32__ieee_hasher*)(calloc(sizeof(wuffs_crc32__ieee_hasher), 1));
37098+
(wuffs_crc32__ieee_hasher*)(calloc(1, sizeof(wuffs_crc32__ieee_hasher)));
3709937099
if (!x) {
3710037100
return NULL;
3710137101
}
@@ -37930,7 +37930,7 @@ wuffs_crc64__ecma_hasher__initialize(
3793037930
wuffs_crc64__ecma_hasher*
3793137931
wuffs_crc64__ecma_hasher__alloc(void) {
3793237932
wuffs_crc64__ecma_hasher* x =
37933-
(wuffs_crc64__ecma_hasher*)(calloc(sizeof(wuffs_crc64__ecma_hasher), 1));
37933+
(wuffs_crc64__ecma_hasher*)(calloc(1, sizeof(wuffs_crc64__ecma_hasher)));
3793437934
if (!x) {
3793537935
return NULL;
3793637936
}
@@ -38481,7 +38481,7 @@ wuffs_deflate__decoder__initialize(
3848138481
wuffs_deflate__decoder*
3848238482
wuffs_deflate__decoder__alloc(void) {
3848338483
wuffs_deflate__decoder* x =
38484-
(wuffs_deflate__decoder*)(calloc(sizeof(wuffs_deflate__decoder), 1));
38484+
(wuffs_deflate__decoder*)(calloc(1, sizeof(wuffs_deflate__decoder)));
3848538485
if (!x) {
3848638486
return NULL;
3848738487
}
@@ -40896,7 +40896,7 @@ wuffs_gif__decoder__initialize(
4089640896
wuffs_gif__decoder*
4089740897
wuffs_gif__decoder__alloc(void) {
4089840898
wuffs_gif__decoder* x =
40899-
(wuffs_gif__decoder*)(calloc(sizeof(wuffs_gif__decoder), 1));
40899+
(wuffs_gif__decoder*)(calloc(1, sizeof(wuffs_gif__decoder)));
4090040900
if (!x) {
4090140901
return NULL;
4090240902
}
@@ -43807,7 +43807,7 @@ wuffs_gzip__decoder__initialize(
4380743807
wuffs_gzip__decoder*
4380843808
wuffs_gzip__decoder__alloc(void) {
4380943809
wuffs_gzip__decoder* x =
43810-
(wuffs_gzip__decoder*)(calloc(sizeof(wuffs_gzip__decoder), 1));
43810+
(wuffs_gzip__decoder*)(calloc(1, sizeof(wuffs_gzip__decoder)));
4381143811
if (!x) {
4381243812
return NULL;
4381343813
}
@@ -44913,7 +44913,7 @@ wuffs_jpeg__decoder__initialize(
4491344913
wuffs_jpeg__decoder*
4491444914
wuffs_jpeg__decoder__alloc(void) {
4491544915
wuffs_jpeg__decoder* x =
44916-
(wuffs_jpeg__decoder*)(calloc(sizeof(wuffs_jpeg__decoder), 1));
44916+
(wuffs_jpeg__decoder*)(calloc(1, sizeof(wuffs_jpeg__decoder)));
4491744917
if (!x) {
4491844918
return NULL;
4491944919
}
@@ -51605,7 +51605,7 @@ wuffs_json__decoder__initialize(
5160551605
wuffs_json__decoder*
5160651606
wuffs_json__decoder__alloc(void) {
5160751607
wuffs_json__decoder* x =
51608-
(wuffs_json__decoder*)(calloc(sizeof(wuffs_json__decoder), 1));
51608+
(wuffs_json__decoder*)(calloc(1, sizeof(wuffs_json__decoder)));
5160951609
if (!x) {
5161051610
return NULL;
5161151611
}
@@ -53663,7 +53663,7 @@ wuffs_lzma__decoder__initialize(
5366353663
wuffs_lzma__decoder*
5366453664
wuffs_lzma__decoder__alloc(void) {
5366553665
wuffs_lzma__decoder* x =
53666-
(wuffs_lzma__decoder*)(calloc(sizeof(wuffs_lzma__decoder), 1));
53666+
(wuffs_lzma__decoder*)(calloc(1, sizeof(wuffs_lzma__decoder)));
5366753667
if (!x) {
5366853668
return NULL;
5366953669
}
@@ -56854,7 +56854,7 @@ wuffs_lzip__decoder__initialize(
5685456854
wuffs_lzip__decoder*
5685556855
wuffs_lzip__decoder__alloc(void) {
5685656856
wuffs_lzip__decoder* x =
56857-
(wuffs_lzip__decoder*)(calloc(sizeof(wuffs_lzip__decoder), 1));
56857+
(wuffs_lzip__decoder*)(calloc(1, sizeof(wuffs_lzip__decoder)));
5685856858
if (!x) {
5685956859
return NULL;
5686056860
}
@@ -57403,7 +57403,7 @@ wuffs_lzw__decoder__initialize(
5740357403
wuffs_lzw__decoder*
5740457404
wuffs_lzw__decoder__alloc(void) {
5740557405
wuffs_lzw__decoder* x =
57406-
(wuffs_lzw__decoder*)(calloc(sizeof(wuffs_lzw__decoder), 1));
57406+
(wuffs_lzw__decoder*)(calloc(1, sizeof(wuffs_lzw__decoder)));
5740757407
if (!x) {
5740857408
return NULL;
5740957409
}
@@ -58019,7 +58019,7 @@ wuffs_netpbm__decoder__initialize(
5801958019
wuffs_netpbm__decoder*
5802058020
wuffs_netpbm__decoder__alloc(void) {
5802158021
wuffs_netpbm__decoder* x =
58022-
(wuffs_netpbm__decoder*)(calloc(sizeof(wuffs_netpbm__decoder), 1));
58022+
(wuffs_netpbm__decoder*)(calloc(1, sizeof(wuffs_netpbm__decoder)));
5802358023
if (!x) {
5802458024
return NULL;
5802558025
}
@@ -59159,7 +59159,7 @@ wuffs_nie__decoder__initialize(
5915959159
wuffs_nie__decoder*
5916059160
wuffs_nie__decoder__alloc(void) {
5916159161
wuffs_nie__decoder* x =
59162-
(wuffs_nie__decoder*)(calloc(sizeof(wuffs_nie__decoder), 1));
59162+
(wuffs_nie__decoder*)(calloc(1, sizeof(wuffs_nie__decoder)));
5916359163
if (!x) {
5916459164
return NULL;
5916559165
}
@@ -60203,7 +60203,7 @@ wuffs_zlib__decoder__initialize(
6020360203
wuffs_zlib__decoder*
6020460204
wuffs_zlib__decoder__alloc(void) {
6020560205
wuffs_zlib__decoder* x =
60206-
(wuffs_zlib__decoder*)(calloc(sizeof(wuffs_zlib__decoder), 1));
60206+
(wuffs_zlib__decoder*)(calloc(1, sizeof(wuffs_zlib__decoder)));
6020760207
if (!x) {
6020860208
return NULL;
6020960209
}
@@ -61171,7 +61171,7 @@ wuffs_png__decoder__initialize(
6117161171
wuffs_png__decoder*
6117261172
wuffs_png__decoder__alloc(void) {
6117361173
wuffs_png__decoder* x =
61174-
(wuffs_png__decoder*)(calloc(sizeof(wuffs_png__decoder), 1));
61174+
(wuffs_png__decoder*)(calloc(1, sizeof(wuffs_png__decoder)));
6117561175
if (!x) {
6117661176
return NULL;
6117761177
}
@@ -67321,7 +67321,7 @@ wuffs_qoi__decoder__initialize(
6732167321
wuffs_qoi__decoder*
6732267322
wuffs_qoi__decoder__alloc(void) {
6732367323
wuffs_qoi__decoder* x =
67324-
(wuffs_qoi__decoder*)(calloc(sizeof(wuffs_qoi__decoder), 1));
67324+
(wuffs_qoi__decoder*)(calloc(1, sizeof(wuffs_qoi__decoder)));
6732567325
if (!x) {
6732667326
return NULL;
6732767327
}
@@ -68558,7 +68558,7 @@ wuffs_sha256__hasher__initialize(
6855868558
wuffs_sha256__hasher*
6855968559
wuffs_sha256__hasher__alloc(void) {
6856068560
wuffs_sha256__hasher* x =
68561-
(wuffs_sha256__hasher*)(calloc(sizeof(wuffs_sha256__hasher), 1));
68561+
(wuffs_sha256__hasher*)(calloc(1, sizeof(wuffs_sha256__hasher)));
6856268562
if (!x) {
6856368563
return NULL;
6856468564
}
@@ -69191,7 +69191,7 @@ wuffs_tga__decoder__initialize(
6919169191
wuffs_tga__decoder*
6919269192
wuffs_tga__decoder__alloc(void) {
6919369193
wuffs_tga__decoder* x =
69194-
(wuffs_tga__decoder*)(calloc(sizeof(wuffs_tga__decoder), 1));
69194+
(wuffs_tga__decoder*)(calloc(1, sizeof(wuffs_tga__decoder)));
6919569195
if (!x) {
6919669196
return NULL;
6919769197
}
@@ -70560,7 +70560,7 @@ wuffs_vp8__placeholder__initialize(
7056070560
wuffs_vp8__placeholder*
7056170561
wuffs_vp8__placeholder__alloc(void) {
7056270562
wuffs_vp8__placeholder* x =
70563-
(wuffs_vp8__placeholder*)(calloc(sizeof(wuffs_vp8__placeholder), 1));
70563+
(wuffs_vp8__placeholder*)(calloc(1, sizeof(wuffs_vp8__placeholder)));
7056470564
if (!x) {
7056570565
return NULL;
7056670566
}
@@ -70708,7 +70708,7 @@ wuffs_wbmp__decoder__initialize(
7070870708
wuffs_wbmp__decoder*
7070970709
wuffs_wbmp__decoder__alloc(void) {
7071070710
wuffs_wbmp__decoder* x =
70711-
(wuffs_wbmp__decoder*)(calloc(sizeof(wuffs_wbmp__decoder), 1));
70711+
(wuffs_wbmp__decoder*)(calloc(1, sizeof(wuffs_wbmp__decoder)));
7071270712
if (!x) {
7071370713
return NULL;
7071470714
}
@@ -71843,7 +71843,7 @@ wuffs_webp__decoder__initialize(
7184371843
wuffs_webp__decoder*
7184471844
wuffs_webp__decoder__alloc(void) {
7184571845
wuffs_webp__decoder* x =
71846-
(wuffs_webp__decoder*)(calloc(sizeof(wuffs_webp__decoder), 1));
71846+
(wuffs_webp__decoder*)(calloc(1, sizeof(wuffs_webp__decoder)));
7184771847
if (!x) {
7184871848
return NULL;
7184971849
}
@@ -75578,7 +75578,7 @@ wuffs_xxhash32__hasher__initialize(
7557875578
wuffs_xxhash32__hasher*
7557975579
wuffs_xxhash32__hasher__alloc(void) {
7558075580
wuffs_xxhash32__hasher* x =
75581-
(wuffs_xxhash32__hasher*)(calloc(sizeof(wuffs_xxhash32__hasher), 1));
75581+
(wuffs_xxhash32__hasher*)(calloc(1, sizeof(wuffs_xxhash32__hasher)));
7558275582
if (!x) {
7558375583
return NULL;
7558475584
}
@@ -75991,7 +75991,7 @@ wuffs_xxhash64__hasher__initialize(
7599175991
wuffs_xxhash64__hasher*
7599275992
wuffs_xxhash64__hasher__alloc(void) {
7599375993
wuffs_xxhash64__hasher* x =
75994-
(wuffs_xxhash64__hasher*)(calloc(sizeof(wuffs_xxhash64__hasher), 1));
75994+
(wuffs_xxhash64__hasher*)(calloc(1, sizeof(wuffs_xxhash64__hasher)));
7599575995
if (!x) {
7599675996
return NULL;
7599775997
}
@@ -76632,7 +76632,7 @@ wuffs_xz__decoder__initialize(
7663276632
wuffs_xz__decoder*
7663376633
wuffs_xz__decoder__alloc(void) {
7663476634
wuffs_xz__decoder* x =
76635-
(wuffs_xz__decoder*)(calloc(sizeof(wuffs_xz__decoder), 1));
76635+
(wuffs_xz__decoder*)(calloc(1, sizeof(wuffs_xz__decoder)));
7663676636
if (!x) {
7663776637
return NULL;
7663876638
}
@@ -79659,7 +79659,7 @@ DecodeImageCallbacks::AllocPixbuf(const wuffs_base__image_config& image_config,
7965979659
return AllocPixbufResult(DecodeImage_UnsupportedPixelConfiguration);
7966079660
}
7966179661
void* ptr =
79662-
allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);
79662+
allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len);
7966379663
if (!ptr) {
7966479664
return AllocPixbufResult(DecodeImage_OutOfMemory);
7966579665
}
@@ -79684,7 +79684,7 @@ DecodeImageCallbacks::AllocWorkbuf(wuffs_base__range_ii_u64 len_range,
7968479684
return AllocWorkbufResult(DecodeImage_OutOfMemory);
7968579685
}
7968679686
void* ptr =
79687-
allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);
79687+
allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len);
7968879688
if (!ptr) {
7968979689
return AllocWorkbufResult(DecodeImage_OutOfMemory);
7969079690
}

0 commit comments

Comments
 (0)