mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
correct assignment packing when there is no pool
This commit is contained in:
parent
fa7f183930
commit
6e736ff9ed
1 changed files with 20 additions and 5 deletions
|
@ -11,6 +11,7 @@
|
|||
Assignment::Assignment(Assignment::Direction direction, Assignment::Type type, const char* pool) :
|
||||
_direction(direction),
|
||||
_type(type),
|
||||
_pool(NULL),
|
||||
_domainSocket(NULL)
|
||||
{
|
||||
// copy the pool, if we got one
|
||||
|
@ -24,6 +25,7 @@ Assignment::Assignment(Assignment::Direction direction, Assignment::Type type, c
|
|||
}
|
||||
|
||||
Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
|
||||
_pool(NULL),
|
||||
_domainSocket(NULL)
|
||||
{
|
||||
int numBytesRead = 0;
|
||||
|
@ -35,9 +37,15 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
|
|||
numBytesRead += sizeof(Assignment::Type);
|
||||
|
||||
int poolLength = strlen((const char*) dataBuffer + numBytesRead);
|
||||
_pool = new char[poolLength + sizeof(char)];
|
||||
strcpy(_pool, (char*) dataBuffer + numBytesRead);
|
||||
numBytesRead += poolLength + sizeof(char);
|
||||
|
||||
if (poolLength) {
|
||||
_pool = new char[poolLength + sizeof(char)];
|
||||
strcpy(_pool, (char*) dataBuffer + numBytesRead);
|
||||
numBytesRead += poolLength + sizeof(char);
|
||||
} else {
|
||||
numBytesRead += sizeof(char);
|
||||
}
|
||||
|
||||
|
||||
if (numBytes > numBytesRead) {
|
||||
memcpy(_domainSocket, dataBuffer + numBytesRead, sizeof(sockaddr));
|
||||
|
@ -53,8 +61,15 @@ int Assignment::packToBuffer(unsigned char* buffer) {
|
|||
memcpy(buffer + numPackedBytes, &_type, sizeof(_type));
|
||||
numPackedBytes += sizeof(_type);
|
||||
|
||||
strcpy((char*) buffer + numPackedBytes, _pool);
|
||||
numPackedBytes += strlen(_pool) + sizeof(char);
|
||||
if (_pool) {
|
||||
int poolLength = strlen(_pool);
|
||||
strcpy((char*) buffer + numPackedBytes, _pool);
|
||||
|
||||
numPackedBytes += poolLength + sizeof(char);
|
||||
} else {
|
||||
buffer[numPackedBytes] = '\0';
|
||||
numPackedBytes += sizeof(char);
|
||||
}
|
||||
|
||||
if (_domainSocket) {
|
||||
memcpy(buffer + numPackedBytes, _domainSocket, sizeof(sockaddr));
|
||||
|
|
Loading…
Reference in a new issue