mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:17:02 +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) :
|
Assignment::Assignment(Assignment::Direction direction, Assignment::Type type, const char* pool) :
|
||||||
_direction(direction),
|
_direction(direction),
|
||||||
_type(type),
|
_type(type),
|
||||||
|
_pool(NULL),
|
||||||
_domainSocket(NULL)
|
_domainSocket(NULL)
|
||||||
{
|
{
|
||||||
// copy the pool, if we got one
|
// 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) :
|
Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
|
||||||
|
_pool(NULL),
|
||||||
_domainSocket(NULL)
|
_domainSocket(NULL)
|
||||||
{
|
{
|
||||||
int numBytesRead = 0;
|
int numBytesRead = 0;
|
||||||
|
@ -35,9 +37,15 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
|
||||||
numBytesRead += sizeof(Assignment::Type);
|
numBytesRead += sizeof(Assignment::Type);
|
||||||
|
|
||||||
int poolLength = strlen((const char*) dataBuffer + numBytesRead);
|
int poolLength = strlen((const char*) dataBuffer + numBytesRead);
|
||||||
_pool = new char[poolLength + sizeof(char)];
|
|
||||||
strcpy(_pool, (char*) dataBuffer + numBytesRead);
|
if (poolLength) {
|
||||||
numBytesRead += poolLength + sizeof(char);
|
_pool = new char[poolLength + sizeof(char)];
|
||||||
|
strcpy(_pool, (char*) dataBuffer + numBytesRead);
|
||||||
|
numBytesRead += poolLength + sizeof(char);
|
||||||
|
} else {
|
||||||
|
numBytesRead += sizeof(char);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (numBytes > numBytesRead) {
|
if (numBytes > numBytesRead) {
|
||||||
memcpy(_domainSocket, dataBuffer + numBytesRead, sizeof(sockaddr));
|
memcpy(_domainSocket, dataBuffer + numBytesRead, sizeof(sockaddr));
|
||||||
|
@ -53,8 +61,15 @@ int Assignment::packToBuffer(unsigned char* buffer) {
|
||||||
memcpy(buffer + numPackedBytes, &_type, sizeof(_type));
|
memcpy(buffer + numPackedBytes, &_type, sizeof(_type));
|
||||||
numPackedBytes += sizeof(_type);
|
numPackedBytes += sizeof(_type);
|
||||||
|
|
||||||
strcpy((char*) buffer + numPackedBytes, _pool);
|
if (_pool) {
|
||||||
numPackedBytes += strlen(_pool) + sizeof(char);
|
int poolLength = strlen(_pool);
|
||||||
|
strcpy((char*) buffer + numPackedBytes, _pool);
|
||||||
|
|
||||||
|
numPackedBytes += poolLength + sizeof(char);
|
||||||
|
} else {
|
||||||
|
buffer[numPackedBytes] = '\0';
|
||||||
|
numPackedBytes += sizeof(char);
|
||||||
|
}
|
||||||
|
|
||||||
if (_domainSocket) {
|
if (_domainSocket) {
|
||||||
memcpy(buffer + numPackedBytes, _domainSocket, sizeof(sockaddr));
|
memcpy(buffer + numPackedBytes, _domainSocket, sizeof(sockaddr));
|
||||||
|
|
Loading…
Reference in a new issue