Index: src/keys/versekey.cpp =================================================================== --- src/keys/versekey.cpp (revision 3900) +++ src/keys/versekey.cpp (working copy) @@ -1747,6 +1747,12 @@ long i = getIndex(); + // assert we're sane + if (i < 0) { + error = KEYERR_OUTOFBOUNDS; + return; + } + initBounds(); if (i > upperBound) { setIndex(upperBound); Index: utilities/osis2mod.cpp =================================================================== --- utilities/osis2mod.cpp (revision 3900) +++ utilities/osis2mod.cpp (working copy) @@ -440,7 +440,8 @@ // Since isValidRef returned false constrain the key to the nearest prior reference. // If we are past the last chapter set the reference to the last chapter int chapterMax = key.getChapterMax(); - if (key.getChapter() > chapterMax) { + bool beyondChapter = key.getChapter() > chapterMax; + if (beyondChapter) { key.setChapter(chapterMax); } @@ -471,7 +472,7 @@ // In this case we should re-versify Matt.7.30 as Matt.7.29. // However, since this and 2) are ambiguous, we'll re-reversify to the last entry in the module. - while (!key.popError() && !module->hasEntry(&key)) { + while (!beyondChapter && !key.popError() && !module->hasEntry(&key)) { key.decrement(1); }