[sword-devel] Crash when getting module type

Troy A. Griffitts scribe at crosswire.org
Fri Oct 27 08:46:19 EDT 2023


Hi David. There shouldn't be any nulls in the SWMgr::Modules map. Have you done anything with the map which might have created an entry?  For example, have you attempted to obtain a module by name which wasn't there? In C++ this would create an empty entry with a null pointer if the KJV wasn't installed.

SWModule *kjv = swordLibrary->Modules["KJV"];

Just trying to guess what might have happened.


On October 26, 2023 10:59:34 MST, "David "Judah's Shadow" Blue" <yudahsshadow at gmx.com> wrote:
>On Wednesday, October 25, 2023 6:22:54 PM EDT Donna Whisnant wrote:
>> 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.
>
>Ok, I didn't know that there could be null elements in the map.
>
>> 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.
>
>Do you have to do something to load modules? When my program initializes, I do
>this
>
>swordLibrary = new sword::SWMgr(new sword::MarkupFilterMgr(sword::FMT_PLAIN));
>and then pass a pointer to that around my various classes.
>
>In this particular function,  the iterator is this,
>
>sword::ModMap::iterator libraryIterator;
>
>I had thought I was following one of the examples.

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://crosswire.org/pipermail/sword-devel/attachments/20231027/76b15913/attachment.htm>


More information about the sword-devel mailing list