Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jul 10, 2024
1 parent fae8821 commit fdf1b61
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions crnlib/crn_packed_uint.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ struct packed_uint {
}

inline operator unsigned int() const {
switch (sizeof(m_buf) / sizeof(m_buf[0])) {
CRNLIB_ASSUME(sizeof(m_buf) == N);
switch (N) {
case 1:
return m_buf[0];
case 2:
return (m_buf[0] << 8U) | m_buf[1];
case 3:
return (m_buf[0] << 16U) | (m_buf[1] << 8U) | (m_buf[2]);
case 4:
default:
return (m_buf[0] << 24U) | (m_buf[1] << 16U) | (m_buf[2] << 8U) | (m_buf[3]);
}
}
Expand Down
5 changes: 3 additions & 2 deletions inc/crn_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,15 @@ struct crn_packed_uint {
}

inline operator unsigned int() const {
switch (sizeof(m_buf) / sizeof(m_buf[0])) {
static_assert(sizeof(m_buf) == N, "");
switch (N) {
case 1:
return m_buf[0];
case 2:
return (m_buf[0] << 8U) | m_buf[1];
case 3:
return (m_buf[0] << 16U) | (m_buf[1] << 8U) | (m_buf[2]);
case 4:
default:
return (m_buf[0] << 24U) | (m_buf[1] << 16U) | (m_buf[2] << 8U) | (m_buf[3]);
}
}
Expand Down

0 comments on commit fdf1b61

Please sign in to comment.