diff options
author | Thomas Haller <thaller@redhat.com> | 2023-12-04 11:13:40 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-12-04 11:13:42 (GMT) |
commit | acd05d6e8066f775474cbcf00b85b4743efe896e (patch) | |
tree | 836472b29e292b667eaf3ea8dafdc4197d58cd81 | |
parent | daa8efcb4c45bd4ad359d74e5f040ef75ad892c9 (diff) | |
download | libnl-acd05d6e8066f775474cbcf00b85b4743efe896e.zip libnl-acd05d6e8066f775474cbcf00b85b4743efe896e.tar.gz libnl-acd05d6e8066f775474cbcf00b85b4743efe896e.tar.bz2 |
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.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/route/tc.c b/lib/route/tc.c index c9a2ffc..a2fd567 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; |