Skip to content

crn_defs: fix false positive “out of range subscript” error #83

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions inc/crn_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ struct crn_packed_uint {
}

inline operator unsigned int() const {
#if 0
/* Compilers will expand the template with all conditions
and generate the code for all conditions even if only one
condition is usable per template variant.

Compilers like ICC will raise warnings at compile time,
and code analysers like CodeQL will raise warnings when
analysing the compiled binary.

See: https://github.com/DaemonEngine/crunch/issues/79 */

switch (N) {
case 1:
return m_buf[0];
Expand All @@ -235,6 +246,15 @@ struct crn_packed_uint {
default:
return (m_buf[0] << 24U) | (m_buf[1] << 16U) | (m_buf[2] << 8U) | (m_buf[3]);
}
#else
unsigned int val = 0U;

for (unsigned int i = 0U; i < N; i++) {
val |= m_buf[ i ] << ((N - (i + 1U)) * 8U);
}

return val;
#endif
}

unsigned char m_buf[N];
Expand Down