diff options
| author | tylo <[email protected]> | 2020-08-07 15:24:49 +0200 |
|---|---|---|
| committer | tylo <[email protected]> | 2020-08-07 15:24:49 +0200 |
| commit | 41312e6f5f952c043fd84624960582491a78ac4e (patch) | |
| tree | 0d80a037bb78567954a7ac872b1d36b0dc242160 | |
| parent | 40d9a916f4d91e7562ec4c197f72ed661c84579e (diff) | |
| download | STC-modified-41312e6f5f952c043fd84624960582491a78ac4e.tar.gz STC-modified-41312e6f5f952c043fd84624960582491a78ac4e.zip | |
Removed alloca usage.
| -rw-r--r-- | stc/cdefs.h | 2 | ||||
| -rw-r--r-- | 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
@@ -23,14 +23,13 @@ #ifndef CSTR__H__
#define CSTR__H__
-#include <stdlib.h> /* alloca, malloc */
-#include <malloc.h>
+#include <stdlib.h> /* malloc */
#include <string.h>
#include <stdarg.h>
#include <stdio.h> /* 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);
|
