diff --git a/.clang-tidy b/.clang-tidy index 87b100911cc79..fac1beb1f2f82 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,4 @@ -Checks: 'clang-diagnostic-*,-clang-analyzer-deadcode.DeadStores,-clang-analyzer-security.FloatLoopCounter,-clang-analyzer-core.UndefinedBinaryOperatorResult,-clang-analyzer-core.uninitialized.Assign,-clang-analyzer-cplusplus.NewDelete,-clang-analyzer-cplusplus.NewDeleteLeaks,-clang-analyzer-core.CallAndMessage,-clang-analyzer-core.NonNullParamChecker,-clang-analyzer-core.DivideZero,-clang-diagnostic-defaulted-function-deleted,-clang-analyzer-optin.cplusplus.VirtualCall' +Checks: 'clang-diagnostic-*,-clang-analyzer-deadcode.DeadStores,-clang-analyzer-security.FloatLoopCounter,-clang-analyzer-core.UndefinedBinaryOperatorResult,-clang-analyzer-core.uninitialized.Assign,-clang-analyzer-cplusplus.NewDeleteLeaks,-clang-analyzer-core.CallAndMessage,-clang-analyzer-core.NonNullParamChecker,-clang-analyzer-optin.cplusplus.VirtualCall,-clang-analyzer-core.NullDereference' WarningsAsErrors: '*' HeaderFilterRegex: '.*' FormatStyle: none diff --git a/src/item.cpp b/src/item.cpp index faeeacfc2fb57..89d5c3fa2bf73 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -597,12 +597,22 @@ item item::in_container( const itype_id &cont ) const long item::charges_per_volume( const units::volume &vol ) const { - if( type->volume == 0_ml ) { - return INFINITE_CHARGES; // TODO: items should not have 0 volume at all! + if( count_by_charges() ) { + if( type->volume == 0_ml ) { + debugmsg( "Item '%s' with zero volume", tname() ); + return INFINITE_CHARGES; + } + // Type cast to prevent integer overflow with large volume containers like the cargo + // dimension + return vol * static_cast( type->stack_size ) / type->volume; + } else { + units::volume my_volume = volume(); + if( my_volume == 0_ml ) { + debugmsg( "Item '%s' with zero volume", tname() ); + return INFINITE_CHARGES; + } + return vol / my_volume; } - // Type cast to prevent integer overflow with large volume containers like the cargo dimension - return count_by_charges() ? vol * static_cast( type->stack_size ) / type->volume - : vol / volume(); } bool item::stacks_with( const item &rhs, bool check_components ) const diff --git a/src/mission_companion.cpp b/src/mission_companion.cpp index e9016a4625a5a..c351e623fa65b 100644 --- a/src/mission_companion.cpp +++ b/src/mission_companion.cpp @@ -1849,11 +1849,11 @@ std::vector talk_function::companion_rank( const std::vector } std::vector adjusted; - for( auto entry : raw ) { + for( const auto &entry : raw ) { comp_rank r; - r.combat = 100 * entry.combat / max_combat; - r.survival = 100 * entry.survival / max_survival; - r.industry = 100 * entry.industry / max_industry; + r.combat = max_combat ? 100 * entry.combat / max_combat : 0; + r.survival = max_survival ? 100 * entry.survival / max_survival : 0; + r.industry = max_industry ? 100 * entry.industry / max_industry : 0; adjusted.push_back( r ); } return adjusted; diff --git a/src/veh_interact.cpp b/src/veh_interact.cpp index 5cedfc4f3dddf..2c14e9fb46b3a 100644 --- a/src/veh_interact.cpp +++ b/src/veh_interact.cpp @@ -2595,7 +2595,7 @@ void veh_interact::count_durability() return lhs + rhs.base.max_damage(); } ); - int pct = 100 * qty / total; + int pct = total ? 100 * qty / total : 0; if( pct < 5 ) { total_durability_text = _( "like new" ); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 726fcde505484..e5ad91563ef53 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2972,7 +2972,15 @@ int vehicle::consumption_per_hour( const itype_id &ftype, int fuel_rate_w ) cons // add 3600 seconds worth of fuel consumption for the engine // HACK - engines consume 1 second worth of fuel per turn, even though a turn is 6 seconds if( vslowdown > 0 ) { - amount_pct += 600 * vslowdown / acceleration( true, target_v ); + int accel = acceleration( true, target_v ); + if( accel == 0 ) { + // FIXME: Long-term plan is to change the fuel consumption + // computation entirely; for now just warn if this would + // otherwise have been division-by-zero + debugmsg( "Vehicle unexpectedly has zero acceleration" ); + } else { + amount_pct += 600 * vslowdown / accel; + } } } int energy_j_per_mL = fuel.fuel_energy() * 1000;