Skip to content
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

Handle UB in bit_scan_forward #20

Merged
merged 1 commit into from
Nov 29, 2015
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion include/eixx/connect/transport_msg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class transport_msg {

/// Transport message type
transport_msg_type type() const { return m_type; }
int to_type() const { return bit_scan_forward(m_type); }
int to_type() const { return m_type == UNDEFINED ? 0 : bit_scan_forward(m_type); }
const tuple<Alloc>& cntrl() const { return m_cntrl;}
const eterm<Alloc>& msg() const { return m_msg; }
/// Returns true when the transport message contains message payload
Expand Down
3 changes: 2 additions & 1 deletion include/eixx/util/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ int __inline__ log2(unsigned long n, uint8_t base = 2) {
return n == 1 ? 0 : 1+log2(n/base, base);
}

static __inline__ unsigned long bit_scan_forward(unsigned long v)
/// Note, that bit_scan_forward(0) leads to UB
static __inline__ int bit_scan_forward(unsigned long v)
{
return __builtin_ctzl(v);
}
Expand Down