[PATCH 2/8] util: Use abs() instead of labs()

Tom Stellard tstellar@redhat.com
Mon Nov 30 19:58:35 GMT 2020


From: Timm Bäder <tbaeder@redhat.com>

Taking the absolute value of unsigned values is pointless, as reported
by clang:

util.cxx:1545:28: error: taking the absolute value of unsigned type 'unsigned long' has no effect [-Werror,-Wabsolute-value]
      unsigned min_score = labs(target.size() - it->size());
                           ^
util.cxx:1545:28: note: remove the call to 'labs' since unsigned values cannot be negative
      unsigned min_score = labs(target.size() - it->size());
---
 util.cxx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util.cxx b/util.cxx
index c31b668a3..bcacacaaf 100644
--- a/util.cxx
+++ b/util.cxx
@@ -1542,7 +1542,7 @@ levenshtein_suggest(const string& target,        // string to match against
 
       // Approximate levenshtein by size-difference only; real score
       // is at least this high
-      unsigned min_score = labs(target.size() - it->size());
+      unsigned min_score = abs(static_cast<signed>(target.size()) - static_cast<signed>(it->size()));
 
       if (min_score > threshold) // min-score too high for threshold
         continue;
-- 
2.26.2



More information about the Systemtap mailing list