[sword-devel] Crash when getting module type
Donna Whisnant
dewhisna at dewtronics.com
Wed Oct 25 18:22:54 EDT 2023
David,
Based on the code you are showing, I can pretty much guarantee you that your segfault is caused by tempMod being a null pointer -- i.e. that the value of the map element you are iterating is null.
Your code needs to be more defensive and check if tempMod is a nullptr before dereferencing it. Adding an 'if' around that code block should fix your segfault problem. But you'll have to determine why some module entries in your map are nulls -- perhaps you missed loading modules or something? Your code snippet doesn't show any of those details... it only shows iterating something that appears to be a std::map.
Donna
> Date: Tue, 24 Oct 2023 16:04:03 -0400
> From: "David \"Judah's Shadow\" Blue"
> Subject: [sword-devel] Crash when getting module type
> Message-ID: <5986010.lOV4Wx5bFT at brooks>
> Content-Type: text/plain; charset="us-ascii"
>
> I've resumed working on bibish some, and I'm getting a weird crash I never had
> before. I'm trying to interate through the list of installed modules and
> select those that match a given type. This is my code:
>
>
> for(libraryIterator = swordLibrary.Modules.begin();
> libraryIterator != swordLibrary.Modules.end();
> libraryIterator++) {
>
>
> sword::SWModule *tempMod = libraryIterator->second;
> modType = tempMod->getType();
>
> if(modType == selectedType) {
> module = "For ";
> module += tempMod->getDescription();
> module += " select ";
> module += tempMod->getName();
> moduleList.push_front(module);
> module = "";
> }
> }
>
> I am getting a segfault on the modType = tempMod->getType(); line. I'm
> using
> 1.9.0 built myself. I'm not sure what I'm doing wrong.
More information about the sword-devel
mailing list