File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -39,14 +39,15 @@ struct packed_uint {
39
39
}
40
40
41
41
inline operator unsigned int () const {
42
- switch (sizeof (m_buf) / sizeof (m_buf[0 ])) {
42
+ CRNLIB_ASSUME (sizeof (m_buf) == N);
43
+ switch (N) {
43
44
case 1 :
44
45
return m_buf[0 ];
45
46
case 2 :
46
47
return (m_buf[0 ] << 8U ) | m_buf[1 ];
47
48
case 3 :
48
49
return (m_buf[0 ] << 16U ) | (m_buf[1 ] << 8U ) | (m_buf[2 ]);
49
- case 4 :
50
+ default :
50
51
return (m_buf[0 ] << 24U ) | (m_buf[1 ] << 16U ) | (m_buf[2 ] << 8U ) | (m_buf[3 ]);
51
52
}
52
53
}
Original file line number Diff line number Diff line change @@ -225,14 +225,15 @@ struct crn_packed_uint {
225
225
}
226
226
227
227
inline operator unsigned int () const {
228
- switch (sizeof (m_buf) / sizeof (m_buf[0 ])) {
228
+ static_assert (sizeof (m_buf) == N, " " );
229
+ switch (N) {
229
230
case 1 :
230
231
return m_buf[0 ];
231
232
case 2 :
232
233
return (m_buf[0 ] << 8U ) | m_buf[1 ];
233
234
case 3 :
234
235
return (m_buf[0 ] << 16U ) | (m_buf[1 ] << 8U ) | (m_buf[2 ]);
235
- case 4 :
236
+ default :
236
237
return (m_buf[0 ] << 24U ) | (m_buf[1 ] << 16U ) | (m_buf[2 ] << 8U ) | (m_buf[3 ]);
237
238
}
238
239
}
You can’t perform that action at this time.
0 commit comments