Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a sign propagation in calculating transaction size statistics
This patch fixes bugs in sign propagation disovered with -Wsign-conversion compilar flag and related integer overflows in dnf5::print_transaction_size_stats(), like this one: dnf5/main.cpp: In function ‘void dnf5::print_transaction_size_stats(Context&)’: dnf5/main.cpp:785:29: error: conversion to ‘long long unsigned int’ from ‘int64_t’ {aka ‘long int’} may change the sign of the result [-Werror=sign-conversion] 785 | in_pkgs_size += pkg_size; | ^~~~~~~~ There were more ways of fixing, but I choose this one: Use unsigned integers because an integer overflow for signed types is undefined in C++. I choose unsigned long long int to follow what get_download_size() and get_install_size() returns. Otherwise, we would have to add another check whether the value fits into e.g. uint64_t. Unless we chose uintmax_t. Explicitly type-cast counters, with a prior range check, on passing them to libdnf5::cli::utils::units::to_size(). Otherwise, we would have to add to_size() for unsigned integers to the public API. (Actuallly to_size() should have been for unsigned integeres from the very beginning. Package sizes cannot be negative.) Not printing the transaction size statistics if an irrepresentible value occurs. Adding more branches to the already complicated code for the very improbably corner cases does not make much sense. (I tried also a different implemeation with keeping int64_t as the counters, but the code was longer and uglier.) Related: #1701
- Loading branch information