Parent: d1009b35c460d700bab7214a3ef2c38e2ab069c7
Author: Anderson Lizardo <anderson.lizardo@openbossa.org>
Committer: Johan Hedberg <johan.hedberg@intel.com>
Date: 2014-01-27 19:55:27
Tree: 0128e78bd2a28f976061d51c4f0d9a2d40b12fb3
shared: Fix undefined behavior when calculating next power of two According to GCC documentation, __builtin_clz() is undefined if argument is zero. The following problem was detected when compiling with -O0: ERROR:unit/test-ringbuf.c:70:test_power2: assertion failed: (size1 == size2) Also refactor align_power2() so the internal "find last set bit" operation is in its own fls() function (similar to how kernel does). fls() checks if argument is zero before calling __builtin_clz().
Diffstat
| M | src/shared/ringbuf.c | | | 9 | ++++++++- |
| M | unit/test-ringbuf.c | | | 7 | ++++++- |
2 files changed, 14 insertions(+), 2 deletions(-)