diff --git a/assignment-client/src/main.cpp b/assignment-client/src/main.cpp index b1b6303525..4003d853ac 100644 --- a/assignment-client/src/main.cpp +++ b/assignment-client/src/main.cpp @@ -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); } } diff --git a/assignment-server/src/main.cpp b/assignment-server/src/main.cpp index 5330b175d2..5d074e1d18 100644 --- a/assignment-server/src/main.cpp +++ b/assignment-server/src/main.cpp @@ -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; diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 43e13636ed..ac6249a823 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -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); } } diff --git a/libraries/shared/src/Assignment.cpp b/libraries/shared/src/Assignment.cpp index 00ab2878a2..112d19b9fe 100644 --- a/libraries/shared/src/Assignment.cpp +++ b/libraries/shared/src/Assignment.cpp @@ -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(); } \ No newline at end of file diff --git a/libraries/shared/src/Assignment.h b/libraries/shared/src/Assignment.h index c85d235547..99acd6924d 100644 --- a/libraries/shared/src/Assignment.h +++ b/libraries/shared/src/Assignment.h @@ -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; diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 45e51c06d9..745ab450db 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -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) {