Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 21, 2016, 1:59:04 PM (9 years ago)
Author:
muemart
Message:

Fix some clang-tidy warnings.
Also, Serialise.h was doing some C-style casts that ended up being const casts. I moved those const casts as close to the source as possible and changed the loadAndIncrease functions to not do that.

Location:
code/trunk/src/libraries
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/GUIManager.cc

    r11071 r11083  
    104104#include "util/OrxAssert.h"
    105105#include "util/output/BaseWriter.h"
     106#include "util/StringUtils.h"
     107#include "util/SubString.h"
    106108#include "config/ConfigValueIncludes.h"
    107109#include "Core.h"
  • code/trunk/src/libraries/core/class/SubclassIdentifier.h

    r11071 r11083  
    9292        public:
    9393            /// Constructor: Automaticaly assigns the Identifier of the given class.
    94             SubclassIdentifier()
     94            SubclassIdentifier() : identifier_(nullptr)
    9595            {
    9696                this->identifier_ = ClassIdentifier<T>::getIdentifier();
     
    9898
    9999            /// Constructor: Assigns the given Identifier.
    100             SubclassIdentifier(Identifier* identifier)
     100            SubclassIdentifier(Identifier* identifier) : identifier_(nullptr)
    101101            {
    102102                this->operator=(identifier);
     
    105105            /// Copyconstructor: Assigns the identifier of another SubclassIdentifier.
    106106            template <class O>
    107             SubclassIdentifier(const SubclassIdentifier<O>& identifier)
     107            SubclassIdentifier(const SubclassIdentifier<O>& identifier) : identifier_(nullptr)
    108108            {
    109109                this->operator=(identifier.getIdentifier());
  • code/trunk/src/libraries/core/input/KeyBinder.cc

    r11071 r11083  
    6767        for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
    6868        {
    69             const std::string& keyname = KeyCode::ByString[i];
     69            const std::string keyname = KeyCode::ByString[i];
    7070            if (!keyname.empty())
    7171                keys_[i].name_ = std::string("Key") + keyname;
  • code/trunk/src/libraries/network/MasterServer.cc

    r11071 r11083  
    253253    /* convert to string */
    254254    std::string ip = std::string( addrconv );
     255    /* output debug info about the data that has come */
     256    helper_output_debug(event, addrconv);
    255257    /* delete addrconv */
    256258    if( addrconv ) free( addrconv );
     
    259261    char * packetdata = (char *)event->packet->data;
    260262
    261     /* output debug info about the data that has come */
    262     helper_output_debug( event, addrconv );
    263263
    264264    /* GAME SERVER OR CLIENT CONNECTION? */
     
    332332  {
    333333    /***** ENTER MAIN LOOP *****/
    334     ENetEvent *event = (ENetEvent *)calloc(sizeof(ENetEvent), sizeof(char));
     334    ENetEvent *event = (ENetEvent *)calloc(1, sizeof(ENetEvent));
    335335    if( event == nullptr )
    336336    {
  • code/trunk/src/libraries/network/packet/Gamestate.cc

    r11071 r11083  
    489489Gamestate* Gamestate::diffVariables(Gamestate *base)
    490490{
    491   assert(this && base); assert(data_ && base->data_);
     491  assert(base); assert(data_ && base->data_);
    492492  assert(!header_.isCompressed() && !base->header_.isCompressed());
    493493  assert(!header_.isDiffed());
  • code/trunk/src/libraries/network/packet/ServerInformation.cc

    r11071 r11083  
    5555      // Save ACK
    5656      uint8_t* temp = event->packet->data;
    57       char* ack = new char[strlen(LAN_DISCOVERY_ACK)+1];
     57      char* ack = nullptr;
    5858      loadAndIncrease((char*&)ack, temp);
    5959
     
    6464      // Save Server Name
    6565      loadAndIncrease(this->serverName_, temp);
     66      delete[] ack;
    6667    }
    6768
     
    7475    {
    7576      std::string payload = this->serverName_ + Ogre::StringConverter::toString(this->clientNumber_);
    76       uint32_t size = returnSize((char*&)LAN_DISCOVERY_ACK) + returnSize(payload);
     77      uint32_t size = returnSize(LAN_DISCOVERY_ACK) + returnSize(payload);
    7778      uint8_t* temp = new uint8_t[size];
    7879      uint8_t* temp2 = temp;
    79       saveAndIncrease((char*&)LAN_DISCOVERY_ACK, temp2);
     80      saveAndIncrease(LAN_DISCOVERY_ACK, temp2);
    8081      saveAndIncrease(payload, temp2);
    8182      ENetPacket* packet = enet_packet_create( temp, size, 0 );
  • code/trunk/src/libraries/util/Serialise.h

    r11071 r11083  
    4848    template <class T> inline uint32_t returnSize( const T& variable );
    4949    /** @brief loads the value of a variable out of the bytestream and increases the mem pointer */
    50     template <class T> inline void loadAndIncrease( const T& variable, uint8_t*& mem );
     50    template <class T> inline void loadAndIncrease( T& variable, uint8_t*& mem );
    5151    /** @brief saves the value of a variable into the bytestream and increases the mem pointer */
    5252    template <class T> inline void saveAndIncrease( const T& variable, uint8_t*& mem );
     
    5757  // =========== char*
    5858
    59   inline uint32_t returnSize( char*& variable )
     59  inline uint32_t returnSize(const char*& variable )
    6060  {
    6161    return strlen(variable)+1;
    6262  }
    6363
    64   inline void saveAndIncrease( char*& variable, uint8_t*& mem )
     64  inline void saveAndIncrease(const char*& variable, uint8_t*& mem )
    6565  {
    66     strcpy((char*)mem, variable);
    67     mem += returnSize(variable);
     66    uint32_t len = returnSize(variable);
     67    std::memcpy(mem, variable, len);
     68    mem += len;
    6869  }
    6970
     
    7273    if( variable )
    7374      delete variable;
    74     uint32_t len = strlen((char*)mem)+1;
     75    uint32_t len = returnSize((const char*&)mem);
    7576    variable = new char[len];
    76     strcpy((char*)variable, (char*)mem);
     77    std::memcpy(variable, mem, len);
    7778    mem += len;
    7879  }
     
    9293    }
    9394
    94     template <> inline void loadAndIncrease( const bool& variable, uint8_t*& mem )
     95    template <> inline void loadAndIncrease( bool& variable, uint8_t*& mem )
    9596    {
    9697        *(uint8_t*)( &variable ) = *static_cast<uint8_t*>(mem);
     
    116117    }
    117118
    118     template <> inline void loadAndIncrease( const char& variable, uint8_t*& mem )
     119    template <> inline void loadAndIncrease( char& variable, uint8_t*& mem )
    119120    {
    120121        *(uint8_t*)( &variable ) = *static_cast<uint8_t*>(mem);
     
    140141    }
    141142
    142     template <> inline void loadAndIncrease( const unsigned char& variable, uint8_t*& mem )
     143    template <> inline void loadAndIncrease( unsigned char& variable, uint8_t*& mem )
    143144    {
    144145        *(uint8_t*)( &variable ) = *static_cast<uint8_t*>(mem);
     
    164165    }
    165166
    166     template <> inline void loadAndIncrease( const short& variable, uint8_t*& mem )
     167    template <> inline void loadAndIncrease( short& variable, uint8_t*& mem )
    167168    {
    168169        *(short*)( &variable ) = *(int16_t*)(mem);
     
    188189    }
    189190
    190     template <> inline void loadAndIncrease( const unsigned short& variable, uint8_t*& mem )
     191    template <> inline void loadAndIncrease( unsigned short& variable, uint8_t*& mem )
    191192    {
    192193        *(unsigned short*)( &variable ) = *(uint16_t*)(mem);
     
    212213    }
    213214
    214     template <> inline void loadAndIncrease( const int& variable, uint8_t*& mem )
     215    template <> inline void loadAndIncrease( int& variable, uint8_t*& mem )
    215216    {
    216217        *(int *)( &variable ) = *(int32_t*)(mem);
     
    236237    }
    237238
    238     template <> inline void loadAndIncrease( const unsigned int& variable, uint8_t*& mem )
     239    template <> inline void loadAndIncrease( unsigned int& variable, uint8_t*& mem )
    239240    {
    240241        *(unsigned int*)( &variable ) = *(uint32_t*)(mem);
     
    260261    }
    261262
    262     template <> inline void loadAndIncrease( const long& variable, uint8_t*& mem )
     263    template <> inline void loadAndIncrease( long& variable, uint8_t*& mem )
    263264    {
    264265        *(long*)( &variable ) = *(int32_t*)(mem);
     
    284285    }
    285286
    286     template <> inline void loadAndIncrease( const unsigned long& variable, uint8_t*& mem )
     287    template <> inline void loadAndIncrease( unsigned long& variable, uint8_t*& mem )
    287288    {
    288289        *(unsigned long*)( &variable ) = *(uint32_t*)(mem);
     
    308309    }
    309310
    310     template <> inline void loadAndIncrease( const long long& variable, uint8_t*& mem )
     311    template <> inline void loadAndIncrease( long long& variable, uint8_t*& mem )
    311312    {
    312313        *(long long*)( &variable ) = *(int64_t*)(mem);
     
    332333    }
    333334
    334     template <> inline void loadAndIncrease( const unsigned long long& variable, uint8_t*& mem )
     335    template <> inline void loadAndIncrease( unsigned long long& variable, uint8_t*& mem )
    335336    {
    336337        *(unsigned long long*)( &variable ) = *(uint64_t*)(mem);
     
    356357    }
    357358
    358     template <> inline void loadAndIncrease( const float& variable, uint8_t*& mem )
     359    template <> inline void loadAndIncrease( float& variable, uint8_t*& mem )
    359360    {
    360361        *(uint32_t*)( &variable ) = *(uint32_t*)(mem);
     
    380381    }
    381382
    382     template <> inline void loadAndIncrease( const double& variable, uint8_t*& mem )
     383    template <> inline void loadAndIncrease( double& variable, uint8_t*& mem )
    383384    {
    384385        *(uint64_t*)( &variable ) = *(uint64_t*)(mem);
     
    404405    }
    405406
    406     template <> inline void loadAndIncrease( const long double& variable, uint8_t*& mem )
     407    template <> inline void loadAndIncrease( long double& variable, uint8_t*& mem )
    407408    {
    408409        double temp;
     
    438439    }
    439440
    440     template <> inline void loadAndIncrease( const std::string& variable, uint8_t*& mem )
     441    template <> inline void loadAndIncrease( std::string& variable, uint8_t*& mem )
    441442    {
    442443        *(std::string*)( &variable ) = (const char *)mem;
     
    464465    }
    465466
    466     template <> inline void loadAndIncrease( const Degree& variable, uint8_t*& mem )
     467    template <> inline void loadAndIncrease( Degree& variable, uint8_t*& mem )
    467468    {
    468469        Ogre::Real* r = (Ogre::Real*)mem;
     
    491492    }
    492493
    493     template <> inline void loadAndIncrease( const Radian& variable, uint8_t*& mem )
     494    template <> inline void loadAndIncrease( Radian& variable, uint8_t*& mem )
    494495    {
    495496        Ogre::Real* r = (Ogre::Real*)mem;
     
    517518    }
    518519
    519     template <> inline void loadAndIncrease( const Vector2& variable, uint8_t*& mem )
     520    template <> inline void loadAndIncrease( Vector2& variable, uint8_t*& mem )
    520521    {
    521522        loadAndIncrease( variable.x, mem );
     
    542543    }
    543544
    544     template <> inline void loadAndIncrease( const Vector3& variable, uint8_t*& mem )
     545    template <> inline void loadAndIncrease( Vector3& variable, uint8_t*& mem )
    545546    {
    546547        loadAndIncrease( variable.x, mem );
     
    570571    }
    571572
    572     template <> inline void loadAndIncrease( const Vector4& variable, uint8_t*& mem )
     573    template <> inline void loadAndIncrease( Vector4& variable, uint8_t*& mem )
    573574    {
    574575        loadAndIncrease( variable.w, mem );
     
    600601    }
    601602
    602     template <> inline void loadAndIncrease( const Quaternion& variable, uint8_t*& mem )
     603    template <> inline void loadAndIncrease( Quaternion& variable, uint8_t*& mem )
    603604    {
    604605        loadAndIncrease( variable.w, mem );
     
    630631    }
    631632
    632     template <> inline void loadAndIncrease( const ColourValue& variable, uint8_t*& mem )
     633    template <> inline void loadAndIncrease( ColourValue& variable, uint8_t*& mem )
    633634    {
    634635        loadAndIncrease( variable.r, mem );
     
    657658    }
    658659
    659     template <> inline void loadAndIncrease( const mbool& variable, uint8_t*& mem )
     660    template <> inline void loadAndIncrease( mbool& variable, uint8_t*& mem )
    660661    {
    661662        loadAndIncrease( (unsigned char&)((mbool&)variable).getMemory(), mem );
Note: See TracChangeset for help on using the changeset viewer.