mirror of
https://github.com/ceph/ceph
synced 2025-01-04 10:12:30 +00:00
test: Division by zero in Legacy::encode_n()
Fixes the Coverity Scan Report: CID 1411820 (#1 of 1): Division or modulo by zero (DIVIDE_BY_ZERO) 9. divide_by_zero: In expression bl.length() * i / sum, division by expression sum which may be zero has undefined behavior. Signed-off-by: Jos Collin <jcollin@redhat.com>
This commit is contained in:
parent
3abb692384
commit
28cf5ac8b0
@ -613,6 +613,7 @@ bufferlist Legacy::encode_n(unsigned n, const vector<unsigned>& segments) {
|
||||
auto p = bl.begin();
|
||||
|
||||
auto sum = std::accumulate(segments.begin(), segments.end(), 0u);
|
||||
assert(sum != 0u);
|
||||
for (auto i : segments) {
|
||||
buffer::ptr seg;
|
||||
p.copy_deep(bl.length() * i / sum, seg);
|
||||
|
Loading…
Reference in New Issue
Block a user