[asterisk-commits] kmoore: branch 1.8 r370642 - in /branches/1.8: addons/ apps/ cdr/ channels/ f...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 31 14:31:57 CDT 2012
Author: kmoore
Date: Tue Jul 31 14:31:42 2012
New Revision: 370642
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=370642
Log:
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/
Modified:
branches/1.8/addons/app_mysql.c
branches/1.8/addons/chan_mobile.c
branches/1.8/addons/res_config_mysql.c
branches/1.8/apps/app_dictate.c
branches/1.8/apps/app_directed_pickup.c
branches/1.8/apps/app_festival.c
branches/1.8/apps/app_getcpeid.c
branches/1.8/apps/app_macro.c
branches/1.8/apps/app_meetme.c
branches/1.8/apps/app_minivm.c
branches/1.8/apps/app_mixmonitor.c
branches/1.8/apps/app_osplookup.c
branches/1.8/apps/app_sms.c
branches/1.8/apps/app_voicemail.c
branches/1.8/apps/app_while.c
branches/1.8/cdr/cdr_pgsql.c
branches/1.8/channels/chan_alsa.c
branches/1.8/channels/chan_gtalk.c
branches/1.8/channels/chan_iax2.c
branches/1.8/channels/chan_jingle.c
branches/1.8/channels/chan_sip.c
branches/1.8/funcs/func_channel.c
branches/1.8/funcs/func_cut.c
branches/1.8/funcs/func_global.c
branches/1.8/funcs/func_logic.c
branches/1.8/funcs/func_strings.c
branches/1.8/include/asterisk/strings.h
branches/1.8/include/asterisk/utils.h
branches/1.8/main/app.c
branches/1.8/main/asterisk.c
branches/1.8/main/astmm.c
branches/1.8/main/callerid.c
branches/1.8/main/channel.c
branches/1.8/main/config.c
branches/1.8/main/dsp.c
branches/1.8/main/event.c
branches/1.8/main/features.c
branches/1.8/main/file.c
branches/1.8/main/http.c
branches/1.8/main/logger.c
branches/1.8/main/manager.c
branches/1.8/main/pbx.c
branches/1.8/main/say.c
branches/1.8/main/strcompat.c
branches/1.8/main/tcptls.c
branches/1.8/main/threadstorage.c
branches/1.8/main/utils.c
branches/1.8/pbx/pbx_ael.c
branches/1.8/pbx/pbx_dundi.c
branches/1.8/pbx/pbx_lua.c
branches/1.8/pbx/pbx_realtime.c
branches/1.8/pbx/pbx_spool.c
branches/1.8/res/ael/pval.c
branches/1.8/res/res_agi.c
branches/1.8/res/res_config_pgsql.c
branches/1.8/res/res_jabber.c
branches/1.8/tests/test_linkedlists.c
branches/1.8/utils/extconf.c
Modified: branches/1.8/addons/app_mysql.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/addons/app_mysql.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/addons/app_mysql.c (original)
+++ branches/1.8/addons/app_mysql.c Tue Jul 31 14:31:42 2012
@@ -295,7 +295,7 @@
AST_NONSTANDARD_APP_ARGS(args, data, ' ');
if (args.argc == 3) {
- var = alloca(6 + strlen(args.variable) + 1);
+ var = ast_alloca(6 + strlen(args.variable) + 1);
sprintf(var, "MYSQL_%s", args.variable);
/* Make the parameter case-insensitive */
Modified: branches/1.8/addons/chan_mobile.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/addons/chan_mobile.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/addons/chan_mobile.c (original)
+++ branches/1.8/addons/chan_mobile.c Tue Jul 31 14:31:42 2012
@@ -558,7 +558,7 @@
max_rsp = 255;
flags = IREQ_CACHE_FLUSH;
- ii = alloca(max_rsp * sizeof(inquiry_info));
+ ii = ast_alloca(max_rsp * sizeof(inquiry_info));
num_rsp = hci_inquiry(adapter->dev_id, len, max_rsp, NULL, &ii, flags);
if (num_rsp > 0) {
ast_cli(a->fd, FORMAT1, "Address", "Name", "Usable", "Type", "Port");
Modified: branches/1.8/addons/res_config_mysql.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/addons/res_config_mysql.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/addons/res_config_mysql.c (original)
+++ branches/1.8/addons/res_config_mysql.c Tue Jul 31 14:31:42 2012
@@ -144,7 +144,7 @@
if (for_write) {
whichdb = ast_strdupa(ptr + 1);
} else {
- whichdb = alloca(ptr - database + 1);
+ whichdb = ast_alloca(ptr - database + 1);
strncpy(whichdb, database, ptr - database);
whichdb[ptr - database] = '\0';
}
@@ -467,7 +467,7 @@
}
initfield = ast_strdupa(newparam);
- if (initfield && (op = strchr(initfield, ' '))) {
+ if ((op = strchr(initfield, ' '))) {
*op = '\0';
}
Modified: branches/1.8/apps/app_dictate.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_dictate.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_dictate.c (original)
+++ branches/1.8/apps/app_dictate.c Tue Jul 31 14:31:42 2012
@@ -149,7 +149,7 @@
ast_mkdir(base, 0755);
len = strlen(base) + strlen(filein) + 2;
if (!path || len > maxlen) {
- path = alloca(len);
+ path = ast_alloca(len);
memset(path, 0, len);
maxlen = len;
} else {
Modified: branches/1.8/apps/app_directed_pickup.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_directed_pickup.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_directed_pickup.c (original)
+++ branches/1.8/apps/app_directed_pickup.c Tue Jul 31 14:31:42 2012
@@ -158,7 +158,7 @@
* debugging.
*/
pickup_args.len = strlen(channame) + 1;
- chkchan = alloca(pickup_args.len + 1);
+ chkchan = ast_alloca(pickup_args.len + 1);
strcpy(chkchan, channame);
strcat(chkchan, "-");
pickup_args.name = chkchan;
Modified: branches/1.8/apps/app_festival.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_festival.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_festival.c (original)
+++ branches/1.8/apps/app_festival.c Tue Jul 31 14:31:42 2012
@@ -343,12 +343,12 @@
const char *endcmd = "\" 'file)(quit)\n";
strln = strlen(startcmd) + strlen(args.text) + strlen(endcmd) + 1;
- newfestivalcommand = alloca(strln);
+ newfestivalcommand = ast_alloca(strln);
snprintf(newfestivalcommand, strln, "%s%s%s", startcmd, args.text, endcmd);
festivalcommand = newfestivalcommand;
} else { /* This else parses the festivalcommand that we're sent from the config file for \n's, etc */
int x, j;
- newfestivalcommand = alloca(strlen(festivalcommand) + strlen(args.text) + 1);
+ newfestivalcommand = ast_alloca(strlen(festivalcommand) + strlen(args.text) + 1);
for (x = 0, j = 0; x < strlen(festivalcommand); x++) {
if (festivalcommand[x] == '\\' && festivalcommand[x + 1] == 'n') {
Modified: branches/1.8/apps/app_getcpeid.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_getcpeid.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_getcpeid.c (original)
+++ branches/1.8/apps/app_getcpeid.c Tue Jul 31 14:31:42 2012
@@ -76,7 +76,7 @@
unsigned int x;
for (x = 0; x < 4; x++)
- data[x] = alloca(80);
+ data[x] = ast_alloca(80);
strcpy(data[0], "** CPE Info **");
strcpy(data[1], "Identifying CPE...");
Modified: branches/1.8/apps/app_macro.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_macro.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_macro.c (original)
+++ branches/1.8/apps/app_macro.c Tue Jul 31 14:31:42 2012
@@ -596,8 +596,7 @@
char *expr = NULL, *label_a = NULL, *label_b = NULL;
int res = 0;
- if (!(expr = ast_strdupa(data)))
- return -1;
+ expr = ast_strdupa(data);
if ((label_a = strchr(expr, '?'))) {
*label_a = '\0';
Modified: branches/1.8/apps/app_meetme.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_meetme.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_meetme.c (original)
+++ branches/1.8/apps/app_meetme.c Tue Jul 31 14:31:42 2012
@@ -4110,8 +4110,7 @@
return -1;
}
- if (!(localdata = ast_strdupa(data)))
- return -1;
+ localdata = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, localdata);
Modified: branches/1.8/apps/app_minivm.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_minivm.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_minivm.c (original)
+++ branches/1.8/apps/app_minivm.c Tue Jul 31 14:31:42 2012
@@ -2054,10 +2054,6 @@
return -1;
}
tmpptr = ast_strdupa((char *)data);
- if (!tmpptr) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -1;
- }
argc = ast_app_separate_args(tmpptr, ',', argv, ARRAY_LEN(argv));
if (argc < 4) {
ast_log(LOG_ERROR, "%d arguments passed to MiniVM_MWI, need 4.\n", argc);
@@ -2102,10 +2098,6 @@
return -1;
}
tmpptr = ast_strdupa((char *)data);
- if (!tmpptr) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -1;
- }
argc = ast_app_separate_args(tmpptr, ',', argv, ARRAY_LEN(argv));
if (argc == 2 && !ast_strlen_zero(argv[1]))
@@ -2186,10 +2178,6 @@
return -1;
}
tmp = ast_strdupa((char *)data);
- if (!tmp) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -1;
- }
argc = ast_app_separate_args(tmp, ',', argv, ARRAY_LEN(argv));
if (argc == 2) {
if (ast_app_parse_options(minivm_app_options, &flags, opts, argv[1])) {
@@ -2249,10 +2237,6 @@
return -1;
}
tmpptr = ast_strdupa((char *)data);
- if (!tmpptr) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return -1;
- }
argc = ast_app_separate_args(tmpptr, ',', argv, ARRAY_LEN(argv));
if (argc == 2) {
@@ -2476,14 +2460,9 @@
if (ast_strlen_zero(data)) {
ast_log(LOG_ERROR, "MinivmAccmess needs at least two arguments: account and option\n");
error = TRUE;
- } else
+ } else {
tmpptr = ast_strdupa((char *)data);
- if (!error) {
- if (!tmpptr) {
- ast_log(LOG_ERROR, "Out of memory\n");
- error = TRUE;
- } else
- argc = ast_app_separate_args(tmpptr, ',', argv, ARRAY_LEN(argv));
+ argc = ast_app_separate_args(tmpptr, ',', argv, ARRAY_LEN(argv));
}
if (argc <=1) {
@@ -2623,7 +2602,7 @@
char *varname = ast_strdupa(var->value);
struct ast_variable *tmpvar;
- if (varname && (varval = strchr(varname, '='))) {
+ if ((varval = strchr(varname, '='))) {
*varval = '\0';
varval++;
if ((tmpvar = ast_variable_new(varname, varval, ""))) {
@@ -2681,11 +2660,6 @@
return 0;
msg_format = ast_strdupa(config);
- if (msg_format == NULL) {
- ast_log(LOG_WARNING, "Out of memory.\n");
- ast_free(newzone);
- return 0;
- }
timezone_str = strsep(&msg_format, "|");
if (!msg_format) {
@@ -3201,10 +3175,7 @@
struct minivm_account *vmu;
char *username, *domain, *colname;
- if (!(username = ast_strdupa(data))) {
- ast_log(LOG_ERROR, "Memory Error!\n");
- return -1;
- }
+ username = ast_strdupa(data);
if ((colname = strchr(username, ':'))) {
*colname = '\0';
@@ -3355,10 +3326,8 @@
*buf = '\0';
- if (!(username = ast_strdupa(data))) { /* Copy indata to local buffer */
- ast_log(LOG_WARNING, "Memory error!\n");
- return -1;
- }
+ username = ast_strdupa(data);
+
if ((countername = strchr(username, ':'))) {
*countername = '\0';
countername++;
@@ -3414,10 +3383,7 @@
return -1;
change = atoi(value);
- if (!(username = ast_strdupa(data))) { /* Copy indata to local buffer */
- ast_log(LOG_WARNING, "Memory error!\n");
- return -1;
- }
+ username = ast_strdupa(data);
if ((countername = strchr(username, ':'))) {
*countername = '\0';
Modified: branches/1.8/apps/app_mixmonitor.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_mixmonitor.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_mixmonitor.c (original)
+++ branches/1.8/apps/app_mixmonitor.c Tue Jul 31 14:31:42 2012
@@ -542,7 +542,7 @@
if (args.filename[0] != '/') {
char *build;
- build = alloca(strlen(ast_config_AST_MONITOR_DIR) + strlen(args.filename) + 3);
+ build = ast_alloca(strlen(ast_config_AST_MONITOR_DIR) + strlen(args.filename) + 3);
sprintf(build, "%s/%s", ast_config_AST_MONITOR_DIR, args.filename);
args.filename = build;
}
Modified: branches/1.8/apps/app_osplookup.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_osplookup.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_osplookup.c (original)
+++ branches/1.8/apps/app_osplookup.c Tue Jul 31 14:31:42 2012
@@ -2240,10 +2240,7 @@
AST_APP_ARG(options);
);
- if (!(tmp = ast_strdupa(data))) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return OSP_AST_ERROR;
- }
+ tmp = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, tmp);
@@ -2335,10 +2332,7 @@
return OSP_AST_ERROR;
}
- if (!(tmp = ast_strdupa(data))) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return OSP_AST_ERROR;
- }
+ tmp = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, tmp);
@@ -2609,10 +2603,7 @@
return OSP_AST_ERROR;
}
- if (!(tmp = ast_strdupa(data))) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return OSP_AST_ERROR;
- }
+ tmp = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, tmp);
@@ -2791,10 +2782,7 @@
AST_APP_ARG(options);
);
- if (!(tmp = ast_strdupa(data))) {
- ast_log(LOG_ERROR, "Out of memory\n");
- return OSP_AST_ERROR;
- }
+ tmp = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, tmp);
Modified: branches/1.8/apps/app_sms.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_sms.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_sms.c (original)
+++ branches/1.8/apps/app_sms.c Tue Jul 31 14:31:42 2012
@@ -1604,7 +1604,7 @@
samples = MAXSAMPLES;
}
len = samples * sizeof(*buf) + AST_FRIENDLY_OFFSET;
- buf = alloca(len);
+ buf = ast_alloca(len);
f.frametype = AST_FRAME_VOICE;
f.subclass.codec = __OUT_FMT;
Modified: branches/1.8/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_voicemail.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_voicemail.c (original)
+++ branches/1.8/apps/app_voicemail.c Tue Jul 31 14:31:42 2012
@@ -951,7 +951,7 @@
static int inprocess_count(const char *context, const char *mailbox, int delta)
{
- struct inprocess *i, *arg = alloca(sizeof(*arg) + strlen(context) + strlen(mailbox) + 2);
+ struct inprocess *i, *arg = ast_alloca(sizeof(*arg) + strlen(context) + strlen(mailbox) + 2);
arg->context = arg->mailbox + strlen(mailbox) + 1;
strcpy(arg->mailbox, mailbox); /* SAFE */
strcpy(arg->context, context); /* SAFE */
@@ -1549,10 +1549,10 @@
}
value = strstr(tmp, ",");
if (!value) {
- new = alloca(strlen(newpassword)+1);
+ new = ast_alloca(strlen(newpassword)+1);
sprintf(new, "%s", newpassword);
} else {
- new = alloca((strlen(value) + strlen(newpassword) + 1));
+ new = ast_alloca((strlen(value) + strlen(newpassword) + 1));
sprintf(new, "%s%s", newpassword, value);
}
if (!(cat = ast_category_get(cfg, category))) {
@@ -1587,7 +1587,7 @@
} else {
var = NULL;
}
- new = alloca(strlen(newpassword) + 1);
+ new = ast_alloca(strlen(newpassword) + 1);
sprintf(new, "%s", newpassword);
if (!(cat = ast_category_get(cfg, category))) {
ast_debug(4, "failed to get category!\n");
@@ -4195,7 +4195,7 @@
int txtsize = 0;
txtsize = (strlen(file) + 5)*sizeof(char);
- txt = alloca(txtsize);
+ txt = ast_alloca(txtsize);
/* Sprintf here would safe because we alloca'd exactly the right length,
* but trying to eliminate all sprintf's anyhow
*/
@@ -8083,7 +8083,7 @@
int cmd;
char *buf;
- buf = alloca(strlen(box) + 2);
+ buf = ast_alloca(strlen(box) + 2);
strcpy(buf, box);
strcat(buf, "s");
@@ -10813,7 +10813,7 @@
read_password_from_file(secretfn, vmu->password, sizeof(vmu->password));
}
- mailbox_full = alloca(strlen(box) + strlen(context) + 1);
+ mailbox_full = ast_alloca(strlen(box) + strlen(context) + 1);
strcpy(mailbox_full, box);
strcat(mailbox_full, "@");
strcat(mailbox_full, context);
Modified: branches/1.8/apps/app_while.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_while.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/apps/app_while.c (original)
+++ branches/1.8/apps/app_while.c Tue Jul 31 14:31:42 2012
@@ -236,7 +236,7 @@
condition = ast_strdupa(data);
size = strlen(chan->context) + strlen(chan->exten) + 32;
- my_name = alloca(size);
+ my_name = ast_alloca(size);
memset(my_name, 0, size);
snprintf(my_name, size, "%s_%s_%d", chan->context, chan->exten, chan->priority);
@@ -281,7 +281,7 @@
if (!end && !while_pri) {
char *goto_str;
size = strlen(chan->context) + strlen(chan->exten) + 32;
- goto_str = alloca(size);
+ goto_str = ast_alloca(size);
memset(goto_str, 0, size);
snprintf(goto_str, size, "%s,%s,%d", chan->context, chan->exten, chan->priority);
pbx_builtin_setvar_helper(chan, varname, goto_str);
@@ -293,7 +293,7 @@
if (! pbx_builtin_getvar_helper(chan, end_varname)) {
char *goto_str;
size = strlen(chan->context) + strlen(chan->exten) + 32;
- goto_str = alloca(size);
+ goto_str = ast_alloca(size);
memset(goto_str, 0, size);
snprintf(goto_str, size, "%s,%s,%d", chan->context, chan->exten, chan->priority+1);
pbx_builtin_setvar_helper(chan, end_varname, goto_str);
Modified: branches/1.8/cdr/cdr_pgsql.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/cdr/cdr_pgsql.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/cdr/cdr_pgsql.c (original)
+++ branches/1.8/cdr/cdr_pgsql.c Tue Jul 31 14:31:42 2012
@@ -535,7 +535,7 @@
if (strchr(schemaname, '\\') || strchr(schemaname, '\'')) {
char *tmp = schemaname, *ptr;
- ptr = schemaname = alloca(strlen(tmp) * 2 + 1);
+ ptr = schemaname = ast_alloca(strlen(tmp) * 2 + 1);
for (; *tmp; tmp++) {
if (strchr("\\'", *tmp)) {
*ptr++ = *tmp;
@@ -548,7 +548,7 @@
if (strchr(tablename, '\\') || strchr(tablename, '\'')) {
char *tmp = tablename, *ptr;
- ptr = tablename = alloca(strlen(tmp) * 2 + 1);
+ ptr = tablename = ast_alloca(strlen(tmp) * 2 + 1);
for (; *tmp; tmp++) {
if (strchr("\\'", *tmp)) {
*ptr++ = *tmp;
Modified: branches/1.8/channels/chan_alsa.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_alsa.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/channels/chan_alsa.c (original)
+++ branches/1.8/channels/chan_alsa.c Tue Jul 31 14:31:42 2012
@@ -183,7 +183,7 @@
ast_debug(1, "Opening device %s in %s mode\n", dev, (stream == SND_PCM_STREAM_CAPTURE) ? "read" : "write");
}
- hwparams = alloca(snd_pcm_hw_params_sizeof());
+ hwparams = ast_alloca(snd_pcm_hw_params_sizeof());
memset(hwparams, 0, snd_pcm_hw_params_sizeof());
snd_pcm_hw_params_any(handle, hwparams);
@@ -224,7 +224,7 @@
if (err < 0)
ast_log(LOG_ERROR, "Couldn't set the new hw params: %s\n", snd_strerror(err));
- swparams = alloca(snd_pcm_sw_params_sizeof());
+ swparams = ast_alloca(snd_pcm_sw_params_sizeof());
memset(swparams, 0, snd_pcm_sw_params_sizeof());
snd_pcm_sw_params_current(handle, swparams);
Modified: branches/1.8/channels/chan_gtalk.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_gtalk.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/channels/chan_gtalk.c (original)
+++ branches/1.8/channels/chan_gtalk.c Tue Jul 31 14:31:42 2012
@@ -1857,15 +1857,13 @@
if (data) {
s = ast_strdupa(data);
- if (s) {
- sender = strsep(&s, "/");
- if (sender && (sender[0] != '\0')) {
- to = strsep(&s, "/");
- }
- if (!to) {
- ast_log(LOG_ERROR, "Bad arguments in Gtalk Dialstring: %s\n", (char*) data);
- return NULL;
- }
+ sender = strsep(&s, "/");
+ if (sender && (sender[0] != '\0')) {
+ to = strsep(&s, "/");
+ }
+ if (!to) {
+ ast_log(LOG_ERROR, "Bad arguments in Gtalk Dialstring: %s\n", (char*) data);
+ return NULL;
}
}
Modified: branches/1.8/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_iax2.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/channels/chan_iax2.c (original)
+++ branches/1.8/channels/chan_iax2.c Tue Jul 31 14:31:42 2012
@@ -3034,10 +3034,7 @@
unsigned char sum[16], buf[1024];
char *s2, *last;
- if (!(s2 = alloca(strlen(s) + 100))) {
- ast_log(LOG_WARNING, "Alloca failed!\n");
- return -1;
- }
+ s2 = ast_alloca(strlen(s) + 100);
last = strrchr(s, '/');
if (last)
@@ -6257,7 +6254,7 @@
int padding;
unsigned char *workspace;
- workspace = alloca(*datalen);
+ workspace = ast_alloca(*datalen);
memset(f, 0, sizeof(*f));
if (ntohs(fh->scallno) & IAX_FLAG_FULL) {
struct ast_iax2_full_enc_hdr *efh = (struct ast_iax2_full_enc_hdr *)fh;
@@ -6303,9 +6300,7 @@
{
int padding;
unsigned char *workspace;
- workspace = alloca(*datalen + 32);
- if (!workspace)
- return -1;
+ workspace = ast_alloca(*datalen + 32);
if (ntohs(fh->scallno) & IAX_FLAG_FULL) {
struct ast_iax2_full_enc_hdr *efh = (struct ast_iax2_full_enc_hdr *)fh;
if (iaxdebug)
@@ -9939,9 +9934,9 @@
char *using_prefs = "mine";
/* allocate an iax_frame with 4096 bytes of data buffer */
- fr = alloca(sizeof(*fr) + 4096);
+ fr = ast_alloca(sizeof(*fr) + 4096);
memset(fr, 0, sizeof(*fr));
- fr->afdatalen = 4096; /* From alloca() above */
+ fr->afdatalen = 4096; /* From ast_alloca() above */
/* Copy frequently used parameters to the stack */
res = thread->buf_len;
@@ -12307,9 +12302,7 @@
char *addr;
char *portstr;
- if (!(tmp = ast_strdupa(srcaddr)))
- return -1;
-
+ tmp = ast_strdupa(srcaddr);
addr = strsep(&tmp, ":");
portstr = tmp;
@@ -12769,7 +12762,7 @@
user->ha = ast_append_ha(v->name, v->value, user->ha, NULL);
} else if (!strcasecmp(v->name, "setvar")) {
varname = ast_strdupa(v->value);
- if (varname && (varval = strchr(varname,'='))) {
+ if ((varval = strchr(varname, '='))) {
*varval = '\0';
varval++;
if((tmpvar = ast_variable_new(varname, varval, ""))) {
Modified: branches/1.8/channels/chan_jingle.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_jingle.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/channels/chan_jingle.c (original)
+++ branches/1.8/channels/chan_jingle.c Tue Jul 31 14:31:42 2012
@@ -1514,14 +1514,13 @@
if (data) {
s = ast_strdupa(data);
- if (s) {
- sender = strsep(&s, "/");
- if (sender && (sender[0] != '\0'))
- to = strsep(&s, "/");
- if (!to) {
- ast_log(LOG_ERROR, "Bad arguments in Jingle Dialstring: %s\n", (char*) data);
- return NULL;
- }
+ sender = strsep(&s, "/");
+ if (sender && (sender[0] != '\0')) {
+ to = strsep(&s, "/");
+ }
+ if (!to) {
+ ast_log(LOG_ERROR, "Bad arguments in Jingle Dialstring: %s\n", (char*) data);
+ return NULL;
}
}
Modified: branches/1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_sip.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/channels/chan_sip.c (original)
+++ branches/1.8/channels/chan_sip.c Tue Jul 31 14:31:42 2012
@@ -5392,7 +5392,7 @@
/* Change the dialog callid. */
callid_size = strlen(tmpcall) + strlen(peer->fromdomain) + 2;
- new_callid = alloca(callid_size);
+ new_callid = ast_alloca(callid_size);
snprintf(new_callid, callid_size, "%s@%s", tmpcall, peer->fromdomain);
change_callid_pvt(dialog, new_callid);
}
@@ -12759,7 +12759,7 @@
cid_num = S_COR(caller->caller.id.number.valid,
caller->caller.id.number.str, "");
need = strlen(cid_num) + strlen(p->fromdomain) + sizeof("sip:@");
- remote_target = alloca(need);
+ remote_target = ast_alloca(need);
snprintf(remote_target, need, "sip:%s@%s", cid_num, p->fromdomain);
remote_display = ast_strdupa(S_COR(caller->caller.id.name.valid,
@@ -12768,7 +12768,7 @@
connected_num = S_COR(caller->connected.id.number.valid,
caller->connected.id.number.str, "");
need = strlen(connected_num) + strlen(p->fromdomain) + sizeof("sip:@");
- local_target = alloca(need);
+ local_target = ast_alloca(need);
snprintf(local_target, need, "sip:%s@%s", connected_num, p->fromdomain);
local_display = ast_strdupa(S_COR(caller->connected.id.name.valid,
@@ -23427,7 +23427,8 @@
payload_size = ast_connected_line_build_data(connected_line_data,
sizeof(connected_line_data), &connected_to_target, NULL);
frame_size = payload_size + sizeof(*frame_payload);
- if (payload_size != -1 && (frame_payload = alloca(frame_size))) {
+ if (payload_size != -1) {
+ frame_payload = ast_alloca(frame_size);
frame_payload->payload_size = payload_size;
memcpy(frame_payload->payload, connected_line_data, payload_size);
frame_payload->action = AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO;
@@ -29678,7 +29679,7 @@
}
if (ok) {
size_t len = strlen(inbuf);
- subbuf = alloca(len + 1);
+ subbuf = ast_alloca(len + 1);
ast_get_encoded_str(inbuf, subbuf, len + 1);
pbx_builtin_setvar_helper(chan, varbuf, subbuf);
if (sipdebug) {
Modified: branches/1.8/funcs/func_channel.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_channel.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/funcs/func_channel.c (original)
+++ branches/1.8/funcs/func_channel.c Tue Jul 31 14:31:42 2012
@@ -621,7 +621,7 @@
char *data, struct ast_str **buf, ssize_t len)
{
struct ast_channel *mchan = ast_channel_get_by_name(chan->linkedid);
- char *template = alloca(4 + strlen(data));
+ char *template = ast_alloca(4 + strlen(data));
sprintf(template, "${%s}", data); /* SAFE */
ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template);
if (mchan) {
Modified: branches/1.8/funcs/func_cut.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_cut.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/funcs/func_cut.c (original)
+++ branches/1.8/funcs/func_cut.c Tue Jul 31 14:31:42 2012
@@ -119,7 +119,7 @@
count++;
}
- sortable_keys = alloca(count * sizeof(struct sortable_keys));
+ sortable_keys = ast_alloca(count * sizeof(struct sortable_keys));
memset(sortable_keys, 0, count * sizeof(struct sortable_keys));
@@ -170,9 +170,8 @@
/* Check arguments */
if (args.argc < 3) {
return ERROR_NOARG;
- } else if (!(var_expr = alloca(strlen(args.varname) + 4))) {
- return ERROR_NOMEM;
- }
+ }
+ var_expr = ast_alloca(strlen(args.varname) + 4);
/* Get the value of the variable named in the 1st argument */
snprintf(var_expr, strlen(args.varname) + 4, "${%s}", args.varname);
Modified: branches/1.8/funcs/func_global.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_global.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/funcs/func_global.c (original)
+++ branches/1.8/funcs/func_global.c Tue Jul 31 14:31:42 2012
@@ -148,7 +148,7 @@
AST_STANDARD_APP_ARGS(args, data);
if (!ast_strlen_zero(args.chan)) {
- char *prefix = alloca(strlen(args.chan) + 2);
+ char *prefix = ast_alloca(strlen(args.chan) + 2);
sprintf(prefix, "%s-", args.chan);
if (!(c_ref = ast_channel_get_by_name(args.chan)) && !(c_ref = ast_channel_get_by_name_prefix(prefix, strlen(prefix)))) {
ast_log(LOG_ERROR, "Channel '%s' not found! Variable '%s' will be blank.\n", args.chan, args.var);
@@ -206,7 +206,7 @@
AST_STANDARD_APP_ARGS(args, data);
if (!ast_strlen_zero(args.chan)) {
- char *prefix = alloca(strlen(args.chan) + 2);
+ char *prefix = ast_alloca(strlen(args.chan) + 2);
sprintf(prefix, "%s-", args.chan);
if (!(c_ref = ast_channel_get_by_name(args.chan)) && !(c_ref = ast_channel_get_by_name_prefix(prefix, strlen(prefix)))) {
ast_log(LOG_ERROR, "Channel '%s' not found! Variable '%s' not set to '%s'.\n", args.chan, args.var, value);
Modified: branches/1.8/funcs/func_logic.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_logic.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/funcs/func_logic.c (original)
+++ branches/1.8/funcs/func_logic.c Tue Jul 31 14:31:42 2012
@@ -250,17 +250,15 @@
struct ast_channel *chan2;
if ((chan2 = ast_channel_get_by_name(args.channel))) {
- char *s = alloca(strlen(args.varname) + 4);
- if (s) {
- sprintf(s, "${%s}", args.varname);
- ast_channel_lock(chan2);
- if (buf) {
- pbx_substitute_variables_helper(chan2, s, buf, len);
- } else {
- ast_str_substitute_variables(str, len, chan2, s);
- }
- ast_channel_unlock(chan2);
+ char *s = ast_alloca(strlen(args.varname) + 4);
+ sprintf(s, "${%s}", args.varname);
+ ast_channel_lock(chan2);
+ if (buf) {
+ pbx_substitute_variables_helper(chan2, s, buf, len);
+ } else {
+ ast_str_substitute_variables(str, len, chan2, s);
}
+ ast_channel_unlock(chan2);
chan2 = ast_channel_unref(chan2);
}
}
Modified: branches/1.8/funcs/func_strings.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_strings.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/funcs/func_strings.c (original)
+++ branches/1.8/funcs/func_strings.c Tue Jul 31 14:31:42 2012
@@ -438,7 +438,7 @@
if (args.delim) {
ast_get_encoded_char(args.delim, delim, &delim_used);
- varsubst = alloca(strlen(args.varname) + 4);
+ varsubst = ast_alloca(strlen(args.varname) + 4);
sprintf(varsubst, "${%s}", args.varname);
ast_str_substitute_variables(&str, 0, chan, varsubst);
@@ -504,7 +504,7 @@
ast_log(LOG_ERROR, "Usage: FIELDNUM(<listname>,<delimiter>,<fieldvalue>)\n");
res = -1;
} else {
- varsubst = alloca(strlen(args.varname) + 4);
+ varsubst = ast_alloca(strlen(args.varname) + 4);
sprintf(varsubst, "${%s}", args.varname);
ast_str_substitute_variables(&str, 0, chan, varsubst);
@@ -588,7 +588,7 @@
return -1;
}
- varsubst = alloca(strlen(args.listname) + 4);
+ varsubst = ast_alloca(strlen(args.listname) + 4);
sprintf(varsubst, "${%s}", args.listname);
/* If we don't lock the channel, the variable could disappear out from underneath us. */
@@ -618,7 +618,7 @@
}
dlen = strlen(args.delimiter);
- delim = alloca(dlen + 1);
+ delim = ast_alloca(dlen + 1);
ast_get_encoded_str(args.delimiter, delim, dlen + 1);
if ((dlen = strlen(delim)) == 0) {
@@ -801,7 +801,7 @@
return -1;
}
- varsubst = alloca(strlen(args.varname) + 4);
+ varsubst = ast_alloca(strlen(args.varname) + 4);
sprintf(varsubst, "${%s}", args.varname);
ast_str_substitute_variables(&str, 0, chan, varsubst);
@@ -919,9 +919,10 @@
char *origvar = "", *value2, varname[256];
int i, ishash = 0;
+ if (!var) {
+ return -1;
+ }
value2 = ast_strdupa(value);
- if (!var || !value2)
- return -1;
if (!strcmp(cmd, "HASH")) {
const char *var2 = pbx_builtin_getvar_helper(chan, "~ODBCFIELDS~");
@@ -1437,7 +1438,7 @@
return -1;
}
- varsubst = alloca(strlen(args.var) + 4);
+ varsubst = ast_alloca(strlen(args.var) + 4);
sprintf(varsubst, "${%s}", args.var);
ast_str_substitute_variables(&before, 0, chan, varsubst);
@@ -1501,7 +1502,7 @@
ast_get_encoded_char(args.delimiter, delimiter, &unused);
}
- varsubst = alloca(strlen(args.var) + 4);
+ varsubst = ast_alloca(strlen(args.var) + 4);
sprintf(varsubst, "${%s}", args.var);
ast_str_substitute_variables(&previous_value, 0, chan, varsubst);
Modified: branches/1.8/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/include/asterisk/strings.h?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/include/asterisk/strings.h (original)
+++ branches/1.8/include/asterisk/strings.h Tue Jul 31 14:31:42 2012
@@ -357,7 +357,7 @@
/*! \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.
*/
@@ -608,7 +608,7 @@
#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; \
Modified: branches/1.8/include/asterisk/utils.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/include/asterisk/utils.h?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/include/asterisk/utils.h (original)
+++ branches/1.8/include/asterisk/utils.h Tue Jul 31 14:31:42 2012
@@ -623,13 +623,22 @@
#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
\param s The string to duplicate
- This macro will duplicate the given string. It returns a pointer to the stack
- allocatted memory for the new string.
+ This macro will duplicate the given string. It returns a pointer to stack
+ allocated memory for the new string.
*/
#define ast_strdupa(s) \
(__extension__ \
Modified: branches/1.8/main/app.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/app.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/main/app.c (original)
+++ branches/1.8/main/app.c Tue Jul 31 14:31:42 2012
@@ -592,7 +592,7 @@
}
if (blen > 2) {
- breaks = alloca(blen + 1);
+ breaks = ast_alloca(blen + 1);
breaks[0] = '\0';
if (stop) {
strcat(breaks, stop);
@@ -1336,8 +1336,8 @@
int lp = strlen(path);
time_t start;
- s = alloca(lp + 10);
- fs = alloca(lp + 20);
+ s = ast_alloca(lp + 10);
+ fs = ast_alloca(lp + 20);
snprintf(fs, strlen(path) + 19, "%s/.lock-%08lx", path, ast_random());
fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, AST_FILE_MODE);
@@ -1369,7 +1369,7 @@
char *s;
int res;
- s = alloca(strlen(path) + 10);
+ s = ast_alloca(strlen(path) + 10);
snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock");
@@ -1410,7 +1410,7 @@
struct path_lock *pl;
struct stat st, ost;
- fs = alloca(strlen(path) + 20);
+ fs = ast_alloca(strlen(path) + 20);
snprintf(fs, strlen(path) + 19, "%s/lock", path);
if (lstat(fs, &st) == 0) {
@@ -1491,7 +1491,7 @@
char *s;
struct path_lock *p;
- s = alloca(strlen(path) + 20);
+ s = ast_alloca(strlen(path) + 20);
AST_LIST_LOCK(&path_lock_list);
AST_LIST_TRAVERSE_SAFE_BEGIN(&path_lock_list, p, le) {
Modified: branches/1.8/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/asterisk.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/main/asterisk.c (original)
+++ branches/1.8/main/asterisk.c Tue Jul 31 14:31:42 2012
@@ -2790,7 +2790,7 @@
}
if (data) {
char prefix[] = "cli quit after ";
- char *tmp = alloca(strlen(data) + strlen(prefix) + 1);
+ char *tmp = ast_alloca(strlen(data) + strlen(prefix) + 1);
sprintf(tmp, "%s%s", prefix, data);
if (write(ast_consock, tmp, strlen(tmp) + 1) < 0) {
ast_log(LOG_ERROR, "write() failed: %s\n", strerror(errno));
Modified: branches/1.8/main/astmm.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/astmm.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/main/astmm.c (original)
+++ branches/1.8/main/astmm.c Tue Jul 31 14:31:42 2012
@@ -430,7 +430,7 @@
break;
}
if (!cur) {
- cur = alloca(sizeof(*cur));
+ cur = ast_alloca(sizeof(*cur));
memset(cur, 0, sizeof(*cur));
ast_copy_string(cur->fn, fn ? reg->func : reg->file, sizeof(cur->fn));
cur->next = list;
Modified: branches/1.8/main/callerid.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/callerid.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/main/callerid.c (original)
+++ branches/1.8/main/callerid.c Tue Jul 31 14:31:42 2012
@@ -314,7 +314,7 @@
int x;
short *buf;
- buf = alloca(2 * len + cid->oldlen);
+ buf = ast_alloca(2 * len + cid->oldlen);
memcpy(buf, cid->oldstuff, cid->oldlen);
mylen += cid->oldlen / 2;
@@ -552,7 +552,7 @@
int x;
short *buf;
- buf = alloca(2 * len + cid->oldlen);
+ buf = ast_alloca(2 * len + cid->oldlen);
memcpy(buf, cid->oldstuff, cid->oldlen);
mylen += cid->oldlen/2;
Modified: branches/1.8/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/channel.c?view=diff&rev=370642&r1=370641&r2=370642
==============================================================================
--- branches/1.8/main/channel.c (original)
+++ branches/1.8/main/channel.c Tue Jul 31 14:31:42 2012
@@ -3158,8 +3158,8 @@
*exception = 0;
if ((sz = n * AST_MAX_FDS + nfds)) {
- pfds = alloca(sizeof(*pfds) * sz);
- fdmap = alloca(sizeof(*fdmap) * sz);
+ pfds = ast_alloca(sizeof(*pfds) * sz);
+ fdmap = ast_alloca(sizeof(*fdmap) * sz);
} else {
/* nothing to allocate and no FDs to check */
return NULL;
@@ -6403,7 +6403,7 @@
sizeof(connected_line_data), &colp->target_id, NULL);
if (payload_size != -1) {
frame_size = payload_size + sizeof(*frame_payload);
- frame_payload = alloca(frame_size);
+ frame_payload = ast_alloca(frame_size);
frame_payload->action = AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO;
frame_payload->payload_size = payload_size;
[... 1002 lines stripped ...]
More information about the asterisk-commits
mailing list