mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 05:52:38 +02:00
correct copying of assignment pool across targets
This commit is contained in:
parent
ebc7de3a90
commit
36c2f42b5c
6 changed files with 13 additions and 13 deletions
|
@ -39,7 +39,7 @@ int main(int argc, char* const argv[]) {
|
|||
// copy the passed assignment pool
|
||||
int poolLength = strlen(optarg);
|
||||
assignmentPool = new char[poolLength + sizeof(char)];
|
||||
memcpy(assignmentPool, optarg, poolLength + sizeof(char));
|
||||
strcpy(assignmentPool, optarg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ int main(int argc, const char* argv[]) {
|
|||
}
|
||||
} else if (senderData[0] == PACKET_TYPE_CREATE_ASSIGNMENT && packetVersionMatch(senderData)) {
|
||||
// memcpy the sent assignment
|
||||
Assignment createdAssignment(senderData + numBytesForPacketHeader(PACKET_TYPE_CREATE_ASSIGNMENT));
|
||||
Assignment createdAssignment(senderData + numBytesForPacketHeader(senderData));
|
||||
|
||||
qDebug() << "Received an assignment:" << createdAssignment;
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ int main(int argc, char* const argv[])
|
|||
|
||||
// loop the parameters to see if we were passed a pool for assignment
|
||||
int parameter = -1;
|
||||
const char ALLOWED_PARAMETERS[] = "p::";
|
||||
const char ALLOWED_PARAMETERS[] = "p::-local::";
|
||||
const char POOL_PARAMETER_CHAR = 'p';
|
||||
|
||||
char* assignmentPool = NULL;
|
||||
|
@ -97,7 +97,7 @@ int main(int argc, char* const argv[])
|
|||
// copy the passed assignment pool
|
||||
int poolLength = strlen(optarg);
|
||||
assignmentPool = new char[poolLength + sizeof(char)];
|
||||
memcpy(assignmentPool, optarg, poolLength + sizeof(char));
|
||||
strcpy(assignmentPool, optarg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ Assignment::Assignment(Assignment::Direction direction, Assignment::Type type, c
|
|||
|
||||
// create the char array and make it large enough for string and null termination
|
||||
_pool = new char[poolLength + sizeof(char)];
|
||||
memcpy(_pool, pool, poolLength + 1);
|
||||
strcpy(_pool, pool);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,25 +33,25 @@ Assignment::Assignment(const unsigned char* dataBuffer) {
|
|||
|
||||
int poolLength = strlen((const char*) dataBuffer + numBytesRead);
|
||||
_pool = new char[poolLength + sizeof(char)];
|
||||
memcpy(_pool, dataBuffer + numBytesRead, poolLength + sizeof(char));
|
||||
strcpy(_pool, (char*) dataBuffer + numBytesRead);
|
||||
}
|
||||
|
||||
int Assignment::packAssignmentToBuffer(unsigned char* buffer) {
|
||||
int Assignment::packToBuffer(unsigned char* buffer) {
|
||||
int numPackedBytes = 0;
|
||||
|
||||
memcpy(buffer, &_direction, sizeof(_direction));
|
||||
numPackedBytes += sizeof(_direction);
|
||||
|
||||
memcpy(buffer, &_type, sizeof(_type));
|
||||
memcpy(buffer + numPackedBytes, &_type, sizeof(_type));
|
||||
numPackedBytes += sizeof(_type);
|
||||
|
||||
strcpy((char *)buffer, _pool);
|
||||
strcpy((char*) buffer + numPackedBytes, _pool);
|
||||
numPackedBytes += strlen(_pool) + sizeof(char);
|
||||
|
||||
return numPackedBytes;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const Assignment &assignment) {
|
||||
debug << "T:" << assignment.getType() << "P" << assignment.getPool();
|
||||
debug << "T:" << assignment.getType() << "P:" << assignment.getPool();
|
||||
return debug.nospace();
|
||||
}
|
|
@ -31,7 +31,7 @@ public:
|
|||
Assignment::Type getType() const { return _type; }
|
||||
const char* getPool() const { return _pool; }
|
||||
|
||||
int packAssignmentToBuffer(unsigned char* buffer);
|
||||
int packToBuffer(unsigned char* buffer);
|
||||
|
||||
private:
|
||||
Assignment::Direction _direction;
|
||||
|
|
|
@ -379,9 +379,9 @@ void NodeList::sendAssignment(Assignment& assignment) {
|
|||
: PACKET_TYPE_REQUEST_ASSIGNMENT;
|
||||
|
||||
int numHeaderBytes = populateTypeAndVersion(assignmentPacket, assignmentPacketType);
|
||||
*(assignmentPacket + numHeaderBytes) = assignment.getType();
|
||||
int numAssignmentBytes = assignment.packToBuffer(assignmentPacket + numHeaderBytes);
|
||||
|
||||
_nodeSocket.send((sockaddr*) &assignmentServerSocket, assignmentPacket, numHeaderBytes + sizeof(unsigned char));
|
||||
_nodeSocket.send((sockaddr*) &assignmentServerSocket, assignmentPacket, numHeaderBytes + numAssignmentBytes);
|
||||
}
|
||||
|
||||
Node* NodeList::addOrUpdateNode(sockaddr* publicSocket, sockaddr* localSocket, char nodeType, uint16_t nodeId) {
|
||||
|
|
Loading…
Reference in a new issue