From d819c40d4768c2bfe83d042abd3c1583172899f9 Mon Sep 17 00:00:00 2001 From: Neil Kindlon <nek3d@d-128-109-67.bootp.Virginia.EDU> Date: Sat, 6 Dec 2014 18:38:58 -0500 Subject: [PATCH] Fix for bug 150, closest hangs with -d and tie first mode --- src/utils/RecordOutputMgr/RecordOutputMgr.cpp | 17 ++++++++++------- src/utils/general/ParseTools.h | 8 +++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/utils/RecordOutputMgr/RecordOutputMgr.cpp b/src/utils/RecordOutputMgr/RecordOutputMgr.cpp index fcde1907..4f33b211 100644 --- a/src/utils/RecordOutputMgr/RecordOutputMgr.cpp +++ b/src/utils/RecordOutputMgr/RecordOutputMgr.cpp @@ -137,20 +137,23 @@ void RecordOutputMgr::printRecord(const Record *record, const QuickString & valu } void RecordOutputMgr::printClosest(RecordKeyVector &keyList, const vector<int> *dists) { + const ContextClosest *context = static_cast<const ContextClosest *>(_context); bool deleteBlocks = false; - RecordKeyVector blockList(keyList.getKey()); - if (keyList.getKey()->getType() == FileRecordTypeChecker::BAM_RECORD_TYPE) { + const Record *keyRec = keyList.getKey(); + RecordKeyVector blockList(keyRec); + if (keyRec->getType() == FileRecordTypeChecker::BAM_RECORD_TYPE) { _bamBlockMgr->getBlocks(blockList, deleteBlocks); _currBamBlockList = &blockList; } if (!keyList.empty()) { int distCount = 0; for (RecordKeyVector::const_iterator_type iter = keyList.begin(); iter != keyList.end(); iter = keyList.next()) { - printKey(keyList.getKey()); + const Record *hitRec = *iter; + printKey(keyRec, keyRec->getStartPosStr(), keyRec->getEndPosStr()); tab(); - addDbFileId((*iter)->getFileIdx()); - (*iter)->print(_outBuf); + addDbFileId(hitRec->getFileIdx()); + printKey(hitRec, hitRec->getStartPosStr(), hitRec->getEndPosStr()); if (dists != NULL) { tab(); _outBuf.append((*dists)[distCount]); @@ -160,9 +163,9 @@ void RecordOutputMgr::printClosest(RecordKeyVector &keyList, const vector<int> * if (needsFlush()) flush(); } } else { - printKey(keyList.getKey()); + printKey(keyRec, keyRec->getStartPosStr(), keyRec->getEndPosStr()); tab(); - null(true, false); + null(false, true); if (context->reportDistance()) { tab(); _outBuf.append(-1); diff --git a/src/utils/general/ParseTools.h b/src/utils/general/ParseTools.h index 2ba28df3..a58495d1 100644 --- a/src/utils/general/ParseTools.h +++ b/src/utils/general/ParseTools.h @@ -12,6 +12,8 @@ #include <string> #include <vector> #include "QuickString.h" +#include <cstdio> +#include <cstdlib> using namespace std; @@ -35,7 +37,11 @@ int str2chrPos(const QuickString &str); template<class T> void int2str(int number, T& buffer, bool appendToBuf = false) { - + int maxVal = (1 << 31) -1; + if (((int)(abs(number))) > maxVal) { + fprintf(stderr, "ERROR: number out of bounds.\n"); + exit(1); + } register int useNum = number; if (useNum == 0) { if (appendToBuf) { -- GitLab