From 41312e6f5f952c043fd84624960582491a78ac4e Mon Sep 17 00:00:00 2001 From: tylo Date: Fri, 7 Aug 2020 15:24:49 +0200 Subject: Removed alloca usage. --- stc/cdefs.h | 2 +- stc/cstr.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/stc/cdefs.h b/stc/cdefs.h index 3a50df0e..6389b779 100644 --- a/stc/cdefs.h +++ b/stc/cdefs.h @@ -59,7 +59,7 @@ #define c_new(T) ((T *) malloc(sizeof(T))) #define c_new_n(T, n) ((T *) malloc(sizeof(T) * (n))) -#define c_max_alloca (1000) +#define c_max_alloca (512) #define c_swap(T, x, y) { T __t = x; x = y; y = __t; } #ifdef __cplusplus #define c_nullptr nullptr diff --git a/stc/cstr.h b/stc/cstr.h index 886fc0a8..0ad7394c 100644 --- a/stc/cstr.h +++ b/stc/cstr.h @@ -23,14 +23,13 @@ #ifndef CSTR__H__ #define CSTR__H__ -#include /* alloca, malloc */ -#include +#include /* malloc */ #include #include #include /* vsnprintf */ - #include "cdefs.h" + typedef struct cstr_t { char* str; } cstr_t; @@ -283,7 +282,8 @@ STC_INLINE void _cstr_internal_move(cstr_t* self, size_t pos1, size_t pos2) { STC_API void cstr_replace_n(cstr_t* self, size_t pos, size_t len, const char* str, size_t n) { - char* xstr = (char *) memcpy(n > c_max_alloca ? malloc(n) : alloca(n), str, n); + char buf[c_max_alloca]; + char* xstr = (char *) memcpy(n > c_max_alloca ? malloc(n) : buf, str, n); _cstr_internal_move(self, pos + len, pos + n); memcpy(&self->str[pos], xstr, n); if (n > c_max_alloca) free(xstr); -- cgit v1.2.3