fix for warnings about signed/unsigned comparison

This commit is contained in:
Andrew Meadows 2014-03-04 11:07:15 -08:00
parent c8149f95a3
commit 1b2db1f7ab
4 changed files with 15 additions and 15 deletions

View file

@ -50,7 +50,7 @@ void JurisdictionMap::copyContents(unsigned char* rootCodeIn, const std::vector<
unsigned char* rootCode; unsigned char* rootCode;
std::vector<unsigned char*> endNodes; std::vector<unsigned char*> endNodes;
if (rootCodeIn) { if (rootCodeIn) {
int bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(rootCodeIn)); size_t bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(rootCodeIn));
rootCode = new unsigned char[bytes]; rootCode = new unsigned char[bytes];
memcpy(rootCode, rootCodeIn, bytes); memcpy(rootCode, rootCodeIn, bytes);
} else { } else {
@ -60,7 +60,7 @@ void JurisdictionMap::copyContents(unsigned char* rootCodeIn, const std::vector<
for (size_t i = 0; i < endNodesIn.size(); i++) { for (size_t i = 0; i < endNodesIn.size(); i++) {
if (endNodesIn[i]) { if (endNodesIn[i]) {
int bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(endNodesIn[i])); size_t bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(endNodesIn[i]));
unsigned char* endNodeCode = new unsigned char[bytes]; unsigned char* endNodeCode = new unsigned char[bytes];
memcpy(endNodeCode, endNodesIn[i], bytes); memcpy(endNodeCode, endNodesIn[i], bytes);
endNodes.push_back(endNodeCode); endNodes.push_back(endNodeCode);
@ -133,7 +133,7 @@ void myDebugPrintOctalCode(const unsigned char* octalCode, bool withNewLine) {
if (!octalCode) { if (!octalCode) {
printf("NULL"); printf("NULL");
} else { } else {
for (int i = 0; i < bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(octalCode)); i++) { for (size_t i = 0; i < bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(octalCode)); i++) {
myDebugoutputBits(octalCode[i],false); myDebugoutputBits(octalCode[i],false);
} }
} }
@ -293,7 +293,7 @@ int JurisdictionMap::packIntoMessage(unsigned char* destinationBuffer, int avail
// add the root jurisdiction // add the root jurisdiction
if (_rootOctalCode) { if (_rootOctalCode) {
int bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(_rootOctalCode)); size_t bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(_rootOctalCode));
memcpy(destinationBuffer, &bytes, sizeof(bytes)); memcpy(destinationBuffer, &bytes, sizeof(bytes));
destinationBuffer += sizeof(bytes); destinationBuffer += sizeof(bytes);
memcpy(destinationBuffer, _rootOctalCode, bytes); memcpy(destinationBuffer, _rootOctalCode, bytes);
@ -306,7 +306,7 @@ int JurisdictionMap::packIntoMessage(unsigned char* destinationBuffer, int avail
for (int i=0; i < endNodeCount; i++) { for (int i=0; i < endNodeCount; i++) {
unsigned char* endNodeCode = _endNodes[i]; unsigned char* endNodeCode = _endNodes[i];
int bytes = 0; size_t bytes = 0;
if (endNodeCode) { if (endNodeCode) {
bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(endNodeCode)); bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(endNodeCode));
} }

View file

@ -44,7 +44,7 @@ void OctreeElement::init(unsigned char * octalCode) {
_voxelNodeLeafCount++; // all nodes start as leaf nodes _voxelNodeLeafCount++; // all nodes start as leaf nodes
int octalCodeLength = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(octalCode)); size_t octalCodeLength = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(octalCode));
if (octalCodeLength > sizeof(_octalCode)) { if (octalCodeLength > sizeof(_octalCode)) {
_octalCode.pointer = octalCode; _octalCode.pointer = octalCode;
_octcodePointer = true; _octcodePointer = true;

View file

@ -35,7 +35,7 @@ void printOctalCode(const unsigned char* octalCode) {
qDebug("NULL"); qDebug("NULL");
} else { } else {
QDebug continuedDebug = qDebug().nospace(); QDebug continuedDebug = qDebug().nospace();
for (int i = 0; i < bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(octalCode)); i++) { for (size_t i = 0; i < bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(octalCode)); i++) {
outputBits(octalCode[i], &continuedDebug); outputBits(octalCode[i], &continuedDebug);
} }
} }
@ -51,11 +51,11 @@ char sectionValue(const unsigned char* startByte, char startIndexInByte) {
} }
} }
int bytesRequiredForCodeLength(unsigned char threeBitCodes) { size_t bytesRequiredForCodeLength(unsigned char threeBitCodes) {
if (threeBitCodes == 0) { if (threeBitCodes == 0) {
return 1; return 1;
} else { } else {
return 1 + (int)ceilf((threeBitCodes * 3) / 8.0f); return 1 + ceilf((threeBitCodes * 3) / 8.0f);
} }
} }
@ -78,10 +78,10 @@ unsigned char* childOctalCode(const unsigned char* parentOctalCode, char childNu
: 0; : 0;
// get the number of bytes used by the parent octal code // get the number of bytes used by the parent octal code
int parentCodeBytes = bytesRequiredForCodeLength(parentCodeSections); size_t parentCodeBytes = bytesRequiredForCodeLength(parentCodeSections);
// child code will have one more section than the parent // child code will have one more section than the parent
int childCodeBytes = bytesRequiredForCodeLength(parentCodeSections + 1); size_t childCodeBytes = bytesRequiredForCodeLength(parentCodeSections + 1);
// create a new buffer to hold the new octal code // create a new buffer to hold the new octal code
unsigned char* newCode = new unsigned char[childCodeBytes]; unsigned char* newCode = new unsigned char[childCodeBytes];
@ -175,8 +175,8 @@ OctalCodeComparison compareOctalCodes(const unsigned char* codeA, const unsigned
OctalCodeComparison result = LESS_THAN; // assume it's shallower OctalCodeComparison result = LESS_THAN; // assume it's shallower
int numberOfBytes = std::min(bytesRequiredForCodeLength(*codeA), bytesRequiredForCodeLength(*codeB)); size_t numberOfBytes = std::min(bytesRequiredForCodeLength(*codeA), bytesRequiredForCodeLength(*codeB));
int compare = memcmp(codeA, codeB, numberOfBytes); size_t compare = memcmp(codeA, codeB, numberOfBytes);
if (compare < 0) { if (compare < 0) {
result = LESS_THAN; result = LESS_THAN;
@ -367,7 +367,7 @@ QString octalCodeToHexString(const unsigned char* octalCode) {
if (!octalCode) { if (!octalCode) {
output = "00"; output = "00";
} else { } else {
for (int i = 0; i < bytesRequiredForCodeLength(*octalCode); i++) { for (size_t i = 0; i < bytesRequiredForCodeLength(*octalCode); i++) {
output.append(QString("%1").arg(octalCode[i], HEX_BYTE_SIZE, HEX_NUMBER_BASE, QChar('0')).toUpper()); output.append(QString("%1").arg(octalCode[i], HEX_BYTE_SIZE, HEX_NUMBER_BASE, QChar('0')).toUpper());
} }
} }

View file

@ -20,7 +20,7 @@ const int GREEN_INDEX = 1;
const int BLUE_INDEX = 2; const int BLUE_INDEX = 2;
void printOctalCode(const unsigned char* octalCode); void printOctalCode(const unsigned char* octalCode);
int bytesRequiredForCodeLength(unsigned char threeBitCodes); size_t bytesRequiredForCodeLength(unsigned char threeBitCodes);
int branchIndexWithDescendant(const unsigned char* ancestorOctalCode, const unsigned char* descendantOctalCode); int branchIndexWithDescendant(const unsigned char* ancestorOctalCode, const unsigned char* descendantOctalCode);
unsigned char* childOctalCode(const unsigned char* parentOctalCode, char childNumber); unsigned char* childOctalCode(const unsigned char* parentOctalCode, char childNumber);