This is an automated email from the ASF dual-hosted git repository.
achennaka pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 8aab39e8b [gutil] fix ASAN warning in CountOnes()
8aab39e8b is described below
commit 8aab39e8b7601c75b0c516c82f1ea6b85c5cfcd6
Author: Alexey Serbin <[email protected]>
AuthorDate: Tue Oct 10 19:52:00 2023 -0700
[gutil] fix ASAN warning in CountOnes()
Running various tests on aarch64 (Graviton3) under ASAN produced
warnings like below:
src/kudu/gutil/bits.h:19:42: runtime error: unsigned integer overflow:
134678536 * 16843009 cannot be represented in type 'unsigned int'
#0 0xffffa1ebd8d4 in Bits::CountOnes(unsigned int)
src/kudu/gutil/bits.h:19:42
#1 0xffffa1ebd830 in Bits::CountOnes64(unsigned long)
src/kudu/gutil/bits.h:30:12
#2 0xffffa1ebd7f8 in Bits::CountOnes64withPopcount(unsigned long)
src/kudu/gutil/bits.h:43:12
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
src/kudu/gutil/bits.h:19:42
This patch addresses the issue.
Change-Id: I47bff62676ee57706d6b5ef841e3891bba5a62fa
Reviewed-on: http://gerrit.cloudera.org:8080/20558
Reviewed-by: Marton Greber <[email protected]>
Tested-by: Alexey Serbin <[email protected]>
Reviewed-by: Abhishek Chennaka <[email protected]>
---
src/kudu/gutil/bits.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/kudu/gutil/bits.h b/src/kudu/gutil/bits.h
index b4a4327b5..1c3c71417 100644
--- a/src/kudu/gutil/bits.h
+++ b/src/kudu/gutil/bits.h
@@ -16,7 +16,7 @@ class Bits {
static int CountOnes(uint32 n) {
n -= ((n >> 1) & 0x55555555);
n = ((n >> 2) & 0x33333333) + (n & 0x33333333);
- return (((n + (n >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
+ return static_cast<int>((((n + (n >> 4)) & 0xF0F0F0FULL) * 0x1010101ULL)
>> 24);
}
// Count bits using sideways addition [WWG'57]. See Knuth TAOCP v4 7.1.3(59)