N
Nomak
Hello,
i have a bug i can't find. I hope somebody will have some ideas...
Here is the bad peace of code:
int compare_sentence(sentence * s1, sentence * s2)
{
assert(s1);
assert(s2);
return s1->similarity_ >= s2->similarity_;
}
....
// check
{
sentences_list_type::iterator it, end = ds->doc.sentences_.end();
for (it = ds->doc.sentences_.begin(); it != end; it++)
{
sentence * s = *it;
assert(s);
assert(s->similarity_ < INT_MAX);
assert(s->sentence_.size() > 0);
}
}
// sort
if (ds->doc.sentences_.size() >= 2)
{
cerr << "&ds.doc.sentences_ = " << &ds->doc.sentences_ << endl;
cerr << "ds.doc.sentences_.size() = " << ds->doc.sentences_.size() <<
endl;
std::sort(ds->doc.sentences_.begin(),
ds->doc.sentences_.end(),
compare_sentence);
sentence * s1 = *ds->doc.sentences_.begin(),
* s2 = *(++(ds->doc.sentences_.begin()));
assert(s1->similarity_ >= s2->similarity_);
}
....
The types:
typedef vector< sentence * > sentences_list_type;
sentences_list_type sentences_;
The output:
&ds.doc.sentences_ = 0x80550a0
ds.doc.sentences_.size() = 852
sim: sim.cc:125: int compare_sentence(sentence*, sentence*): Assertion
`s1' failed.
make: *** [check] Aborted
Valgrind 2.1.1 memcheck:
&ds.doc.sentences_ = 0x3c3690b8
ds.doc.sentences_.size() = 852
==32628==
==32628== Conditional jump or move depends on uninitialised value(s)
==32628== at 0x8049356: compare_sentence(sentence*, sentence*)
(sim.cc:125)
==32628== by 0x804CBB4:
_ZSt21__unguarded_partitionIN9__gnu_cxx17__normal_iteratorIPP8sentenceSt6vectorIS3_SaIS3_EEEES3_PFiS3_S3_EET_SB_SB_T0_T1_
(stl_algo.h:1912)
==32628== by 0x804C46B:
_ZSt16__introsort_loopIN9__gnu_cxx17__normal_iteratorIPP8sentenceSt6vectorIS3_SaIS3_EEEEiPFiS3_S3_EEvT_SB_T0_T1_
(stl_algo.h:2149)
==32628== by 0x804C481:
_ZSt16__introsort_loopIN9__gnu_cxx17__normal_iteratorIPP8sentenceSt6vectorIS3_SaIS3_EEEEiPFiS3_S3_EEvT_SB_T0_T1_
(stl_algo.h:2150)
sim: sim.cc:125: int compare_sentence(sentence*, sentence*): Assertion
`s1' failed.
Valgrind doesn't show any error before the sort call.
I must be doing something bad but i'm lost now...
The check block checks for null pointer and also use a pointer to
access data (since linux doesn't have a IsBadPointer).
So i'm lost. How can i find the bug?
NB: sorry for the > 80 columns
i have a bug i can't find. I hope somebody will have some ideas...
Here is the bad peace of code:
int compare_sentence(sentence * s1, sentence * s2)
{
assert(s1);
assert(s2);
return s1->similarity_ >= s2->similarity_;
}
....
// check
{
sentences_list_type::iterator it, end = ds->doc.sentences_.end();
for (it = ds->doc.sentences_.begin(); it != end; it++)
{
sentence * s = *it;
assert(s);
assert(s->similarity_ < INT_MAX);
assert(s->sentence_.size() > 0);
}
}
// sort
if (ds->doc.sentences_.size() >= 2)
{
cerr << "&ds.doc.sentences_ = " << &ds->doc.sentences_ << endl;
cerr << "ds.doc.sentences_.size() = " << ds->doc.sentences_.size() <<
endl;
std::sort(ds->doc.sentences_.begin(),
ds->doc.sentences_.end(),
compare_sentence);
sentence * s1 = *ds->doc.sentences_.begin(),
* s2 = *(++(ds->doc.sentences_.begin()));
assert(s1->similarity_ >= s2->similarity_);
}
....
The types:
typedef vector< sentence * > sentences_list_type;
sentences_list_type sentences_;
The output:
&ds.doc.sentences_ = 0x80550a0
ds.doc.sentences_.size() = 852
sim: sim.cc:125: int compare_sentence(sentence*, sentence*): Assertion
`s1' failed.
make: *** [check] Aborted
Valgrind 2.1.1 memcheck:
&ds.doc.sentences_ = 0x3c3690b8
ds.doc.sentences_.size() = 852
==32628==
==32628== Conditional jump or move depends on uninitialised value(s)
==32628== at 0x8049356: compare_sentence(sentence*, sentence*)
(sim.cc:125)
==32628== by 0x804CBB4:
_ZSt21__unguarded_partitionIN9__gnu_cxx17__normal_iteratorIPP8sentenceSt6vectorIS3_SaIS3_EEEES3_PFiS3_S3_EET_SB_SB_T0_T1_
(stl_algo.h:1912)
==32628== by 0x804C46B:
_ZSt16__introsort_loopIN9__gnu_cxx17__normal_iteratorIPP8sentenceSt6vectorIS3_SaIS3_EEEEiPFiS3_S3_EEvT_SB_T0_T1_
(stl_algo.h:2149)
==32628== by 0x804C481:
_ZSt16__introsort_loopIN9__gnu_cxx17__normal_iteratorIPP8sentenceSt6vectorIS3_SaIS3_EEEEiPFiS3_S3_EEvT_SB_T0_T1_
(stl_algo.h:2150)
sim: sim.cc:125: int compare_sentence(sentence*, sentence*): Assertion
`s1' failed.
Valgrind doesn't show any error before the sort call.
I must be doing something bad but i'm lost now...
The check block checks for null pointer and also use a pointer to
access data (since linux doesn't have a IsBadPointer).
So i'm lost. How can i find the bug?
NB: sorry for the > 80 columns