Bugfinder can support byte padding check?

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

Angelo Yeo
Angelo Yeo on 16 Jan 2024
Edited: Angelo Yeo on 16 Jan 2024
(1) Can you elaborate what "data type restrictions" is?
(2) Regarding non-initialized variables, check out the doc below.
(3) You should also elaborate what your ultimate purpose of byte padding inspection is. However, here are some docs that would be helpful for you.
Thank you for reply. I will provide some supplementary explanation.
(1) Can you elaborate what "data type restrictions" is?
-> This means specifying data type names. For example, if define a "typedef signed chart" as int8_t or "typedef unsigned int" as uint32_t. Also, I would like to inquire whether bug finder can determine whether the defined data type is being used normally.
(3) You should also elaborate what your ultimate purpose of byte padding inspection is. However, here are some docs that would be helpful for you.
-> for example, if define structure as below,
data c is padding in memory map.
I would like to know if bug finder can check padding bytes like above.
" 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?
But can you elaborate further on what you mean by "used normally"?
-> normally means It is possible to distinguish between cases where a data type not declared with typedef is used or a value outside the range of the data type is specified.
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?
-> I would like to detect unwanted padding, such as empty, in the example structure shown.

Sign in to comment.

Answers (1)

Snehal
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:
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:
Hope this helps.

Products

Release

R2019a

Asked:

on 16 Jan 2024

Answered:

on 31 Jan 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!