Skip to content

Commit

Permalink
Merge pull request CleverRaven#33166 from jbytheway/clang_tidy_bugpro…
Browse files Browse the repository at this point in the history
…ne_too_small_loop_variable

clang-tidy bugprone-too-small-loop-variable
  • Loading branch information
ZhilkinSerg authored Aug 12, 2019
2 parents b28c17f + 9d72a63 commit 4df9ad2
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 19 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ performance-*,\
readability-*,\
-bugprone-misplaced-widening-cast,\
-bugprone-narrowing-conversions,\
-bugprone-too-small-loop-variable,\
-bugprone-undefined-memory-manipulation,\
-bugprone-unused-return-value,\
-bugprone-use-after-move,\
Expand Down
8 changes: 4 additions & 4 deletions src/defense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ Press %s to buy everything in your cart, %s to buy nothing." ),
total_price += caravan_price( g->u, item( tmp_itm, 0 ).price( false ) );
if( category_selected == CARAVAN_CART ) { // Find the item in its category
for( int i = 1; i < NUM_CARAVAN_CATEGORIES; i++ ) {
for( unsigned j = 0; j < items[i].size(); j++ ) {
for( size_t j = 0; j < items[i].size(); j++ ) {
if( items[i][j] == tmp_itm ) {
item_count[i][j]++;
}
Expand Down Expand Up @@ -1055,7 +1055,7 @@ Press %s to buy everything in your cart, %s to buy nothing." ),
total_price -= caravan_price( g->u, item( tmp_itm, 0 ).price( false ) );
if( category_selected == CARAVAN_CART ) { // Find the item in its category
for( int i = 1; i < NUM_CARAVAN_CATEGORIES; i++ ) {
for( unsigned j = 0; j < items[i].size(); j++ ) {
for( size_t j = 0; j < items[i].size(); j++ ) {
if( items[i][j] == tmp_itm ) {
item_count[i][j]--;
}
Expand Down Expand Up @@ -1117,7 +1117,7 @@ Press %s to buy everything in your cart, %s to buy nothing." ),
if( !cancel ) {
g->u.cash -= total_price;
bool dropped_some = false;
for( unsigned i = 0; i < items[0].size(); i++ ) {
for( size_t i = 0; i < items[0].size(); i++ ) {
item tmp( items[0][i] );
tmp = tmp.in_its_container();

Expand Down Expand Up @@ -1456,7 +1456,7 @@ std::string defense_game::special_wave_message( std::string name )

// Capitalize
capitalize_letter( name );
for( unsigned i = 2; i < name.size(); i++ ) {
for( size_t i = 2; i < name.size(); i++ ) {
if( name[i - 1] == ' ' ) {
capitalize_letter( name, i );
}
Expand Down
4 changes: 2 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,8 @@ bool game::cleanup_at_end()
sfx::fade_audio_group( 3, 2000 );
sfx::fade_audio_group( 4, 2000 );

for( unsigned int iY = 0; iY < vRip.size(); ++iY ) {
for( unsigned int iX = 0; iX < vRip[iY].length(); ++iX ) {
for( size_t iY = 0; iY < vRip.size(); ++iY ) {
for( size_t iX = 0; iX < vRip[iY].length(); ++iX ) {
char cTemp = vRip[iY][iX];
if( cTemp != ' ' ) {
nc_color ncColor = c_light_gray;
Expand Down
4 changes: 2 additions & 2 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6428,14 +6428,14 @@ std::vector<tripoint> map::get_dir_circle( const tripoint &f, const tripoint &t
// 642 864 786 578 357 135 213 421

size_t pos_offset = 0;
for( unsigned int i = 1; i < spiral.size(); i++ ) {
for( size_t i = 1; i < spiral.size(); i++ ) {
if( spiral[i] == line[0] ) {
pos_offset = i - 1;
break;
}
}

for( unsigned int i = 1; i < spiral.size(); i++ ) {
for( size_t i = 1; i < spiral.size(); i++ ) {
if( pos_offset >= pos_index.size() ) {
pos_offset = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ float npc::vehicle_danger( int radius ) const
int danger = 0;

// TODO: check for most dangerous vehicle?
for( unsigned int i = 0; i < vehicles.size(); ++i ) {
for( size_t i = 0; i < vehicles.size(); ++i ) {
const wrapped_vehicle &wrapped_veh = vehicles[i];
if( wrapped_veh.v->is_moving() ) {
// FIXME: this can't be the right way to do this
Expand Down
8 changes: 4 additions & 4 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ bool npc::consume_cbm_items( const std::function<bool( const item & )> &filter )
{
invslice slice = inv.slice();
int index = -1;
for( unsigned int i = 0; i < slice.size(); i++ ) {
for( size_t i = 0; i < slice.size(); i++ ) {
const item &it = slice[i]->front();
const item &real_item = it.is_container() ? it.contents.front() : it;
if( filter( real_item ) ) {
Expand Down Expand Up @@ -2825,7 +2825,7 @@ void npc::drop_items( int weight, int volume )

// First fill our ratio vectors, so we know which things to drop first
invslice slice = inv.slice();
for( unsigned int i = 0; i < slice.size(); i++ ) {
for( size_t i = 0; i < slice.size(); i++ ) {
item &it = slice[i]->front();
double wgt_ratio = 0.0;
double vol_ratio = 0.0;
Expand Down Expand Up @@ -3478,7 +3478,7 @@ bool npc::consume_food()
int want_hunger = get_hunger();
int want_quench = get_thirst();
invslice slice = inv.slice();
for( unsigned int i = 0; i < slice.size(); i++ ) {
for( size_t i = 0; i < slice.size(); i++ ) {
const item &it = slice[i]->front();
const item &food_item = it.is_food_container() ?
it.contents.front() : it;
Expand Down Expand Up @@ -3553,7 +3553,7 @@ void npc::mug_player( player &mark )
double best_value = minimum_item_value() * value_mod;
int item_index = INT_MIN;
invslice slice = mark.inv.slice();
for( unsigned int i = 0; i < slice.size(); i++ ) {
for( size_t i = 0; i < slice.size(); i++ ) {
if( value( slice[i]->front() ) >= best_value &&
can_pickVolume( slice[i]->front(), true ) &&
can_pickWeight( slice[i]->front(), true ) ) {
Expand Down
6 changes: 3 additions & 3 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,12 +986,12 @@ void options_manager::init()
add_options_world_default();
add_options_android();

for( unsigned i = 0; i < vPages.size(); ++i ) {
for( size_t i = 0; i < vPages.size(); ++i ) {
mPageItems[i].resize( mOptionsSort[vPages[i].first] );
}

for( auto &elem : options ) {
for( unsigned i = 0; i < vPages.size(); ++i ) {
for( size_t i = 0; i < vPages.size(); ++i ) {
if( vPages[i].first == elem.second.getPage() && elem.second.getSortPos() > -1 ) {
mPageItems[i][elem.second.getSortPos()] = elem.first;
break;
Expand All @@ -1000,7 +1000,7 @@ void options_manager::init()
}

//Sort out possible double empty lines after options are hidden
for( unsigned i = 0; i < vPages.size(); ++i ) {
for( size_t i = 0; i < vPages.size(); ++i ) {
bool bLastLineEmpty = false;
while( mPageItems[i][0].empty() ) {
//delete empty lines at the beginning
Expand Down
2 changes: 1 addition & 1 deletion tests/explosion_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void check_vehicle_damage( const std::string &explosive_id, const std::st

// We don't expect any destroyed parts.
REQUIRE( before_hp.size() == after_hp.size() );
for( unsigned int i = 0; i < before_hp.size(); ++i ) {
for( size_t i = 0; i < before_hp.size(); ++i ) {
INFO( target_vehicle->parts[ i ].name() );
if( target_vehicle->parts[ i ].info().get_id() == "windshield" ||
target_vehicle->parts[ i ].info().get_id() == "headlight" ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/new_character_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static std::vector<trait_id> next_subset( const std::vector<trait_id> &set )

++bitset;
// Check each bit position for a match
for( unsigned idx = 0; idx < set.size(); idx++ ) {
for( size_t idx = 0; idx < set.size(); idx++ ) {
if( bitset & ( 1 << idx ) ) {
ret.push_back( set[idx] );
}
Expand Down

0 comments on commit 4df9ad2

Please sign in to comment.