Fix integer overflows in btop_collect.cpp #546
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Correct data types in calls to std::accumulate(). The "bandwidth" deques have type "long long", so the initial value of the accumulator (0) must also be "long long" (i.e., "0ll") to prevent integer overflows. Also, since since the bandwidth deques are (signed) "long long", the avg_speed should presumably be a signed "long long" instead of an unsigned "uint64_t". The previous behavior was for large bandwidth values to overflow the accumulator, resulting in a negative total, which then was cast to be a huge "uint64_t" value. As a consequence, the network graph autoscaling was broken for large bandwidths.
Changes are very minor but untested on FreeBSD and macOS.
Fixes #545.