Bugfinder can support byte padding check?
1 view (last 30 days)
Show older comments
We are reviewing coding rule checks on C language code using Bug Finder. I would like to add some features using the Custom Coding rule option. Are features such as data type restrictions or uninitialized local variable checking supported? It would be nice to have an example if possible.
Additionally, is it possible to support byte padding inspection of structures? If it is not possible in Bugfinder, is it possible in Code Prover?
4 Comments
Anirban
on 16 Jan 2024
" I would like to inquire whether bug finder can determine whether the defined data type is being used normally."
Polyspace Bug Finder can understand relations between specific data types and detect issues arising from bad use of data types. For instance, if you define "typedef signed int" as int32_t, and then assign a variable of int32_t to a variable of type char, on an architecture where char has smaller size than int, Polyspace Bug Finder can detect the overflow.
But can you elaborate further on what you mean by "used normally"?
I would like to know if bug finder can check padding bytes like above.
Polyspace Bug Finder and Code Prover can understand a structure like the one you have shown. But specifically, what check are you looking for? What would you like Bug Finder to report on the example structure you have shown?
Answers (1)
Snehal
on 31 Jan 2025
Hi,
I understand that you want to know whether Polyspace supports data type restrictions and uninitialized local variable checks.
Yes, Polyspace Bug Finder allows you to specify custom coding rules to enforce the use of specific ‘typedef’ names like ‘int8_t’ or ‘uint32_t’. It automatically detects uninitialized variables, helping prevent undefined behaviour too.
When using Polyspace Bug Finder, custom coding rules can be defined in a ‘.pschk’ file and then used in the bug finder analysis.
To implement this check, refer to the following documentations:
- https://www.mathworks.com/help/bugfinder/ug/enforce-custom-coding-standard-using-polyspace.html
- https://www.mathworks.com/help/bugfinder/ug/create-custom-coding-standard-by-using-polyspace-bug-finder-checkers.html
Both – Polyspace Bug Finder and Code Prover can analyze the memory layout of structures and understand padding introduced by the compiler for alignment purposes.
If a struct object is defined such that the arrangement of its component members requires additional padding in the memory, the checker flags such type of objects. Consider rearranging structure members to minimize padding and enhancing memory efficiency.
Refer to the following documentation links for better understanding:
- https://www.mathworks.com/help/bugfinder/ref/unnecessarypadding.html
- https://www.mathworks.com/help/bugfinder/ref/certcruledcl39c.html
- https://www.mathworks.com/help/bugfinder/ref/informationleakviastructurepadding.html
Hope this helps.
0 Comments
See Also
Categories
Find more on Generate Reports in Polyspace Platform User Interface in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!