diff --git a/main.cpp b/main.cpp index 0f0b22d..9c252a2 100644 --- a/main.cpp +++ b/main.cpp @@ -564,12 +564,20 @@ void RunProcess(void) { } if(param.out_sam&¶m.sam_header) { - char _ch[1000]; + char _ch[LINEBUFFSIZE]; + int ret_len; for(bit32_t i=0;i<ref.total_num;i++) { - sprintf(_ch,"@SQ\tSN:%s\tLN:%u\n",ref.title[i<<1].name.c_str(),ref.title[i<<1].size); + ret_len=snprintf(_ch,LINEBUFFSIZE,"@SQ\tSN:%s\tLN:%u\n",ref.title[i<<1].name.c_str(),ref.title[i<<1].size); + if (ret_len>=LINEBUFFSIZE) { + cerr<<"Buffer error, output was truncated (increase LINEBUFFSIZE in main.cpp and recompile)."<<endl; + } _str.append(_ch); } - sprintf(_ch,"@PG\tID:BSMAP\tVN:%s\tCL:\"%s\"\n",version,command_line.c_str()); _str.append(_ch); + ret_len=snprintf(_ch,LINEBUFFSIZE,"@PG\tID:BSMAP\tVN:%s\tCL:\"%s\"\n",version,command_line.c_str()); + if (ret_len>=LINEBUFFSIZE) { + cerr<<"Buffer error, output was truncated (increase LINEBUFFSIZE in main.cpp and recompile)."<<endl; + } + _str.append(_ch); if(param.stdout) cout<< _str; else if(param.pipe_out) fwrite(_str.c_str(),1,_str.size(),pout); else fout<<_str;