walaj / SeqLib

C++ htslib/bwa-mem/fermi interface for interrogating sequence data
http://bioinformatics.oxfordjournals.org/content/early/2016/12/21/bioinformatics.btw741.full.pdf+html
Other
133 stars 36 forks source link

Default Constructor may be optimized in case segment fault happens #37

Closed wulj2 closed 5 years ago

wulj2 commented 5 years ago

hello walaj the default FastqReader constructor will take some default value of fp and seq, while you did not define their default value there. fp: https://github.com/walaj/SeqLib/blob/master/SeqLib/FastqReader.h/#L52 seq: https://github.com/walaj/SeqLib/blob/master/SeqLib/FastqReader.h/#L53 FastqReader(): https://github.com/walaj/SeqLib/blob/master/SeqLib/FastqReader.h/#L22

however the default value of seq is not null, which will lead to segment fault if some one accidentally create a FastqReader class by FastqReader() and never use it to open any fast/q file at all, in the end, before the end of main function, the destroyer of FastqReader() will try to destroy something that does not exists and lead to segmentation fault use code in https://github.com/walaj/SeqLib/blob/master/SeqLib/FastqReader.h/#L40

My suggestion is to change FastqReader(): https://github.com/walaj/SeqLib/blob/master/SeqLib/FastqReader.h/#L22 into something like below: FastqReader(){ seq = NULL; }

walaj commented 5 years ago

Thank you -- great catch!