Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 18, 2009, 4:03:59 PM (15 years ago)
Author:
rgrieder
Message:

Found even more casts. They sure aren't all of them, but I hope to have caught every pointer C-style cast because they can be very dangerous.
Note: I didn't do the pointer casts in the network library because that would have taken way too long.

Location:
code/trunk/src/network
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/ClientInformation.cc

    r3214 r3301  
    166166
    167167  double ClientInformation::getPacketLoss(){
    168     return ((double)this->peer_->packetLoss)/ENET_PEER_PACKET_LOSS_SCALE;
     168    return static_cast<double>(this->peer_->packetLoss)/ENET_PEER_PACKET_LOSS_SCALE;
    169169  }
    170170
     
    173173      return gamestateID_;
    174174    else
    175       return (unsigned int)-1;
     175      return static_cast<unsigned int>(-1);
    176176  }
    177177
     
    180180      return partialGamestateID_;
    181181    else
    182       return (unsigned int)-1;
     182      return static_cast<unsigned int>(-1);
    183183  }
    184184
     
    197197
    198198  bool ClientInformation::removeClient(unsigned int clientID) {
    199     if((unsigned int)clientID==CLIENTID_UNKNOWN)
     199    if(clientID==CLIENTID_UNKNOWN)
    200200      return false;
    201201    ClientInformation *temp = head_;
  • code/trunk/src/network/GamestateClient.h

    r3214 r3301  
    4747#include "GamestateHandler.h"
    4848
    49 const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
     49const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1);
    5050
    5151namespace orxonox
  • code/trunk/src/network/GamestateManager.cc

    r3214 r3301  
    174174    }
    175175
    176     assert(curid==(unsigned int)GAMESTATEID_INITIAL || curid<gamestateID);
     176    assert(curid==GAMESTATEID_INITIAL || curid<gamestateID);
    177177    COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
    178178    std::map<unsigned int, packet::Gamestate*>::iterator it;
  • code/trunk/src/network/NetworkPrereqs.h

    r3280 r3301  
    6161namespace orxonox
    6262{
    63   static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
    64   static const unsigned int CLIENTID_UNKNOWN    = (unsigned int)-2;
    65   static const uint32_t     OBJECTID_UNKNOWN    = (uint32_t)(-1);
     63  static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1);
     64  static const unsigned int CLIENTID_UNKNOWN    = static_cast<unsigned int>(-2);
     65  static const uint32_t     OBJECTID_UNKNOWN    = static_cast<uint32_t>(-1);
    6666}
    6767
  • code/trunk/src/network/TrafficControl.cc

    r3214 r3301  
    3838namespace orxonox {
    3939
    40   static const unsigned int SCHED_PRIORITY_OFFSET = (unsigned int)-1;
     40  static const unsigned int SCHED_PRIORITY_OFFSET = static_cast<unsigned int>(-1);
    4141
    4242  objInfo::objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched)
  • code/trunk/src/network/packet/Chat.cc

    r3280 r3301  
    5151  *(unsigned int *)(data_ + _PLAYERID ) = playerID;
    5252  *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_;
    53   memcpy( data_+_MESSAGE, (void *)message.c_str(), messageLength_ );
     53  memcpy( data_+_MESSAGE, static_cast<void*>(const_cast<char*>(message.c_str())), messageLength_ );
    5454}
    5555
  • code/trunk/src/network/packet/Packet.cc

    r3280 r3301  
    143143      // Assures we don't create a packet and destroy it right after in another thread
    144144      // without having a reference in the packetMap_
    145       packetMap_[(size_t)(void*)enetPacket_] = this;
     145      packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;
    146146    }
    147147  }
     
    172172Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){
    173173  uint8_t *data = packet->data;
    174   assert(ClientInformation::findClient(&peer->address)->getID() != (unsigned int)-2 || !Host::isServer());
     174  assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
    175175  unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
    176176  Packet *p = 0;
     
    230230void Packet::deletePacket(ENetPacket *enetPacket){
    231231  // Get our Packet from a gloabal map with all Packets created in the send() method of Packet.
    232   std::map<size_t, Packet*>::iterator it = packetMap_.find((size_t)enetPacket);
     232  std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket));
    233233  assert(it != packetMap_.end());
    234234  // Make sure we don't delete it again in the destructor
  • code/trunk/src/network/synchronisable/Synchronisable.h

    r3280 r3301  
    4444
    4545/*#define REGISTERDATA(varname, ...) \
    46     registerVariable((void*)&varname, sizeof(varname), DATA, __VA_ARGS__)
     46    registerVariable(static_cast<void*>(&varname), sizeof(varname), DATA, __VA_ARGS__)
    4747#define REGISTERSTRING(stringname, ...) \
    4848    registerVariable(&stringname, stringname.length()+1, STRING, __VA_ARGS__)*/
  • code/trunk/src/network/synchronisable/SynchronisableVariable.h

    r3280 r3301  
    3636#include <cstring>
    3737#include "util/Serialise.h"
     38#include "util/TemplateUtils.h"
    3839#include "core/GameMode.h"
    3940#include "network/synchronisable/NetworkCallbackManager.h"
     
    7879      virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false);
    7980      virtual inline uint32_t getSize(uint8_t mode);
    80       virtual inline void* getReference(){ return (void *)&this->variable_; }
     81      virtual inline void* getReference(){ return static_cast<void*>(const_cast<typename TypeStripper<T>::RawType*>(&this->variable_)); }
    8182    protected:
    8283     
     
    178179        {
    179180          this->varReference_++;
    180           memcpy((void*)&this->varBuffer_, &this->variable_, sizeof(this->variable_));
     181          memcpy(static_cast<void*>(const_cast<typename TypeStripper<T>::RawType*>(&this->varBuffer_)), &this->variable_, sizeof(this->variable_));
    181182        }
    182183      }
     
    211212          {
    212213            mem += sizeof(varReference_);
    213             memcpy((void*)&this->varBuffer_, &this->variable_, sizeof(T));
     214            memcpy(static_cast<void*>(const_cast<typename TypeStripper<T>::RawType*>(&this->varBuffer_)), &this->variable_, sizeof(T));
    214215            if ( this->callback_ != 0 )
    215216              callback = true;
Note: See TracChangeset for help on using the changeset viewer.