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.
This commit is contained in:
Nigel Tao committed 2024-08-12 22:33:33 +10:00
1 parent 721e574398
commit 5d69840f8e
3 files changed
+32 -32

No files matched your search

+2 -2
View File
@@ -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);
}
+1 -1
View File
@@ -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), "+