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 {
3939 }
4040
4141 inline operator unsigned int () const {
42- switch (sizeof (m_buf) / sizeof (m_buf[0 ])) {
42+ CRNLIB_ASSUME (sizeof (m_buf) == N);
43+ switch (N) {
4344 case 1 :
4445 return m_buf[0 ];
4546 case 2 :
4647 return (m_buf[0 ] << 8U ) | m_buf[1 ];
4748 case 3 :
4849 return (m_buf[0 ] << 16U ) | (m_buf[1 ] << 8U ) | (m_buf[2 ]);
49- case 4 :
50+ default :
5051 return (m_buf[0 ] << 24U ) | (m_buf[1 ] << 16U ) | (m_buf[2 ] << 8U ) | (m_buf[3 ]);
5152 }
5253 }
Original file line number Diff line number Diff line change @@ -225,14 +225,15 @@ struct crn_packed_uint {
225225 }
226226
227227 inline operator unsigned int () const {
228- switch (sizeof (m_buf) / sizeof (m_buf[0 ])) {
228+ static_assert (sizeof (m_buf) == N, " " );
229+ switch (N) {
229230 case 1 :
230231 return m_buf[0 ];
231232 case 2 :
232233 return (m_buf[0 ] << 8U ) | m_buf[1 ];
233234 case 3 :
234235 return (m_buf[0 ] << 16U ) | (m_buf[1 ] << 8U ) | (m_buf[2 ]);
235- case 4 :
236+ default :
236237 return (m_buf[0 ] << 24U ) | (m_buf[1 ] << 16U ) | (m_buf[2 ] << 8U ) | (m_buf[3 ]);
237238 }
238239 }
You can’t perform that action at this time.
0 commit comments