Skip to content

Commit ea9aecc

Browse files
committed
Rewrite index oob checks to silence -Wstrict-overflow error
1 parent 11cb244 commit ea9aecc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/CppSQLite3.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ int CppSQLite3Query::numFields() const {
356356
const char *CppSQLite3Query::fieldValue(int nField) const {
357357
checkVM();
358358

359-
if (nField < 0 || nField > mnCols - 1) {
359+
if (nField < 0 || nField >= mnCols) {
360360
throw CppSQLite3Exception(
361361
CPPSQLITE_ERROR, "Invalid field index requested", DONT_DELETE_MSG);
362362
}
@@ -450,7 +450,7 @@ const unsigned char *CppSQLite3Query::getBlobField(int nField,
450450
size_t &nLen) const {
451451
checkVM();
452452

453-
if (nField < 0 || nField > mnCols - 1) {
453+
if (nField < 0 || nField >= mnCols) {
454454
throw CppSQLite3Exception(
455455
CPPSQLITE_ERROR, "Invalid field index requested", DONT_DELETE_MSG);
456456
}
@@ -495,7 +495,7 @@ int CppSQLite3Query::fieldIndex(const char *szField) const {
495495
const char *CppSQLite3Query::fieldName(int nCol) const {
496496
checkVM();
497497

498-
if (nCol < 0 || nCol > mnCols - 1) {
498+
if (nCol < 0 || nCol >= mnCols) {
499499
throw CppSQLite3Exception(
500500
CPPSQLITE_ERROR, "Invalid field index requested", DONT_DELETE_MSG);
501501
}
@@ -506,7 +506,7 @@ const char *CppSQLite3Query::fieldName(int nCol) const {
506506
const char *CppSQLite3Query::fieldDeclType(int nCol) const {
507507
checkVM();
508508

509-
if (nCol < 0 || nCol > mnCols - 1) {
509+
if (nCol < 0 || nCol >= mnCols) {
510510
throw CppSQLite3Exception(
511511
CPPSQLITE_ERROR, "Invalid field index requested", DONT_DELETE_MSG);
512512
}
@@ -517,7 +517,7 @@ const char *CppSQLite3Query::fieldDeclType(int nCol) const {
517517
int CppSQLite3Query::fieldDataType(int nCol) const {
518518
checkVM();
519519

520-
if (nCol < 0 || nCol > mnCols - 1) {
520+
if (nCol < 0 || nCol >= mnCols) {
521521
throw CppSQLite3Exception(
522522
CPPSQLITE_ERROR, "Invalid field index requested", DONT_DELETE_MSG);
523523
}
@@ -632,7 +632,7 @@ int CppSQLite3Table::numRows() const {
632632
const char *CppSQLite3Table::fieldValue(int nField) const {
633633
checkResults();
634634

635-
if (nField < 0 || nField > mnCols - 1) {
635+
if (nField < 0 || nField >= mnCols) {
636636
throw CppSQLite3Exception(
637637
CPPSQLITE_ERROR, "Invalid field index requested", DONT_DELETE_MSG);
638638
}
@@ -743,7 +743,7 @@ bool CppSQLite3Table::fieldIsNull(const char *szField) const {
743743
const char *CppSQLite3Table::fieldName(int nCol) const {
744744
checkResults();
745745

746-
if (nCol < 0 || nCol > mnCols - 1) {
746+
if (nCol < 0 || nCol >= mnCols) {
747747
throw CppSQLite3Exception(
748748
CPPSQLITE_ERROR, "Invalid field index requested", DONT_DELETE_MSG);
749749
}
@@ -754,7 +754,7 @@ const char *CppSQLite3Table::fieldName(int nCol) const {
754754
void CppSQLite3Table::setRow(int nRow) {
755755
checkResults();
756756

757-
if (nRow < 0 || nRow > mnRows - 1) {
757+
if (nRow < 0 || nRow >= mnRows) {
758758
throw CppSQLite3Exception(
759759
CPPSQLITE_ERROR, "Invalid row index requested", DONT_DELETE_MSG);
760760
}

0 commit comments

Comments
 (0)