[sword-devel] Seg fault in verseKey.increment

DM Smith dmsmith at crosswire.org
Sat Nov 12 08:45:00 MST 2011


I have tracked down a segfault in osis2mod to it's usage of increment in 
VerseKey.

Here is the smallest test case that shows the problem. Can someone 
please fix increment so that it sets Error()? I looked but don't know 
how to do it.

If there is an alternative way to get this to work then great.

#include <iostream>
#include <swmgr.h>
#include <swbuf.h>
#include <listkey.h>
#include <versekey.h>

using namespace sword;
using namespace std;

int main(int argc, char **argv) {

         VerseKey vk;
         vk.setVersificationSystem("KJV");
         vk.AutoNormalize(0);
         vk.Headings(1); // turn on mod/testmnt/book/chap headings
         vk.Persist(1);
         vk.setText("Lam 5:22");  // last verse in Lamentation
         SWBuf keyVal = "Lam 6:1"; // a chapter and verse that does not 
exist in Lamentation

         ListKey verseKeys = vk.ParseVerseList(keyVal, vk, true);

         // Show that the verseKeys has no error
         if (verseKeys.Error()) {
                 cout << "Unexpected error in " << vk << endl;
                 exit(0);
         }

         int memberKeyCount = verseKeys.Count();
         cout << "Member Key Count = " << memberKeyCount << endl;

         // Show that the verseKeys has no error
         if (verseKeys.Error()) {
                 cout << "Unexpected error in " << vk << endl;
                 exit(0);
         }

         vk = verseKeys.getElement(0);
         cout << vk << endl;

         // Show that the verseKeys has no error
         if (verseKeys.Error()) {
                 cout << "Unexpected error in " << vk << endl;
                 exit(0);
         }

         // See if this reference is a range, referring to more than one 
verse
         // If it does, skip the verse and output the rest

         // This can be done by incrementing, which will produce an error
         // if there is only one verse.
         verseKeys.setPosition(TOP);

         // Show that the verseKeys has no error
         if (verseKeys.Error()) {
                 cout << "Unexpected error in " << vk << endl;
                 exit(0);
         }

         verseKeys.increment(1); // this segment faults but shouldn't

         if (!verseKeys.Error()) {
                 cout << "The remaining verses in the range are " << 
verseKeys << endl;
         }
         else {
                 cout << "It wasn't a verse range " << verseKeys << endl;
         }
         exit(0);
}








More information about the sword-devel mailing list