diff options
author | Kinsey Moore <kmoore@digium.com> | 2012-07-31 20:21:43 +0000 |
---|---|---|
committer | Kinsey Moore <kmoore@digium.com> | 2012-07-31 20:21:43 +0000 |
commit | 9b16c8b0f6c3b6310e303411421bfcb16b26c3c4 (patch) | |
tree | 273c31a834a21bd2239ec6b83cd35c602ea25d26 /include | |
parent | 6c23a60f802e7708389b1a6463a40dc0500512bd (diff) |
Clean up and ensure proper usage of alloca()
This replaces all calls to alloca() with ast_alloca() which calls gcc's
__builtin_alloca() to avoid BSD semantics and removes all NULL checks
on memory allocated via ast_alloca() and ast_strdupa().
(closes issue ASTERISK-20125)
Review: https://reviewboard.asterisk.org/r/2032/
Patch-by: Walter Doekes (wdoekes)
........
Merged revisions 370642 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370643 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370655 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/strings.h | 4 | ||||
-rw-r--r-- | include/asterisk/utils.h | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 7a7772294..7d8069032 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -372,7 +372,7 @@ int ast_get_timeval(const char *src, struct timeval *tv, struct timeval _default /*! \brief The descriptor of a dynamic string * XXX storage will be optimized later if needed * We use the ts field to indicate the type of storage. - * Three special constants indicate malloc, alloca() or static + * Three special constants indicate malloc, ast_alloca() or static * variables, all other values indicate a * struct ast_threadstorage pointer. */ @@ -623,7 +623,7 @@ int ast_str_copy_string(struct ast_str **dst, struct ast_str *src), #define ast_str_alloca(init_len) \ ({ \ struct ast_str *__ast_str_buf; \ - __ast_str_buf = alloca(sizeof(*__ast_str_buf) + init_len); \ + __ast_str_buf = ast_alloca(sizeof(*__ast_str_buf) + init_len); \ __ast_str_buf->__AST_STR_LEN = init_len; \ __ast_str_buf->__AST_STR_USED = 0; \ __ast_str_buf->__AST_STR_TS = DS_ALLOCA; \ diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index edc01d4df..a417cf4d3 100644 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -646,6 +646,15 @@ int _ast_vasprintf(char **ret, const char *file, int lineno, const char *func, c #endif /* AST_DEBUG_MALLOC */ +/*! + \brief call __builtin_alloca to ensure we get gcc builtin semantics + \param size The size of the buffer we want allocated + + This macro will attempt to allocate memory from the stack. If it fails + you won't get a NULL returned, but a SEGFAULT if you're lucky. +*/ +#define ast_alloca(size) __builtin_alloca(size) + #if !defined(ast_strdupa) && defined(__GNUC__) /*! * \brief duplicate a string in memory from the stack |