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

warning: 'cksm' may be used uninitialized #2

Open
stevstrong opened this issue Jan 1, 2024 · 0 comments
Open

warning: 'cksm' may be used uninitialized #2

stevstrong opened this issue Jan 1, 2024 · 0 comments

Comments

@stevstrong
Copy link

Hello,

by porting this lib to STM32 I have the mentioned warning generated by the compiler at this place:

uint32_t cksm;
// cksm = seed;
position += sizeof(Control_Byte);
while ((ENC28_Rcr8(J60_ECON1) & 0x20) != 0); // Waits until the DMAST bit is clear
ENC28_Wcr16(J60_EDMASTL, (pHead->packetStart + position));
ENC28_Wcr16(J60_EDMANDL, pHead->packetStart + position + (length - 1));
if (!(ENC28_Rcr8(J60_ECON1) & 0x10)) // Verify CSUMEN is not set already
{
// Sets CSUMEN and DMAST to select and start a checksum operation
ENC28_Bfs(J60_ECON1, 0x30);
while ((ENC28_Rcr8(J60_ECON1) & 0x20) != 0); // Waits until the DMAST bit is clear
ENC28_Bfc(J60_ECON1,0x10);
cksm = ENC28_Rcr16(J60_EDMACSL);
if (seed)
{
seed = ~(seed);
cksm += seed;
while (cksm >> 16)
{
cksm = (cksm & 0x0FFFF) + (cksm >> 16);
}
}
cksm = htons(cksm);
}
return (uint16_t)cksm;

Indeed, it looks like for the false case of line 1188 the variable cksm will remain uninitialized.
I could set it to 0 at declaration time (in line 1178), but what would actually be the right solution?

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

No branches or pull requests

1 participant