Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Argument Order in calloc Call in fir_filter.c #972

Open
goatmanic opened this issue Jun 17, 2024 · 1 comment · May be fixed by #984
Open

Fix Argument Order in calloc Call in fir_filter.c #972

goatmanic opened this issue Jun 17, 2024 · 1 comment · May be fixed by #984

Comments

@goatmanic
Copy link

goatmanic commented Jun 17, 2024

The calloc function call in the fir_filter.c file uses the arguments in an incorrect order, causing a compilation error with the message:

error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=callc- transposed-args]

This error occurs because calloc expects the number of elements as the first argument and the size of each element as the second argument. However, the existing code has these reversed.

Affected File:

Path: bladeRF/host/utilities/bladeRF-fsk/c/src/fir_filter.c
Line: 227

Proposed Fix

The arguments to calloc should be reordered to correctly reflect the expected signature of calloc(num_elements, element_size). The corrected line of code is:

outbuf = calloc(chunk_size, sizeof(struct complex_sample));

This change ensures that the chunk_size (the number of elements) is passed as the first argument and the sizeof(struct complex_sample) (the size of each element) is passed as the second argument.

Steps to Reproduce:

  1. Compile the affected file with a strict compiler that treats warnings as errors.
  2. Observe the compilation error due to the transposed arguments in the calloc function.
@MartinHerren MartinHerren linked a pull request Sep 9, 2024 that will close this issue
@bezborodow
Copy link

bezborodow commented Sep 22, 2024

I have the same error. Applying this patch allows compilation to succeed. I am using Fedora 40.

[ 96%] Building C object host/utilities/bladeRF-fsk/c/CMakeFiles/bladeRF-fsk_test_fir_filter.dir/src/fir_filter.c.o
/home/dbezborodov/src/bladeRF/host/utilities/bladeRF-fsk/c/src/fir_filter.c: In function ‘main’:
/home/dbezborodov/src/bladeRF/host/utilities/bladeRF-fsk/c/src/fir_filter.c:227:28: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  227 |     outbuf = calloc(sizeof(struct complex_sample), chunk_size);
      |                            ^~~~~~
/home/dbezborodov/src/bladeRF/host/utilities/bladeRF-fsk/c/src/fir_filter.c:227:28: note: earlier argument should specify number of elements, later size of each element
cc1: all warnings being treated as errors
make[2]: *** [host/utilities/bladeRF-fsk/c/CMakeFiles/bladeRF-fsk_test_fir_filter.dir/build.make:90: host/utilities/bladeRF-fsk/c/CMakeFiles/bladeRF-fsk_test_fir_filter.dir/src/fir_filter.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1553: host/utilities/bladeRF-fsk/c/CMakeFiles/bladeRF-fsk_test_fir_filter.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants