From 67207e20f3dc8b9e92e45560776b5b304f964cc1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 7 Nov 2020 07:56:08 -0500 Subject: Fixed segfaults for invalid module names --- libbible.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'libbible.cc') diff --git a/libbible.cc b/libbible.cc index 7b08174..29e8873 100644 --- a/libbible.cc +++ b/libbible.cc @@ -42,6 +42,10 @@ map> libbible::getModules() { vector libbible::getPassages(string modName, string book) { vector passages; SWModule *target = library.getModule(modName.c_str()); + if(target == nullptr) { + // Module doesn't exist + return passages; + } target->setKey((book + " " + "1").c_str()); VerseKey *key = (VerseKey *) target->getKey(); int maxChapter = key->getChapterMax(); @@ -124,13 +128,17 @@ void inferMissing(libbible::passage *pass, SWModule *target) { } vector libbible::getText(libbible::passage pass) { + vector texts; SWModule *target = library.getModule(pass.modName.c_str()); + if(target == nullptr) { + // Module doesn't exist + return texts; + } inferMissing(&pass, target); target->setKey((pass.book + " " + to_string(pass.chapterStart) + ":" + to_string(pass.verseStart)).c_str()); VerseKey *key = (VerseKey *) target->getKey(); - vector texts; bool endOfParagraph = false; -- cgit v1.2.3