Skip to content

Commit 4434664

Browse files
committed
crn_defs: fix false positive “out of range subscript” error
1 parent 73e74fa commit 4434664

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

inc/crn_defs.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ struct crn_packed_uint {
225225
}
226226

227227
inline operator unsigned int() const {
228+
#if 0
229+
/* Compilers will expand the template with all conditions
230+
and generate the code for all conditions even if only one
231+
condition is usable per template variant.
232+
233+
Compilers like ICC will raise warnings at compile time,
234+
and code analysers like CodeQL will raise warnings when
235+
analysing the compiled binary.
236+
237+
See: https://github.com/DaemonEngine/crunch/issues/79 */
238+
228239
switch (N) {
229240
case 1:
230241
return m_buf[0];
@@ -235,6 +246,15 @@ struct crn_packed_uint {
235246
default:
236247
return (m_buf[0] << 24U) | (m_buf[1] << 16U) | (m_buf[2] << 8U) | (m_buf[3]);
237248
}
249+
#else
250+
unsigned int val = 0U;
251+
252+
for (unsigned int i = 0U; i < N; i++) {
253+
val |= m_buf[ i ] << ((N - (i + 1U)) * 8U);
254+
}
255+
256+
return val;
257+
#endif
238258
}
239259

240260
unsigned char m_buf[N];

0 commit comments

Comments
 (0)