Skip to content

Commit

Permalink
fix issues comparing signed with unsigned vars
Browse files Browse the repository at this point in the history
  • Loading branch information
carltimmer committed Sep 20, 2024
1 parent 5ead07e commit 6f53917
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 143 deletions.
29 changes: 15 additions & 14 deletions src/libsrc++/BaseStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ namespace evio {
auto first = children.begin();
auto end = children.end();

size_t index = 0;
ssize_t index = 0;

for (; first < end; first++) {
if (aChild == *first) {
Expand Down Expand Up @@ -1049,14 +1049,15 @@ namespace evio {
throw EvioException("argument is null");
}

// index >= -1
ssize_t index = getIndex(aChild); // linear search

if (index == -1) {
throw EvioException("node is not a child");
}

if (index < getChildCount() - 1) {
return getChildAt(index + 1);
if ((size_t)index < getChildCount() - 1) {
return getChildAt((size_t)index + 1);
}
else {
return nullptr;
Expand Down Expand Up @@ -1584,7 +1585,7 @@ namespace evio {
ss << std::endl;
std::string myIndent = indent + " ";
uint32_t childCount = getChildCount();
for (int i=0; i < childCount; i++) {
for (uint32_t i=0; i < childCount; i++) {
ss << children[i]->treeToString(myIndent);
if (i < childCount - 1) {
ss << std::endl;
Expand Down Expand Up @@ -1712,7 +1713,7 @@ namespace evio {
uint32_t numInts = (rawBytes.size() - header->getPadding()) / sizeof(int16_t);
shortData.resize(numInts);

for (int i=0; i < numInts; ++i) {
for (uint32_t i=0; i < numInts; ++i) {
int16_t dat = *(pInt++);
if (needSwap()) {
dat = SWAP_16(dat);
Expand Down Expand Up @@ -1744,7 +1745,7 @@ namespace evio {
uint32_t numInts = (rawBytes.size() - header->getPadding()) / sizeof(uint16_t);
ushortData.resize(numInts);

for (int i=0; i < numInts; ++i) {
for (uint32_t i=0; i < numInts; ++i) {
int16_t dat = *(pInt++);
if (needSwap()) {
dat = SWAP_16(dat);
Expand Down Expand Up @@ -1774,7 +1775,7 @@ namespace evio {
uint32_t numInts = (rawBytes.size() - header->getPadding()) / sizeof(int32_t);
intData.resize(numInts);

for (int i=0; i < numInts; ++i) {
for (uint32_t i=0; i < numInts; ++i) {
int32_t dat = *(pInt++);
if (needSwap()) {
dat = SWAP_32(dat);
Expand Down Expand Up @@ -1804,7 +1805,7 @@ namespace evio {
uint32_t numInts = (rawBytes.size() - header->getPadding()) / sizeof(uint32_t);
uintData.resize(numInts);

for (int i=0; i < numInts; ++i) {
for (uint32_t i=0; i < numInts; ++i) {
uint32_t dat = *(pInt++);
if (needSwap()) {
dat = SWAP_32(dat);
Expand Down Expand Up @@ -1834,7 +1835,7 @@ namespace evio {
uint32_t numLongs = (rawBytes.size() - header->getPadding()) / sizeof(int64_t);
longData.resize(numLongs);

for (int i=0; i < numLongs; ++i) {
for (uint32_t i=0; i < numLongs; ++i) {
int64_t dat = *(pLong++);
if (needSwap()) {
dat = SWAP_64(dat);
Expand Down Expand Up @@ -1864,7 +1865,7 @@ namespace evio {
uint32_t numLongs = (rawBytes.size() - header->getPadding()) / sizeof(uint64_t);
ulongData.resize(numLongs);

for (int i=0; i < numLongs; ++i) {
for (uint32_t i=0; i < numLongs; ++i) {
uint64_t dat = *(pLong++);
if (needSwap()) {
dat = SWAP_64(dat);
Expand Down Expand Up @@ -1894,7 +1895,7 @@ namespace evio {
uint32_t numReals = (rawBytes.size() - header->getPadding()) / sizeof(float);
floatData.resize(numReals);

for (int i=0; i < numReals; ++i) {
for (uint32_t i=0; i < numReals; ++i) {
float dat = *(pFlt++);
if (needSwap()) {
dat = SWAP_32(dat);
Expand Down Expand Up @@ -1924,7 +1925,7 @@ namespace evio {
uint32_t numReals = (rawBytes.size() - header->getPadding()) / sizeof(double);
doubleData.resize(numReals);

for (int i=0; i < numReals; ++i) {
for (uint32_t i=0; i < numReals; ++i) {
double dat = *(pFlt++);
if (needSwap()) {
dat = SWAP_64(dat);
Expand Down Expand Up @@ -2154,7 +2155,7 @@ namespace evio {

// Transform to ASCII
bytes.resize(dataLen);
for (int i=0; i < strData.length(); i++) {
for (size_t i=0; i < strData.length(); i++) {
bytes[i] = strData[i];
}
}
Expand Down Expand Up @@ -2206,7 +2207,7 @@ namespace evio {

// Transform to ASCII
rawBytes.resize(dataLen);
for (int i=0; i < strData.length(); i++) {
for (size_t i=0; i < strData.length(); i++) {
rawBytes[i] = strData[i];
}

Expand Down
2 changes: 1 addition & 1 deletion src/libsrc++/BlockHeaderV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace evio {
* This is not part of the block header proper. It is a position in a memory buffer of the start of the block
* (physical record). It is kept for convenience.
*/
uint64_t bufferStartingPosition = 0L;
size_t bufferStartingPosition = 0L;

public:

Expand Down
8 changes: 4 additions & 4 deletions src/libsrc++/BlockHeaderV4.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace evio {
* This is not part of the block header proper. It is a position in a memory buffer of the start of the block
* (physical record). It is kept for convenience.
*/
int64_t bufferStartingPosition = 0L;
size_t bufferStartingPosition = 0L;


public:
Expand Down Expand Up @@ -569,7 +569,7 @@ namespace evio {

uint32_t v = version;

for (int i=0; i < bSet.size(); i++) {
for (size_t i=0; i < bSet.size(); i++) {
if (i > 23) {
break;
}
Expand Down Expand Up @@ -622,7 +622,7 @@ namespace evio {
return v;
}

for (int i=0; i < bSet->size(); i++) {
for (size_t i=0; i < bSet->size(); i++) {
if (i > 23) {
break;
}
Expand All @@ -641,7 +641,7 @@ namespace evio {
* @param word integer to parse into bit info fields
*/
void parseToBitInfo(uint32_t word) {
for (int i=0; i < bitInfo.size(); i++) {
for (size_t i=0; i < bitInfo.size(); i++) {
bitInfo[i] = ((word >> (8+i)) & 0x1) > 0;
}
}
Expand Down
25 changes: 14 additions & 11 deletions src/libsrc++/CompactEventBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace evio {

// Fill stackArray vector with pre-allocated objects so each openBank/Seg/TagSeg
// doesn't have to create a new StructureContent object each time they're called.
for (int i=0; i < MAX_LEVELS; i++) {
for (uint32_t i=0; i < MAX_LEVELS; i++) {
stackArray[i] = std::make_shared<StructureContent>();
}
}
Expand All @@ -75,7 +75,7 @@ namespace evio {
totalLengths.assign(MAX_LEVELS, 0);
stackArray.resize(MAX_LEVELS);

for (int i=0; i < MAX_LEVELS; i++) {
for (uint32_t i=0; i < MAX_LEVELS; i++) {
stackArray[i] = std::make_shared<StructureContent>();
}

Expand Down Expand Up @@ -198,7 +198,8 @@ namespace evio {
}

// currentLevel starts at -1
if (++currentLevel >= MAX_LEVELS) {
currentLevel++;
if ((uint32_t)currentLevel >= MAX_LEVELS) {
throw EvioException("too many nested evio structures, increase MAX_LEVELS from " +
std::to_string(MAX_LEVELS));
}
Expand Down Expand Up @@ -280,7 +281,8 @@ namespace evio {
}

// currentLevel starts at -1
if (++currentLevel >= MAX_LEVELS) {
currentLevel++;
if ((uint32_t)currentLevel >= MAX_LEVELS) {
throw EvioException("too many nested evio structures, increase MAX_LEVELS from " +
std::to_string(MAX_LEVELS));
}
Expand Down Expand Up @@ -370,7 +372,8 @@ namespace evio {
}

// currentLevel starts at -1
if (++currentLevel >= MAX_LEVELS) {
currentLevel++;
if ((uint32_t)currentLevel >= MAX_LEVELS) {
throw EvioException("too many nested evio structures, increase MAX_LEVELS from " +
std::to_string(MAX_LEVELS));
}
Expand Down Expand Up @@ -496,7 +499,7 @@ namespace evio {
try {
Util::toBytes(len, order, array + arrayOffset + currentStructure->pos);
}
catch (EvioException e) {/* never happen*/}
catch (EvioException & e) {/* never happen*/}
}
else if (type == DataType::SEGMENT || type == DataType::ALSOSEGMENT || type == DataType::TAGSEGMENT) {
try {
Expand Down Expand Up @@ -828,7 +831,7 @@ namespace evio {
}
else {
size_t pos = position;
for (int i=0; i < len; i++) {
for (uint32_t i=0; i < len; i++) {
uint8_t* bytes = reinterpret_cast<uint8_t *>(data);
array[arrayOffset + pos++] = bytes[3];
array[arrayOffset + pos++] = bytes[2];
Expand Down Expand Up @@ -907,7 +910,7 @@ namespace evio {
}
else {
size_t pos = position;
for (int i=0; i < len; i++) {
for (uint32_t i=0; i < len; i++) {
uint8_t* bytes = reinterpret_cast<uint8_t *>(data);
array[arrayOffset + pos++] = bytes[1];
array[arrayOffset + pos++] = bytes[0];
Expand Down Expand Up @@ -962,7 +965,7 @@ namespace evio {
}
else {
size_t pos = position;
for (int i = 0; i < len; i++) {
for (uint32_t i = 0; i < len; i++) {
uint8_t *bytes = reinterpret_cast<uint8_t *>(data);
array[arrayOffset + pos++] = bytes[7];
array[arrayOffset + pos++] = bytes[6];
Expand Down Expand Up @@ -1017,7 +1020,7 @@ namespace evio {
}
else {
size_t pos = position;
for (int i=0; i < len; i++) {
for (uint32_t i=0; i < len; i++) {
uint8_t* bytes = reinterpret_cast<uint8_t *>(data);
array[arrayOffset + pos++] = bytes[3];
array[arrayOffset + pos++] = bytes[2];
Expand Down Expand Up @@ -1064,7 +1067,7 @@ namespace evio {
}
else {
size_t pos = position;
for (int i=0; i < len; i++) {
for (uint32_t i=0; i < len; i++) {
uint8_t* bytes = reinterpret_cast<uint8_t *>(data);
array[arrayOffset + pos++] = bytes[7];
array[arrayOffset + pos++] = bytes[6];
Expand Down
14 changes: 7 additions & 7 deletions src/libsrc++/CompositeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ namespace evio {

// Char data does not get swapped but needs
// to be copied if not swapping in place.
for (int i=0; i < byteLen; i++) {
for (uint32_t i=0; i < byteLen; i++) {
destBuffer.put(destPos+i, srcBuffer.getByte(srcPos+i));
}

Expand Down Expand Up @@ -1434,7 +1434,7 @@ namespace evio {
}

// size of int list
size_t nfmt = ifmt.size();
int nfmt = (int)ifmt.size();
if (nfmt <= 0) throw EvioException("empty format list");

bool inPlace = false;
Expand Down Expand Up @@ -1805,7 +1805,7 @@ namespace evio {
throw EvioException("ifmt arg empty");
}
// size of int list
size_t nfmt = ifmt.size();
int nfmt = (int)ifmt.size();

if (nwrd < 2) {
throw EvioException("number of words to swap must be >= 2");
Expand Down Expand Up @@ -2824,7 +2824,7 @@ namespace evio {
Util::stringsToRawBytes(strs, rb);
rawBuf.put(rb, 0, rb.size());

if (ncnf != rb.size()) {
if (ncnf != (int)rb.size()) {
throw EvioException("String format mismatch with string (array)");
}
//break;
Expand Down Expand Up @@ -3172,11 +3172,11 @@ namespace evio {
ss << std::hex << std::showbase;
}

int numItems = items.size();
size_t numItems = items.size();

uint32_t getIndexOrig = getIndex;

for (int i=0; i < items.size(); i++) {
for (size_t i=0; i < numItems; i++) {
if (i%5 == 0) ss << indent;

DataType typ = types[i];
Expand Down Expand Up @@ -3227,7 +3227,7 @@ namespace evio {
ss << "a=" << getFloat();

auto & strs = getStrings();
for (int j=0; j < strs.size(); j++) {
for (size_t j=0; j < strs.size(); j++) {
ss << strs[j];
if (j < strs.size() - 1) {
ss << ",";
Expand Down
Loading

0 comments on commit 6f53917

Please sign in to comment.