Skip to content

Commit

Permalink
Merge pull request #64694 from BrettDong/clang-tidy-fix
Browse files Browse the repository at this point in the history
Preparation for upgrading to clang-tidy 16
  • Loading branch information
dseguin authored Mar 31, 2023
2 parents fc74bce + ab3f437 commit 1df1844
Show file tree
Hide file tree
Showing 26 changed files with 29 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ void repair_item_finish( player_activity *act, Character *you, bool no_menu )
item_location *ploc = nullptr;

if( !act->targets.empty() ) {
ploc = &act->targets[0];
ploc = act->targets.data();
}

item &main_tool = !w_hack.init( *act ) ?
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void advanced_inventory_pane::load_settings( int saved_area_idx,
!is_re_enter ) ? saved_area_idx :
save_state->area_idx;
const aim_location location = static_cast<aim_location>( i_location );
const advanced_inv_area square = squares[location];
const advanced_inv_area &square = squares[location];
// determine the square's vehicle/map item presence
bool has_veh_items = square.can_store_in_vehicle() ?
!square.veh->get_items( square.vstor ).empty() : false;
Expand Down
2 changes: 0 additions & 2 deletions src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include "weather.h"

#if defined(TILES)
#include <memory>

#include "cata_tiles.h" // all animation functions will be pushed out to a cata_tiles function in some manner
#include "sdltiles.h"
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ void avatar::power_bionics()
const bionic_data &bio_data = bio_id.obj();
if( menu_mode == ACTIVATING ) {
if( bio_data.activated ) {
int b = tmp - &( *my_bionics )[0];
int b = tmp - my_bionics->data();
bionic &bio = ( *my_bionics )[b];
hide = true;
ui.mark_resize();
Expand Down
3 changes: 1 addition & 2 deletions src/cata_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "cached_options.h"
#include "catacharset.h"
#include "cata_utility.h"
#include "debug.h"
#include "enum_conversions.h"
#include "filesystem.h"
Expand Down Expand Up @@ -511,7 +510,7 @@ std::optional<std::string> read_whole_file( const fs::path &path )
fin.seekg( 0 );

outstring.resize( size );
fin.read( &outstring[0], size );
fin.read( outstring.data(), size );
}
if( fin.bad() ) {
throw std::runtime_error( "reading file failed" );
Expand Down
8 changes: 4 additions & 4 deletions src/catacharset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ std::wstring utf8_to_wstr( const std::string &str )
#if defined(_WIN32)
int sz = MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, nullptr, 0 ) + 1;
std::wstring wstr( sz, '\0' );
MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, &wstr[0], sz );
MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, wstr.data(), sz );
strip_trailing_nulls( wstr );
return wstr;
#else
std::size_t sz = std::mbstowcs( nullptr, str.c_str(), 0 ) + 1;
std::wstring wstr( sz, '\0' );
std::mbstowcs( &wstr[0], str.c_str(), sz );
std::mbstowcs( wstr.data(), str.c_str(), sz );
strip_trailing_nulls( wstr );
return wstr;
#endif
Expand All @@ -364,13 +364,13 @@ std::string wstr_to_utf8( const std::wstring &wstr )
#if defined(_WIN32)
int sz = WideCharToMultiByte( CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr );
std::string str( sz, '\0' );
WideCharToMultiByte( CP_UTF8, 0, wstr.c_str(), -1, &str[0], sz, nullptr, nullptr );
WideCharToMultiByte( CP_UTF8, 0, wstr.c_str(), -1, str.data(), sz, nullptr, nullptr );
strip_trailing_nulls( str );
return str;
#else
std::size_t sz = std::wcstombs( nullptr, wstr.c_str(), 0 ) + 1;
std::string str( sz, '\0' );
std::wcstombs( &str[0], wstr.c_str(), sz );
std::wcstombs( str.data(), wstr.c_str(), sz );
strip_trailing_nulls( str );
return str;
#endif
Expand Down
1 change: 0 additions & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#ifndef CATA_SRC_CHARACTER_H
#define CATA_SRC_CHARACTER_H

#include <functional>
#include <algorithm>
#include <bitset>
#include <climits>
Expand Down
1 change: 0 additions & 1 deletion src/computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <cstdlib>
#include <sstream>

#include "computer.h"
#include "debug.h"
#include "enum_conversions.h"
#include "json.h"
Expand Down
2 changes: 1 addition & 1 deletion src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ void construct::done_appliance( const tripoint_bub_ms &p, Character & )
return;
}

const item base = components.front();
const item &base = components.front();
const vpart_id &vpart = vpart_appliance_from_item( base.typeId() );

// TODO: fix point types
Expand Down
2 changes: 1 addition & 1 deletion src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ std::pair<nutrients, nutrients> Character::compute_nutrient_range(
our_extra_flags.insert( flag_COOKED );
}

const requirement_data requirements = rec.simple_requirements();
const requirement_data &requirements = rec.simple_requirements();
const requirement_data::alter_item_comp_vector &component_requirements =
requirements.get_components();

Expand Down
2 changes: 0 additions & 2 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
#include "translations.h"
#include "ui_manager.h"

using std::min; // from <algorithm>

static const std::string default_context_id( "default" );

template <class T1, class T2>
Expand Down
10 changes: 5 additions & 5 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,25 +1598,25 @@ double item::get_var( const std::string &name, const double default_value ) cons
const std::string &val = it->second;
char *end;
errno = 0;
double result = strtod( &val[0], &end );
double result = strtod( val.data(), &end );
if( errno != 0 ) {
debugmsg( "Error parsing floating point value from %s in item::get_var: %s",
val, strerror( errno ) );
return default_value;
}
if( end != &val[0] + val.size() ) {
if( end != val.data() + val.size() ) {
if( *end == ',' ) {
// likely legacy format with localized ',' for fraction separator instead of '.'
std::string converted_val = val;
converted_val[end - &val[0]] = '.';
converted_val[end - val.data()] = '.';
errno = 0;
double result = strtod( &converted_val[0], &end );
double result = strtod( converted_val.data(), &end );
if( errno != 0 ) {
debugmsg( "Error parsing floating point value from %s in item::get_var: %s",
val, strerror( errno ) );
return default_value;
}
if( end != &converted_val[0] + converted_val.size() ) {
if( end != converted_val.data() + converted_val.size() ) {
debugmsg( "Stray characters at end of floating point value %s in item::get_var", val );
}
return result;
Expand Down
4 changes: 2 additions & 2 deletions src/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ void TextJsonIn::error( int offset, const std::string &message )
rewind( 3, 240 );
size_t startpos = tell();
std::string buffer( pos - startpos, '\0' );
stream->read( &buffer[0], pos - startpos );
stream->read( buffer.data(), pos - startpos );
auto it = buffer.begin();
for( ; it < buffer.end() && ( *it == '\r' || *it == '\n' ); ++it ) {
// skip starting newlines
Expand Down Expand Up @@ -2073,7 +2073,7 @@ std::string TextJsonIn::substr( size_t pos, size_t len )
}
ret.resize( len );
stream->seekg( pos );
stream->read( &ret[0], len );
stream->read( ret.data(), len );
return ret;
}

Expand Down
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*/

// IWYU pragma: no_include <sys/signal.h>
#include <clocale>
#include <algorithm>
#include <array>
#include <clocale>
Expand Down
2 changes: 2 additions & 0 deletions src/mapgen_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2185,8 +2185,10 @@ void mapgen_forest( mapgendata &dat )
if( p.x < SEEX ) {
if( p.y < SEEY ) {
unify_continuous_border( adjacent_biomes[3], adjacent_biomes[7], adjacent_biomes[0],
// NOLINTNEXTLINE(readability-container-data-pointer)
&cardinal_four_weights[3], &cardinal_four_weights[0], self_weight );
} else {
// NOLINTNEXTLINE(readability-container-data-pointer)
unify_continuous_border( adjacent_biomes[0], adjacent_biomes[4], adjacent_biomes[1],
&cardinal_four_weights[0], &cardinal_four_weights[1], self_weight );
}
Expand Down
2 changes: 1 addition & 1 deletion src/memorial_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void memorial_logger::load( std::istream &fin )
size_t size = fin.tellg();
fin.seekg( 0, std::ios_base::beg );
memorial_data.resize( size );
fin.read( &memorial_data[0], size );
fin.read( memorial_data.data(), size );
JsonValue jsin = json_loader::from_string( memorial_data );
if( !jsin.read( log ) ) {
debugmsg( "Error reading JSON memorial log" );
Expand Down
1 change: 0 additions & 1 deletion src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
#include "viewer.h"
#include "weakpoint.h"
#include "weather.h"
#include "harvest.h"

static const anatomy_id anatomy_default_anatomy( "default_anatomy" );

Expand Down
1 change: 0 additions & 1 deletion src/options.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "options.h"

#include <clocale>
#include <cfloat>
#include <climits>
#include <clocale>
Expand Down
1 change: 0 additions & 1 deletion src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <algorithm>
#include <functional>
#include <functional>
#include <iosfwd>
#include <map>
#include <optional>
Expand Down
8 changes: 4 additions & 4 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ std::string trim_by_length( const std::string &text, int width )

const std::vector<std::string> color_segments = split_by_color( text );
for( size_t i = 0; i < color_segments.size() ; ++i ) {
std::string seg = color_segments[i];
const std::string &seg = color_segments[i];
if( seg.empty() ) {
// TODO: Check is required right now because, for a fully-color-tagged string, split_by_color
// returns an empty string first
Expand Down Expand Up @@ -1346,7 +1346,7 @@ std::string to_upper_case( const std::string &s )
{
const auto &f = std::use_facet<std::ctype<wchar_t>>( std::locale() );
std::wstring wstr = utf8_to_wstr( s );
f.toupper( &wstr[0], &wstr[0] + wstr.size() );
f.toupper( wstr.data(), wstr.data() + wstr.size() );
return wstr_to_utf8( wstr );
}

Expand Down Expand Up @@ -2415,7 +2415,7 @@ std::string cata::string_formatter::raw_string_format( const char *format, ... )

va_list args_copy;
va_copy( args_copy, args );
const int result = vsnprintf( &buffer[0], buffer_size, format, args_copy );
const int result = vsnprintf( buffer.data(), buffer_size, format, args_copy );
va_end( args_copy );

// No error, and the buffer is big enough; we're done.
Expand All @@ -2435,7 +2435,7 @@ std::string cata::string_formatter::raw_string_format( const char *format, ... )
}

va_end( args );
return std::string( &buffer[0] );
return std::string( buffer.data() );
#endif
}
#endif
Expand Down
3 changes: 1 addition & 2 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#ifndef CATA_SRC_OUTPUT_H
#define CATA_SRC_OUTPUT_H

#include <functional>
#include <clocale>
#include <algorithm>
#include <clocale>
#include <cstddef>
#include <cstdint>
#include <forward_list>
Expand Down
1 change: 0 additions & 1 deletion src/overmap_ui.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "overmap_ui.h"

#include <functional>
#include <algorithm>
#include <array>
#include <chrono>
Expand Down
1 change: 0 additions & 1 deletion src/rng.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#ifndef CATA_SRC_RNG_H
#define CATA_SRC_RNG_H

#include <functional>
#include <array>
#include <cstddef>
#include <functional>
Expand Down
4 changes: 2 additions & 2 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2961,8 +2961,8 @@ void item::io( Archive &archive )
archive.io( "item_vars", item_vars, io::empty_default_tag() );
// TODO: change default to empty string
archive.io( "name", corpse_name, std::string() );
archive.io( "owner", owner, owner.NULL_ID() );
archive.io( "old_owner", old_owner, old_owner.NULL_ID() );
archive.io( "owner", owner, faction_id::NULL_ID() );
archive.io( "old_owner", old_owner, faction_id::NULL_ID() );
archive.io( "invlet", invlet, '\0' );
archive.io( "damaged", damage_, 0 );
archive.io( "degradation", degradation_, 0 );
Expand Down
4 changes: 1 addition & 3 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "catacharset.h"
#include "color.h"
#include "color_loader.h"
#include "cuboid_rectangle.h"
#include "cursesport.h"
#include "debug.h"
#include "filesystem.h"
Expand All @@ -65,7 +64,6 @@
#include "overmap_ui.h"
#include "overmapbuffer.h"
#include "path_info.h"
#include "point.h"
#include "sdl_geometry.h"
#include "sdl_wrappers.h"
#include "sdl_font.h"
Expand Down Expand Up @@ -771,7 +769,7 @@ std::string cata_tiles::get_omt_id_rotation_and_subtile(
oter_id ot_id = oter_at( omp );
const oter_t &ot = *ot_id;
oter_type_id ot_type_id = ot.get_type_id();
oter_type_t ot_type = *ot_type_id;
const oter_type_t &ot_type = *ot_type_id;

if( ot_type.has_connections() ) {
// This would be for connected terrain
Expand Down
2 changes: 1 addition & 1 deletion src/translation_plural_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Token TranslationPluralRulesEvaluator::GetNextToken( const char *&p )
std::vector<Token> TranslationPluralRulesEvaluator::Lexer( const std::string &expr )
{
std::vector<ExprToken> tokens;
const char *p = &expr[0];
const char *p = expr.data();
ExprToken token;
while( ( token = GetNextToken( p ) ).type != ExprTokenType::Termination ) {
tokens.emplace_back( token );
Expand Down

0 comments on commit 1df1844

Please sign in to comment.