Reputation: 737
I just don't get it. I have a function to read stemmed strings from a List, check each string if it contains a punctuation marker to and build phrases in a loop of the single word images. When I check the string building/containing the phrase with s.length() > 0 in the if-statement I get a seg fault. Here is the function:
std::wstring
Phrase::userFriendlyTerms() {
std::wstring s = L"";
List<Object> *terms = getTerms();
Iterator<Object> *i = terms->iterator();
for (; i->hasNext();) {
StemmedTerm *t = (StemmedTerm *) i->next();
std::wstring image = t->getTerm();
// --- gdb shows me a seg. fault with s.length()
if (s.length() > 0 &&
!((image.compare(L",") == 0) || (image.compare(L"?" == 0))
|| (image.compare(L"!") == 0)
|| (image.compare(L";") == 0))) {
s.append(L" ");
}
s.append(image);
}
delete i;
return s;
}
Exact error message is:
Program received signal SIGSEGV, Segmentation fault.
__wcslen (s=0x0) at wcslen.c:30
30 wcslen.c: No such file or directory.
in wcslen.c
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) n
Program not restarted.
(gdb) backtrace
#0 __wcslen (s=0x0) at wcslen.c:30
#1 0x00007ffff7b89e56 in std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::compare(wchar_t const*) const () from /usr/lib/libstdc++.so.6
#2 0x00000000004833ed in Phrase::userFriendlyTerms (this=0x1425ac0) at algorithm/Phrase.cpp:56
Maybe I am blind or missing something ...
Thanks for your help!
Upvotes: 0
Views: 309
Reputation: 36082
this here looks suspicious
(image.compare(L"?" == 0)
are you sure you didn't mean
(image.compare(L"?") == 0)
Upvotes: 2