Skip to content

Commit

Permalink
fix: remove bugs, appearing with protection off
Browse files Browse the repository at this point in the history
  • Loading branch information
MeerkatBoss committed Oct 21, 2022
1 parent 5b567e3 commit e111e29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions int_stack.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#define NSTACK_CHECK
#define STK_PROT_LEVEL 0
#include "int_stack.h"
#include "stack.h"
13 changes: 10 additions & 3 deletions stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ unsigned int StackAssert_(const Stack* stack,
size_t line,
int force = 0)
{
unsigned int errs = StackCheck_(stack);
unsigned int errs = 0;
_ON_STACK_CHECK(
errs = StackCheck_(stack);
)

if (!errs && !force)
return STK_NO_ERROR;
Expand Down Expand Up @@ -460,14 +463,18 @@ element_t* ReallocWithCanary_(element_t* old_array,
return result;
)
_NO_CANARY(
return realloc(old_array, new_size);
return (element_t*)realloc(old_array, new_size * sizeof(element_t));
)

}

void FreeWithCanary_(element_t* ptr)
{
free((canary_t*)ptr - 1);
_ON_CANARY(
free((canary_t*)ptr - 1);
return;
)
free(ptr);
}

inline size_t GetNewCapacity_(size_t size)
Expand Down

0 comments on commit e111e29

Please sign in to comment.