debevv / nanoMODBUS

A compact MODBUS RTU/TCP C library for embedded/microcontrollers
MIT License
234 stars 47 forks source link

Fix Clang static analyser nit: zero out nmbs_bitfield structs. #25

Closed JanX2 closed 1 year ago

JanX2 commented 1 year ago

Do you have any thoughts on this? Better safe than sorry.

debevv commented 1 year ago

Yup, given the code it won't matter but I like best practices. Can you use nmbs_bitfield_reset()? And can you format the code with the provided .clang-format?. Thank you

JanX2 commented 1 year ago

nmbs_bitfield_reset() does not work with globals. Took me a while to figure out why the macro was failing to compile in some of the sample code. Any suggestions? Fall back to = {0}?

Edit: scratch that. The globals and declarations should be initialized with = {0} so nmbs_bitfield_reset() would be superfluous. nmbs_bitfield_reset() only really makes sense, when we want to set a bitfield back to 0. Am I missing something?

debevv commented 1 year ago

Yes, ={0} should be fine, 1 line is better than 2 anyway. But why do you say nmbs_bitfield_reset() doesn't work? It tried something like this:

nmbs_bitfield a;
int main() {
    nmbs_bitfield_reset(a);
}

and it compiles as expected.

debevv commented 1 year ago

Just realized I missed your edit. Well then, it think this can be closed. Thank you

JanX2 commented 1 year ago

Yes, ={0} should be fine, 1 line is better than 2 anyway. But why do you say nmbs_bitfield_reset() doesn't work? It tried something like this:

nmbs_bitfield a;
int main() {
    nmbs_bitfield_reset(a);
}

and it compiles as expected.

Yes. But this won’t:


nmbs_bitfield a;
nmbs_bitfield_reset(a);
int main() {
    return 0;
}