Fixing memory leaks and indexes out of bounds

This commit is contained in:
Leonardo Vencovsky committed 2020-04-22 18:38:05 -03:00
1 parent 6d4b8618bf
commit 64201cb630
7 files changed
+50 -40

No files matched your search

+5 -1
View File
@@ -351,7 +351,7 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
\
_heap_->buffer[_heap_->count++] = value; \
\
if (!PFX##_empty(_heap_)) \
if (PFX##_count(_heap_) > 1) \
{ \
PFX##_impl_float_up(_heap_, _heap_->count - 1); \
} \
@@ -739,6 +739,10 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
/* Go to parent */ \
C = (C - 1) / 2; \
\
/* Prevent the two lines below from accessing a negative index */ \
if (C == 0) \
break; \
\
child = _heap_->buffer[C]; \
parent = _heap_->buffer[(C - 1) / 2]; \
} \
+1 -1
View File
@@ -805,7 +805,7 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
L = M + 1; \
} \
\
if (_list_->f_val->cmp(_list_->buffer[L - 1], value) == 0) \
if (L > 0 && _list_->f_val->cmp(_list_->buffer[L - 1], value) == 0) \
return L - 1; \
\
/* Not found */ \