Skip to content
Snippets Groups Projects
Mauro Carvalho Chehab's avatar
Mauro Carvalho Chehab authored
The new gcc version 14 now complains when calloc is called
with inverted arguments:

	../benchmarks/gem_exec_reloc.c:85:31: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
	   85 |         target = calloc(sizeof(*target), num_relocs);
	      |                               ^
	../benchmarks/gem_exec_reloc.c:85:31: note: earlier argument should specify number of elements, later size of each element

Replace all occurrences of calloc that were warned on gcc 14 by
placing the arguments at the right order.

Logic fixed using this small python script, written specifically
to catch gcc calloc warnings:

    #!/usr/bin/env python3
    import re
    warnings = [
    	"lib/igt_kms.c:2781",
    	"lib/igt_kms.c:2809",
    	"lib/igt_kms.c:2858",
    	"lib/igt_chamelium.c:156",
    	"lib/igt_chamelium.c:1519",
    	"tests/kms_atomic_transition.c:483",
    	"tests/kms_atomic_transition.c:485",
    	"tests/kms_atomic_transition.c:487",
    	"tests/kms_flip.c:426",
    	"tests/kms_flip.c:427",
    	"tests/intel/gem_exec_alignment.c:204",
    	"tests/intel/gem_exec_alignment.c:409",
    	"tests/intel/gem_exec_fair.c:1121",
    	"tests/intel/gem_exec_fair.c:1122",
    	"tests/intel/gem_fence_thrash.c:153",
    	"tests/intel/gem_fence_thrash.c:234",
    	"tests/intel/gem_ppgtt.c:432",
    	"tests/intel/gem_ppgtt.c:459",
    	"tests/intel/gem_render_tiled_blits.c:152",
    	"tests/intel/gem_userptr_blits.c:1433",
    	"tests/chamelium/kms_chamelium_frames.c:943",
    	"tests/amdgpu/amd_multidisplay_modeset.c:242",
    	"benchmarks/gem_exec_reloc.c:83",
    	"benchmarks/gem_exec_reloc.c:84",
    	"benchmarks/gem_exec_reloc.c:85",
    	"benchmarks/gem_latency.c:196",
    	"assembler/main.c:400",
    	"assembler/gram.y:219",
    	"assembler/gram.y:231",
    	"assembler/gram.y:242",
    ]
    split_file = re.compile(r"([^\:]+):(\d+)")
    calloc = re.compile(r"(calloc\s*\()(.*)\,\s*([\w\d\ \+\*\-\>]+)(\))")
    for f in warnings:
        match = split_file.match(f)
        if not match:
            continue
        fname = match.group(1)
        line_number = int(match.group(2))
        new = ""
        with open(fname, 'r', encoding = 'utf8') as fp:
            for ln, line in enumerate(fp):
                if ln + 1 == line_number:
                    new_line = calloc.sub(r"\1\3, \2\4", line)
                    if new_line != line:
                        line = new_line
                    else:
                        print(f"{fname}, line {line_number}: FAILED: {line.strip()}")
                new += line
        with open(fname, 'w', encoding = 'utf8') as fp:
            fp.write(new)

Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
Reviewed-by: default avatarKamil Konieczny <kamil.konieczny@linux.intel.com>
58ca03ee
History
Name Last commit Last update
..