Skip to content

Commit

Permalink
Fixed index OOB error. Possible fix for remote X-forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
kcleal committed Jan 15, 2024
1 parent 959fb61 commit 482e2cc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ OBJECTS = $(patsubst %.cpp, %.o, $(wildcard ./src/*.cpp))
OBJECTS += $(patsubst %.c, %.o, $(wildcard ./lib/libBigWig/*.c))


debug: LDFLAGS+=-fsanitize=address -fsanitize=undefined
debug:
CXXFLAGS+=-g
LDFLAGS+=-fsanitize=address -fsanitize=undefined

$(TARGET): $(OBJECTS)
$(CXX) -g $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $@
Expand Down
5 changes: 3 additions & 2 deletions src/plot_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ namespace Manager {
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
// glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);


#ifndef __APPLE__
glfwWindowHint(GLFW_CONTEXT_CREATION_API , GLFW_EGL_CONTEXT_API);
#endif
window = glfwCreateWindow(width, height, "GW", NULL, NULL);

if (!window) {
Expand Down
21 changes: 17 additions & 4 deletions src/segments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,34 +572,44 @@ namespace Segs {
void findMismatches(const Themes::IniOptions &opts, ReadCollection &collection) {

std::vector<Segs::Mismatches> &mm_array = collection.mmVector;
size_t mm_array_len = mm_array.size();
const Utils::Region *region = collection.region;
if (region == nullptr) {
return;
}
int regionLen = region->end - region->start;
if (opts.max_coverage == 0 || regionLen > opts.snp_threshold) {
return;
}

const char *refSeq = region->refSeq;
if (refSeq == nullptr) {
return;
}
for (const auto &align: collection.readQueue) {
if (align.y != -1) {
if (align.y != -1 || align.delegate == nullptr) {
continue;
}
uint32_t r_pos = align.pos;
uint32_t cigar_l = align.delegate->core.n_cigar;
uint8_t *ptr_seq = bam_get_seq(align.delegate);
uint32_t *cigar_p = bam_get_cigar(align.delegate);
if (cigar_l == 0 || ptr_seq == nullptr || cigar_p == nullptr) {
continue;
}
int r_idx;
uint32_t idx = 0;

uint32_t qseq_len = align.delegate->core.l_qseq;
uint32_t rlen = region->end - region->start;
auto rbegin = (uint32_t) region->start;
auto rend = (uint32_t) region->end;
uint32_t op, l;
for (uint32_t k = 0; k < cigar_l; k++) {
op = cigar_p[k] & BAM_CIGAR_MASK;
l = cigar_p[k] >> BAM_CIGAR_SHIFT;

if (idx >= qseq_len) { // shouldn't happen
break;
}
switch (op) {
case BAM_CSOFT_CLIP:
case BAM_CINS:
Expand All @@ -617,7 +627,7 @@ namespace Segs {
break;
case BAM_CDIFF:
for (uint32_t i = 0; i < l; ++i) {
if (r_pos >= rbegin && r_pos < rend) {
if (r_pos >= rbegin && r_pos < rend && r_pos - rbegin < mm_array_len) {
char bam_base = bam_seqi(ptr_seq, idx);
switch (bam_base) {
case 1:
Expand Down Expand Up @@ -652,6 +662,9 @@ namespace Segs {
if (r_idx >= (int)rlen) {
break;
}
if (r_pos - rbegin >= mm_array_len) {
break;
}

char ref_base;
switch (refSeq[r_idx]) {
Expand Down

0 comments on commit 482e2cc

Please sign in to comment.