summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-12-04 12:13:40 +0100
committerThomas Haller <thaller@redhat.com>2023-12-04 12:13:42 +0100
commitacd05d6e8066f775474cbcf00b85b4743efe896e (patch)
tree836472b29e292b667eaf3ea8dafdc4197d58cd81
parentdaa8efcb4c45bd4ad359d74e5f040ef75ad892c9 (diff)
downloadlibnl-acd05d6e8066f775474cbcf00b85b4743efe896e.tar.gz
route/tc: avoid integer overflow in rtnl_tc_calc_cell_log()
Coverity doesn't like this. Workaround. Error: CPPCHECK_WARNING (CWE-190): [#def97] libnl-3.8.0/lib/route/tc.c:681: error[integerOverflow]: Signed integer overflow for expression '1<<i'. # 679| # 680| for (i = 0; i < 32; i++) # 681|-> if ((1 << i) == cell_size) # 682| return i; # 683|
-rw-r--r--lib/route/tc.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/route/tc.c b/lib/route/tc.c
index c9a2ffcf..a2fd5674 100644
--- a/lib/route/tc.c
+++ b/lib/route/tc.c
@@ -671,14 +671,14 @@ int rtnl_tc_calc_bufsize(int txtime, int rate)
/**
* Calculate the binary logarithm for a specific cell size
* @arg cell_size Size of cell, must be a power of two.
- * @return Binary logirhtm of cell size or a negative error code.
+ * @return Binary logarithm of cell size or a negative error code.
*/
int rtnl_tc_calc_cell_log(int cell_size)
{
int i;
for (i = 0; i < 32; i++)
- if ((1 << i) == cell_size)
+ if ((((uint32_t)1u) << i) == cell_size)
return i;
return -NLE_INVAL;