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
This commit is contained in:
Kinsey Moore
2012-07-31 20:21:43 +00:00
parent 6c23a60f80
commit 9b16c8b0f6
64 changed files with 317 additions and 399 deletions

View File

@@ -689,9 +689,7 @@ struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char
if (preflang == NULL)
preflang = "";
buflen = strlen(preflang) + strlen(filename) + 4;
buf = alloca(buflen);
if (buf == NULL)
return NULL;
buf = ast_alloca(buflen);
if (!(file_fmt_cap = ast_format_cap_alloc_nolock())) {
return NULL;
@@ -735,9 +733,7 @@ struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *fil
if (preflang == NULL)
preflang = "";
buflen = strlen(preflang) + strlen(filename) + 4;
buf = alloca(buflen);
if (buf == NULL)
return NULL;
buf = ast_alloca(buflen);
/* is the channel capable of video without translation ?*/
if (!ast_format_cap_has_type(ast_channel_nativeformats(chan), AST_FORMAT_TYPE_VIDEO)) {
@@ -987,9 +983,7 @@ int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
if (preflang == NULL)
preflang = "";
buflen = strlen(preflang) + strlen(filename) + 4; /* room for everything */
buf = alloca(buflen);
if (buf == NULL)
return 0;
buf = ast_alloca(buflen);
return fileexists_core(filename, fmt, preflang, buf, buflen, NULL) ? 1 : 0;
}
@@ -1168,7 +1162,7 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
*c = '_';
size = strlen(fn) + strlen(record_cache_dir) + 2;
buf = alloca(size);
buf = ast_alloca(size);
strcpy(buf, record_cache_dir);
strcat(buf, "/");
strcat(buf, fn);