aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/common.c8
-rw-r--r--src/parse.c16
-rw-r--r--src/preprocess.c12
3 files changed, 27 insertions, 9 deletions
diff --git a/src/common.c b/src/common.c
index 4e747bb..8fb73f7 100644
--- a/src/common.c
+++ b/src/common.c
@@ -36,7 +36,9 @@ void strbuilder_init(StrBuilder* b) {
void strbuilder_reserve(StrBuilder* b, size_t size) {
if (size <= b->capacity)
return;
- b->capacity *= 2;
+ while (b->capacity < size) {
+ b->capacity *= 2;
+ }
b->buf = realloc(b->buf, b->capacity * sizeof(char));
memset(b->buf + b->len, 0, (b->capacity - b->len) * sizeof(char));
}
@@ -62,7 +64,9 @@ void strings_init(StrArray* strings) {
void strings_reserve(StrArray* strings, size_t size) {
if (size <= strings->capacity)
return;
- strings->capacity *= 2;
+ while (strings->capacity < size) {
+ strings->capacity *= 2;
+ }
strings->data = realloc(strings->data, strings->capacity * sizeof(const char*));
memset(strings->data + strings->len, 0, (strings->capacity - strings->len) * sizeof(const char*));
}
diff --git a/src/parse.c b/src/parse.c
index 01c494b..de7ff63 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -23,7 +23,9 @@ void lvars_init(LocalVarArray* lvars) {
void lvars_reserve(LocalVarArray* lvars, size_t size) {
if (size <= lvars->capacity)
return;
- lvars->capacity *= 2;
+ while (lvars->capacity < size) {
+ lvars->capacity *= 2;
+ }
lvars->data = realloc(lvars->data, lvars->capacity * sizeof(LocalVar));
memset(lvars->data + lvars->len, 0, (lvars->capacity - lvars->len) * sizeof(LocalVar));
}
@@ -55,7 +57,9 @@ void scopedsymbols_init(ScopedSymbolArray* syms) {
void scopedsymbols_reserve(ScopedSymbolArray* syms, size_t size) {
if (size <= syms->capacity)
return;
- syms->capacity *= 2;
+ while (syms->capacity < size) {
+ syms->capacity *= 2;
+ }
syms->data = realloc(syms->data, syms->capacity * sizeof(ScopedSymbol));
memset(syms->data + syms->len, 0, (syms->capacity - syms->len) * sizeof(ScopedSymbol));
}
@@ -93,7 +97,9 @@ void gvars_init(GlobalVarArray* gvars) {
void gvars_reserve(GlobalVarArray* gvars, size_t size) {
if (size <= gvars->capacity)
return;
- gvars->capacity *= 2;
+ while (gvars->capacity < size) {
+ gvars->capacity *= 2;
+ }
gvars->data = realloc(gvars->data, gvars->capacity * sizeof(GlobalVar));
memset(gvars->data + gvars->len, 0, (gvars->capacity - gvars->len) * sizeof(GlobalVar));
}
@@ -125,7 +131,9 @@ void funcs_init(FuncArray* funcs) {
void funcs_reserve(FuncArray* funcs, size_t size) {
if (size <= funcs->capacity)
return;
- funcs->capacity *= 2;
+ while (funcs->capacity < size) {
+ funcs->capacity *= 2;
+ }
funcs->data = realloc(funcs->data, funcs->capacity * sizeof(Func));
memset(funcs->data + funcs->len, 0, (funcs->capacity - funcs->len) * sizeof(Func));
}
diff --git a/src/preprocess.c b/src/preprocess.c
index 75727d7..e44bbf4 100644
--- a/src/preprocess.c
+++ b/src/preprocess.c
@@ -453,7 +453,9 @@ void tokens_init(TokenArray* tokens, size_t capacity) {
void tokens_reserve(TokenArray* tokens, size_t size) {
if (size <= tokens->capacity)
return;
- tokens->capacity *= 2;
+ while (tokens->capacity < size) {
+ tokens->capacity *= 2;
+ }
tokens->data = realloc(tokens->data, tokens->capacity * sizeof(Token));
memset(tokens->data + tokens->len, 0, (tokens->capacity - tokens->len) * sizeof(Token));
}
@@ -530,7 +532,9 @@ MacroArray* macros_new() {
void macros_reserve(MacroArray* macros, size_t size) {
if (size <= macros->capacity)
return;
- macros->capacity *= 2;
+ while (macros->capacity < size) {
+ macros->capacity *= 2;
+ }
macros->data = realloc(macros->data, macros->capacity * sizeof(Macro));
memset(macros->data + macros->len, 0, (macros->capacity - macros->len) * sizeof(Macro));
}
@@ -599,7 +603,9 @@ MacroArgArray* macroargs_new() {
void macroargs_reserve(MacroArgArray* macroargs, size_t size) {
if (size <= macroargs->capacity)
return;
- macroargs->capacity *= 2;
+ while (macroargs->capacity < size) {
+ macroargs->capacity *= 2;
+ }
macroargs->data = realloc(macroargs->data, macroargs->capacity * sizeof(MacroArg));
memset(macroargs->data + macroargs->len, 0, (macroargs->capacity - macroargs->len) * sizeof(MacroArg));
}