ravioli icon indicating copy to clipboard operation
ravioli copied to clipboard

Variable initialization to numeric constant treated as global.

Open ghost opened this issue 6 years ago • 4 comments

sample code:

#define VAL 0
union
{
    typedef_struct_t tst;
    uint32_t val;    // for alignment
} new_struct;

new_struct.tst.a = 0;
new_struct.tst.b = VAL;

Those new_struct initialization statements increase the globals count.

ghost avatar Oct 31 '19 16:10 ghost

Upon further investigation, it looks like alignment (extra whitespace) is the issue.

new_struct.tst.long_var_name = 0;
new_struct.tst.var_name =          0;
new_struct.tst.var2_name        = VAL;

The second assignment increases the globals count.

ghost avatar Oct 31 '19 17:10 ghost

+1 I also have a lot of false positive.

g-berthiaume avatar Dec 17 '19 19:12 g-berthiaume

Hello!

It turns out the the way ravioli counts globals is quite naive -- and likely to be quite buggy -- and also isn't correct for the way KSF is defined.

What it needs to count are global usages not merely global definitions. This is a bit more complicated problem, but the right thing to do.

I'm currently working on improvements to global counting. When this is done, this should potentially fix a variety of issues.

mchernosky avatar Aug 27 '21 22:08 mchernosky

I'm currently working on improvements to global counting. When this is done, this should potentially fix a variety of issues.

Great! Looking forward to it.

g-berthiaume avatar Aug 28 '21 00:08 g-berthiaume