<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">hi,<div class=""><br class=""></div><div class="">I am seeing a corrupt memory read for: <b class="">moab::ScdInterface::compute_partition_sqij</b></div><div class=""><br class=""></div><div class="">The issue is these lines:</div><div class=""><pre class="fragment" style="font-family: monospace, fixed; font-size: 9pt; border: 1px solid rgb(196, 207, 229); background-color: rgb(251, 252, 253); padding: 4px 6px; margin: 4px 8px 4px 2px; overflow: auto; overflow-wrap: break-word; line-height: 15px; font-variant-ligatures: normal; orphans: 2; widows: 2;"> <span class="keywordtype" style="color: rgb(96, 64, 32);">double</span> ijratio = ((double)(gijk[3]-gijk[0]))/((<span class="keywordtype" style="color: rgb(96, 64, 32);">double</span>)(gijk[4]-gijk[1]));
<span class="keywordtype" style="color: rgb(96, 64, 32);">unsigned</span> <span class="keywordtype" style="color: rgb(96, 64, 32);">int</span> ind = std::lower_bound(ppfactors.begin(), ppfactors.end(), ijratio) - ppfactors.begin();
<span class="keywordflow" style="color: rgb(224, 128, 0);">if</span> (ind && fabs(ppfactors[ind-1]-ijratio) < fabs(ppfactors[ind]-ijratio)) ind--;</pre><div class=""><br class=""></div></div><div class="">If <span style="orphans: 2; widows: 2; background-color: rgb(251, 252, 253);" class="">std::lower_bound returns ppfactors.end() for finding no match, then ind will be out of bounds.</span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class="">Then </span><span style="background-color: rgb(251, 252, 253);" class="">ppfactors[ind] reads bad memory.</span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class=""><br class=""></span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class="">I attached a test to demonstrate this (<b class=""><i class="">test.cpp</i></b>).</span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class=""><br class=""></span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class="">Even though the bad memory read always happens the code will coincidentally work out.</span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class="">It may not fail until after several thousand runs.</span></div><div style="orphans: 2; widows: 2;" class=""><br class=""></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class="">I attached a batch script I use to detect this (<b class=""><i class="">run.sh</i></b>).</span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class=""><br class=""></span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class="">I can’t see how ijratio is guaranteed to be below or equal one of the factors so perhaps we are not setting this up correctly.</span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class="">Clamping ind resolves the issue for me but I’m not sure what the complete solution is here.</span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class=""><br class=""></span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class="">Thanks,</span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class="">Michel</span></div><div style="orphans: 2; widows: 2;" class=""><span style="background-color: rgb(251, 252, 253);" class=""><br class=""></span></div><div style="orphans: 2; widows: 2;" class=""></div></body></html>