ngmlr icon indicating copy to clipboard operation
ngmlr copied to clipboard

not initialized variable may cause panic in some OS

Open tsjsdbd opened this issue 5 years ago • 2 comments

we found this panic at some OS:

ngmlr[315]: segfault at 564a2f0316a5 ip 0000564a39f5440a sp 00007febb91f8450 error 4 in ngmlr[564a39f38000+3d000]

then use gdb found:

Program terminated with signal 11, Segmentation fault,
#0 0x000055af3cce5392 in Convex::ConvexAlignFast::SingleAlign(int, CorridorLine*
, int, void*) () at /sfs/ngmlr-0.2.7/src/ConvexAlignFast.cpp:503

which locals are:

(gdb) info locals
k = 1980558533

that means :

if (refSeq[k] == 'X') {
    nCount += 1
}

will cause index out of bounds。

for C++, local value need be initialise.

if we add this line to source code, panic will not happen:

if (allocated) {
    align.pBuffer2[0] = '\0';

    FwdResults fwdResults;
    memset(&fwdResults, 0, sizeof(FwdResults));  // <===== add this line

    // Debug: rscript convex-align-vis.r
    if (stdoutPrintAlignCorridor == 6) {

tsjsdbd avatar Sep 02 '19 02:09 tsjsdbd

maybe a constructor initializer is better than memset. for https://stackoverflow.com/questions/5800585/regarding-struct-initialization-in-c like:

struct ABC
{
   int x;
   int y;

   ABC(): x(1),y(2){}
};

tsjsdbd avatar Sep 02 '19 07:09 tsjsdbd

we got the same ERROR on CentOS 7.4, but run successed on Ubuntu 16.04

zhuying412 avatar Sep 02 '19 07:09 zhuying412