[Asterisk-cvs] asterisk app.c, 1.62, 1.63 asterisk.c, 1.158, 1.159 channel.c, 1.199, 1.200 file.c, 1.65, 1.66 pbx.c, 1.251, 1.252

kpfleming at lists.digium.com kpfleming at lists.digium.com
Sun Jun 5 12:29:42 CDT 2005


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv2173

Modified Files:
	app.c asterisk.c channel.c file.c pbx.c 
Log Message:
more ast_copy_string() conversion


Index: app.c
===================================================================
RCS file: /usr/cvsroot/asterisk/app.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- app.c	5 Jun 2005 15:04:43 -0000	1.62
+++ app.c	5 Jun 2005 16:32:16 -0000	1.63
@@ -384,7 +384,7 @@
 			return -1;
 		autoclose = 1;
 		if (filename[0] == '/') 
-			strncpy(tmpf, filename, sizeof(tmpf) - 1);
+			ast_copy_string(tmpf, filename, sizeof(tmpf));
 		else
 			snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", (char *)ast_config_AST_VAR_DIR, "sounds", filename);
 		fd = open(tmpf, O_RDONLY);
@@ -773,7 +773,7 @@
 		if (d < 0)
 			return -1;
 	}
-	strncpy(prependfile, recordfile, sizeof(prependfile) -1);	
+	ast_copy_string(prependfile, recordfile, sizeof(prependfile));	
 	strncat(prependfile, "-prepend", sizeof(prependfile) - strlen(prependfile) - 1);
 			
 	fmts = ast_strdupa(fmt);
@@ -971,7 +971,7 @@
 	char *grp=NULL, *cat=NULL;
 
 	if (data && !ast_strlen_zero(data)) {
-		strncpy(tmp, data, sizeof(tmp) - 1);
+		ast_copy_string(tmp, data, sizeof(tmp));
 		grp = tmp;
 		cat = strchr(tmp, '@');
 		if (cat) {
@@ -981,14 +981,14 @@
 	}
 
 	if (grp && !ast_strlen_zero(grp))
-		strncpy(group, grp, group_max -1);
+		ast_copy_string(group, grp, group_max);
 	else
 		res = -1;
 
 	if (cat)
 		snprintf(category, category_max, "%s_%s", GROUP_CATEGORY_PREFIX, cat);
 	else
-		strncpy(category, GROUP_CATEGORY_PREFIX, category_max - 1);
+		ast_copy_string(category, GROUP_CATEGORY_PREFIX, category_max);
 
 	return res;
 }
@@ -1015,9 +1015,9 @@
 	char cat[80] = "";
 
 	if (category && !ast_strlen_zero(category)) {
-		strncpy(cat, category, sizeof(cat) - 1);
+		ast_copy_string(cat, category, sizeof(cat));
 	} else {
-		strncpy(cat, GROUP_CATEGORY_PREFIX, sizeof(cat) - 1);
+		ast_copy_string(cat, GROUP_CATEGORY_PREFIX, sizeof(cat));
 	}
 
 	if (group && !ast_strlen_zero(group)) {
@@ -1050,9 +1050,9 @@
 		return 0;
 
 	if (category && !ast_strlen_zero(category)) {
-		strncpy(cat, category, sizeof(cat) - 1);
+		ast_copy_string(cat, category, sizeof(cat));
 	} else {
-		strncpy(cat, GROUP_CATEGORY_PREFIX, sizeof(cat) - 1);
+		ast_copy_string(cat, GROUP_CATEGORY_PREFIX, sizeof(cat));
 	}
 
 	chan = ast_channel_walk_locked(NULL);

Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.158
retrieving revision 1.159
diff -u -d -r1.158 -r1.159
--- asterisk.c	3 Jun 2005 03:04:08 -0000	1.158
+++ asterisk.c	5 Jun 2005 16:32:16 -0000	1.159
@@ -282,7 +282,7 @@
 	struct pollfd fds[2];
 	
 	if (gethostname(hostname, sizeof(hostname)-1))
-		strncpy(hostname, "<Unknown>", sizeof(hostname)-1);
+		ast_copy_string(hostname, "<Unknown>", sizeof(hostname));
 	snprintf(tmp, sizeof(tmp), "%s/%d/%s\n", hostname, ast_mainpid, ASTERISK_VERSION);
 	fdprint(con->fd, tmp);
 	for(;;) {
@@ -413,7 +413,7 @@
 	}		
 	memset(&sunaddr, 0, sizeof(sunaddr));
 	sunaddr.sun_family = AF_LOCAL;
-	strncpy(sunaddr.sun_path, (char *)ast_config_AST_SOCKET, sizeof(sunaddr.sun_path)-1);
+	ast_copy_string(sunaddr.sun_path, (char *)ast_config_AST_SOCKET, sizeof(sunaddr.sun_path));
 	res = bind(ast_socket, (struct sockaddr *)&sunaddr, sizeof(sunaddr));
 	if (res) {
 		ast_log(LOG_WARNING, "Unable to bind socket to %s: %s\n", (char *)ast_config_AST_SOCKET, strerror(errno));
@@ -486,7 +486,7 @@
 	}
 	memset(&sunaddr, 0, sizeof(sunaddr));
 	sunaddr.sun_family = AF_LOCAL;
-	strncpy(sunaddr.sun_path, (char *)ast_config_AST_SOCKET, sizeof(sunaddr.sun_path)-1);
+	ast_copy_string(sunaddr.sun_path, (char *)ast_config_AST_SOCKET, sizeof(sunaddr.sun_path));
 	res = connect(ast_consock, (struct sockaddr *)&sunaddr, sizeof(sunaddr));
 	if (res) {
 		close(ast_consock);
@@ -1558,17 +1558,17 @@
 	}
 
 	/* init with buildtime config */
-	strncpy((char *)ast_config_AST_CONFIG_DIR,AST_CONFIG_DIR,sizeof(ast_config_AST_CONFIG_DIR)-1);
-	strncpy((char *)ast_config_AST_SPOOL_DIR,AST_SPOOL_DIR,sizeof(ast_config_AST_SPOOL_DIR)-1);
-	strncpy((char *)ast_config_AST_MODULE_DIR,AST_MODULE_DIR,sizeof(ast_config_AST_VAR_DIR)-1);
-	strncpy((char *)ast_config_AST_VAR_DIR,AST_VAR_DIR,sizeof(ast_config_AST_VAR_DIR)-1);
-	strncpy((char *)ast_config_AST_LOG_DIR,AST_LOG_DIR,sizeof(ast_config_AST_LOG_DIR)-1);
-	strncpy((char *)ast_config_AST_AGI_DIR,AST_AGI_DIR,sizeof(ast_config_AST_AGI_DIR)-1);
-	strncpy((char *)ast_config_AST_DB,AST_DB,sizeof(ast_config_AST_DB)-1);
-	strncpy((char *)ast_config_AST_KEY_DIR,AST_KEY_DIR,sizeof(ast_config_AST_KEY_DIR)-1);
-	strncpy((char *)ast_config_AST_PID,AST_PID,sizeof(ast_config_AST_PID)-1);
-	strncpy((char *)ast_config_AST_SOCKET,AST_SOCKET,sizeof(ast_config_AST_SOCKET)-1);
-	strncpy((char *)ast_config_AST_RUN_DIR,AST_RUN_DIR,sizeof(ast_config_AST_RUN_DIR)-1);
+	ast_copy_string((char *)ast_config_AST_CONFIG_DIR,AST_CONFIG_DIR,sizeof(ast_config_AST_CONFIG_DIR));
+	ast_copy_string((char *)ast_config_AST_SPOOL_DIR,AST_SPOOL_DIR,sizeof(ast_config_AST_SPOOL_DIR));
+	ast_copy_string((char *)ast_config_AST_MODULE_DIR,AST_MODULE_DIR,sizeof(ast_config_AST_VAR_DIR));
+	ast_copy_string((char *)ast_config_AST_VAR_DIR,AST_VAR_DIR,sizeof(ast_config_AST_VAR_DIR));
+	ast_copy_string((char *)ast_config_AST_LOG_DIR,AST_LOG_DIR,sizeof(ast_config_AST_LOG_DIR));
+	ast_copy_string((char *)ast_config_AST_AGI_DIR,AST_AGI_DIR,sizeof(ast_config_AST_AGI_DIR));
+	ast_copy_string((char *)ast_config_AST_DB,AST_DB,sizeof(ast_config_AST_DB));
+	ast_copy_string((char *)ast_config_AST_KEY_DIR,AST_KEY_DIR,sizeof(ast_config_AST_KEY_DIR));
+	ast_copy_string((char *)ast_config_AST_PID,AST_PID,sizeof(ast_config_AST_PID));
+	ast_copy_string((char *)ast_config_AST_SOCKET,AST_SOCKET,sizeof(ast_config_AST_SOCKET));
+	ast_copy_string((char *)ast_config_AST_RUN_DIR,AST_RUN_DIR,sizeof(ast_config_AST_RUN_DIR));
 	
 	/* no asterisk.conf? no problem, use buildtime config! */
 	if (!cfg) {
@@ -1585,22 +1585,22 @@
 	v = ast_variable_browse(cfg, "directories");
 	while(v) {
 		if (!strcasecmp(v->name, "astetcdir")) {
-			strncpy((char *)ast_config_AST_CONFIG_DIR,v->value,sizeof(ast_config_AST_CONFIG_DIR)-1);
+			ast_copy_string((char *)ast_config_AST_CONFIG_DIR,v->value,sizeof(ast_config_AST_CONFIG_DIR));
 		} else if (!strcasecmp(v->name, "astspooldir")) {
-			strncpy((char *)ast_config_AST_SPOOL_DIR,v->value,sizeof(ast_config_AST_SPOOL_DIR)-1);
+			ast_copy_string((char *)ast_config_AST_SPOOL_DIR,v->value,sizeof(ast_config_AST_SPOOL_DIR));
 		} else if (!strcasecmp(v->name, "astvarlibdir")) {
-			strncpy((char *)ast_config_AST_VAR_DIR,v->value,sizeof(ast_config_AST_VAR_DIR)-1);
+			ast_copy_string((char *)ast_config_AST_VAR_DIR,v->value,sizeof(ast_config_AST_VAR_DIR));
 			snprintf((char *)ast_config_AST_DB,sizeof(ast_config_AST_DB),"%s/%s",v->value,"astdb");    
 		} else if (!strcasecmp(v->name, "astlogdir")) {
-			strncpy((char *)ast_config_AST_LOG_DIR,v->value,sizeof(ast_config_AST_LOG_DIR)-1);
+			ast_copy_string((char *)ast_config_AST_LOG_DIR,v->value,sizeof(ast_config_AST_LOG_DIR));
 		} else if (!strcasecmp(v->name, "astagidir")) {
-			strncpy((char *)ast_config_AST_AGI_DIR,v->value,sizeof(ast_config_AST_AGI_DIR)-1);
+			ast_copy_string((char *)ast_config_AST_AGI_DIR,v->value,sizeof(ast_config_AST_AGI_DIR));
 		} else if (!strcasecmp(v->name, "astrundir")) {
 			snprintf((char *)ast_config_AST_PID,sizeof(ast_config_AST_PID),"%s/%s",v->value,"asterisk.pid");
 			snprintf((char *)ast_config_AST_SOCKET,sizeof(ast_config_AST_SOCKET),"%s/%s",v->value,v_ctlfile==NULL?"asterisk.ctl":v_ctlfile->value);
-			strncpy((char *)ast_config_AST_RUN_DIR,v->value,sizeof(ast_config_AST_RUN_DIR)-1);
+			ast_copy_string((char *)ast_config_AST_RUN_DIR,v->value,sizeof(ast_config_AST_RUN_DIR));
 		} else if (!strcasecmp(v->name, "astmoddir")) {
-			strncpy((char *)ast_config_AST_MODULE_DIR,v->value,sizeof(ast_config_AST_MODULE_DIR)-1);
+			ast_copy_string((char *)ast_config_AST_MODULE_DIR,v->value,sizeof(ast_config_AST_MODULE_DIR));
 		}
 		v = v->next;
 	}
@@ -1650,7 +1650,7 @@
 			option_cache_record_files = ast_true(v->value);
 		/* Specify cache directory */
 		}  else if (!strcasecmp(v->name, "record_cache_dir")) {
-			strncpy(record_cache_dir,v->value,AST_CACHE_DIR_LEN);
+			ast_copy_string(record_cache_dir,v->value,AST_CACHE_DIR_LEN);
 		/* Build transcode paths via SLINEAR, instead of directly */
 		} else if (!strcasecmp(v->name, "transcode_via_sln")) {
 			option_transcode_slin = ast_true(v->value);
@@ -1694,7 +1694,7 @@
 		option_nofork++;
 	}
 	if (gethostname(hostname, sizeof(hostname)-1))
-		strncpy(hostname, "<Unknown>", sizeof(hostname)-1);
+		ast_copy_string(hostname, "<Unknown>", sizeof(hostname));
 	ast_mainpid = getpid();
 	ast_ulaw_init();
 	ast_alaw_init();
@@ -1761,7 +1761,7 @@
 			xarg = optarg;
 			break;
 		case 'C':
-			strncpy((char *)ast_config_AST_CONFIG_FILE,optarg,sizeof(ast_config_AST_CONFIG_FILE) - 1);
+			ast_copy_string((char *)ast_config_AST_CONFIG_FILE,optarg,sizeof(ast_config_AST_CONFIG_FILE));
 			option_overrideconfig++;
 			break;
 		case 'i':

Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.199
retrieving revision 1.200
diff -u -d -r1.199 -r1.200
--- channel.c	5 Jun 2005 15:04:43 -0000	1.199
+++ channel.c	5 Jun 2005 16:32:16 -0000	1.200
@@ -393,7 +393,7 @@
 	tmp->fds[AST_MAX_FDS-1] = tmp->alertpipe[0];
 	/* And timing pipe */
 	tmp->fds[AST_MAX_FDS-2] = tmp->timingfd;
-	strncpy(tmp->name, "**Unknown**", sizeof(tmp->name)-1);
+	ast_copy_string(tmp->name, "**Unknown**", sizeof(tmp->name));
 	/* Initial state */
 	tmp->_state = AST_STATE_DOWN;
 	tmp->streamid = -1;
@@ -405,12 +405,12 @@
 	headp = &tmp->varshead;
 	ast_mutex_init(&tmp->lock);
 	AST_LIST_HEAD_INIT(headp);
-	strncpy(tmp->context, "default", sizeof(tmp->context)-1);
-	strncpy(tmp->language, defaultlanguage, sizeof(tmp->language)-1);
-	strncpy(tmp->exten, "s", sizeof(tmp->exten)-1);
+	ast_copy_string(tmp->context, "default", sizeof(tmp->context));
+	ast_copy_string(tmp->language, defaultlanguage, sizeof(tmp->language));
+	ast_copy_string(tmp->exten, "s", sizeof(tmp->exten));
 	tmp->priority = 1;
 	tmp->amaflags = ast_default_amaflags;
-	strncpy(tmp->accountcode, ast_default_accountcode, sizeof(tmp->accountcode)-1);
+	ast_copy_string(tmp->accountcode, ast_default_accountcode, sizeof(tmp->accountcode));
 
 	tmp->tech = &null_tech;
 
@@ -674,7 +674,7 @@
 		free(chan->tech_pvt);
 	}
 
-	strncpy(name, chan->name, sizeof(name)-1);
+	ast_copy_string(name, chan->name, sizeof(name));
 	
 	/* Stop monitoring */
 	if (chan->monitor) {
@@ -1994,9 +1994,9 @@
 		/* Final fixups */
 		if (oh) {
 			if (oh->context && *oh->context)
-				strncpy(chan->context, oh->context, sizeof(chan->context) - 1);
+				ast_copy_string(chan->context, oh->context, sizeof(chan->context));
 			if (oh->exten && *oh->exten)
-				strncpy(chan->exten, oh->exten, sizeof(chan->exten) - 1);
+				ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten));
 			chan->priority = oh->priority;
 		}
 		if (chan->_state == AST_STATE_UP) 
@@ -2093,7 +2093,7 @@
 
 	chan = ast_channel_walk_locked(NULL);
 	while (chan) {
-		strncpy(name, chan->name, sizeof(name)-1);
+		ast_copy_string(name, chan->name, sizeof(name));
 		ast_mutex_unlock(&chan->lock);
 		cut = strchr(name,'-');
 		if (cut)
@@ -2117,7 +2117,7 @@
 	struct chanlist *chanls;
 	int res = 0;
 	
-	strncpy(tech, device, sizeof(tech)-1);
+	ast_copy_string(tech, device, sizeof(tech));
 	number = strchr(tech, '/');
 	if (!number) {
 	    return AST_DEVICE_INVALID;
@@ -2373,8 +2373,8 @@
 void ast_change_name(struct ast_channel *chan, char *newname)
 {
 	char tmp[256];
-	strncpy(tmp, chan->name, sizeof(tmp) - 1);
-	strncpy(chan->name, newname, sizeof(chan->name) - 1);
+	ast_copy_string(tmp, chan->name, sizeof(tmp));
+	ast_copy_string(chan->name, newname, sizeof(chan->name));
 	manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", tmp, chan->name, chan->uniqueid);
 }
 
@@ -2495,17 +2495,17 @@
 	clone->masqr = NULL;
 	
 	/* Save the original name */
-	strncpy(orig, original->name, sizeof(orig) - 1);
+	ast_copy_string(orig, original->name, sizeof(orig));
 	/* Save the new name */
-	strncpy(newn, clone->name, sizeof(newn) - 1);
+	ast_copy_string(newn, clone->name, sizeof(newn));
 	/* Create the masq name */
 	snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn);
 		
 	/* Copy the name from the clone channel */
-	strncpy(original->name, newn, sizeof(original->name)-1);
+	ast_copy_string(original->name, newn, sizeof(original->name));
 
 	/* Mangle the name of the clone channel */
-	strncpy(clone->name, masqn, sizeof(clone->name) - 1);
+	ast_copy_string(clone->name, masqn, sizeof(clone->name));
 	
 	/* Notify any managers of the change, first the masq then the other */
 	manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clone->uniqueid);
@@ -2589,14 +2589,14 @@
 	
 	snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig);
 	/* Mangle the name of the clone channel */
-	strncpy(clone->name, zombn, sizeof(clone->name) - 1);
+	ast_copy_string(clone->name, zombn, sizeof(clone->name));
 	manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clone->uniqueid);
 
 	/* Update the type. */
 	original->type = clone->type;
 	
 	/* Keep the same language.  */
-	strncpy(original->language, clone->language, sizeof(original->language));
+	ast_copy_string(original->language, clone->language, sizeof(original->language));
 	/* Copy the FD's */
 	for (x=0;x<AST_MAX_FDS;x++) {
 		original->fds[x] = clone->fds[x];
@@ -2638,7 +2638,7 @@
 	ast_set_read_format(original, rformat);
 
 	/* Copy the music class */
-	strncpy(original->musicclass, clone->musicclass, sizeof(original->musicclass) - 1);
+	ast_copy_string(original->musicclass, clone->musicclass, sizeof(original->musicclass));
 
 	ast_log(LOG_DEBUG, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat);
 

Index: file.c
===================================================================
RCS file: /usr/cvsroot/asterisk/file.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- file.c	5 Jun 2005 15:04:43 -0000	1.65
+++ file.c	5 Jun 2005 16:32:16 -0000	1.66
@@ -119,8 +119,8 @@
 		ast_mutex_unlock(&formatlock);
 		return -1;
 	}
-	strncpy(tmp->name, name, sizeof(tmp->name)-1);
-	strncpy(tmp->exts, exts, sizeof(tmp->exts)-1);
+	ast_copy_string(tmp->name, name, sizeof(tmp->name));
+	ast_copy_string(tmp->exts, exts, sizeof(tmp->exts));
 	tmp->open = open;
 	tmp->rewrite = rewrite;
 	tmp->read = read;
@@ -285,9 +285,9 @@
 	int fnsize = 0;
 
 	if (!strcmp(ext, "wav49")) {
-		strncpy(type, "WAV", sizeof(type) - 1);
+		ast_copy_string(type, "WAV", sizeof(type));
 	} else {
-		strncpy(type, ext, sizeof(type) - 1);
+		ast_copy_string(type, ext, sizeof(type));
 	}
 
 	if (filename[0] == '/') {
@@ -313,7 +313,7 @@
 	char *stringp = NULL, *ext;
 	char tmp[256];
 
-	strncpy(tmp, exts, sizeof(tmp) - 1);
+	ast_copy_string(tmp, exts, sizeof(tmp));
 	stringp = tmp;
 	while ((ext = strsep(&stringp, "|"))) {
 		if (!strcmp(ext, type)) {
@@ -472,7 +472,7 @@
 			ast_deactivate_generator(chan);
 	}
 	if (preflang && !ast_strlen_zero(preflang)) {
-		strncpy(filename3, filename, sizeof(filename3) - 1);
+		ast_copy_string(filename3, filename, sizeof(filename3));
 		endpart = strrchr(filename3, '/');
 		if (endpart) {
 			*endpart = '\0';
@@ -483,7 +483,7 @@
 		fmts = ast_fileexists(filename2, NULL, NULL);
 	}
 	if (fmts < 1) {
-		strncpy(filename2, filename, sizeof(filename2)-1);
+		ast_copy_string(filename2, filename, sizeof(filename2));
 		fmts = ast_fileexists(filename2, NULL, NULL);
 	}
 	if (fmts < 1) {
@@ -524,13 +524,13 @@
 		snprintf(filename2, sizeof(filename2), "%s/%s", preflang, filename);
 		fmts = ast_fileexists(filename2, fmt, NULL);
 		if (fmts < 1) {
-			strncpy(lang2, preflang, sizeof(lang2)-1);
+			ast_copy_string(lang2, preflang, sizeof(lang2));
 			snprintf(filename2, sizeof(filename2), "%s/%s", lang2, filename);
 			fmts = ast_fileexists(filename2, fmt, NULL);
 		}
 	}
 	if (fmts < 1) {
-		strncpy(filename2, filename, sizeof(filename2)-1);
+		ast_copy_string(filename2, filename, sizeof(filename2));
 		fmts = ast_fileexists(filename2, fmt, NULL);
 	}
 	if (fmts < 1) {
@@ -723,7 +723,7 @@
 	int res = -1;
 	if (preflang && !ast_strlen_zero(preflang)) {
 		/* Insert the language between the last two parts of the path */
-		strncpy(tmp, filename, sizeof(tmp) - 1);
+		ast_copy_string(tmp, filename, sizeof(tmp));
 		c = strrchr(tmp, '/');
 		if (c) {
 			*c = '\0';
@@ -738,7 +738,7 @@
 		res = ast_filehelper(filename2, NULL, fmt, ACTION_EXISTS);
 		if (res < 1) {
 			char *stringp=NULL;
-			strncpy(lang2, preflang, sizeof(lang2)-1);
+			ast_copy_string(lang2, preflang, sizeof(lang2));
 			stringp=lang2;
 			strsep(&stringp, "_");
 			/* If language is a specific locality of a language (like es_MX), strip the locality and try again */

Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.251
retrieving revision 1.252
diff -u -d -r1.251 -r1.252
--- pbx.c	5 Jun 2005 16:08:44 -0000	1.251
+++ pbx.c	5 Jun 2005 16:32:16 -0000	1.252
@@ -913,7 +913,7 @@
 		headp=&c->varshead;
 	*ret=NULL;
 	if ((first=strchr(var,':'))) {	/* : Remove characters counting from end or start of string */
-		strncpy(tmpvar, var, sizeof(tmpvar) - 1);
+		ast_copy_string(tmpvar, var, sizeof(tmpvar));
 		first = strchr(tmpvar, ':');
 		if (!first)
 			first = tmpvar + strlen(tmpvar);
@@ -959,25 +959,25 @@
 						if (c->cid.cid_name) {
 							snprintf(workspace, workspacelen, "\"%s\" <%s>", c->cid.cid_name, c->cid.cid_num);
 						} else {
-							strncpy(workspace, c->cid.cid_num, workspacelen - 1);
+							ast_copy_string(workspace, c->cid.cid_num, workspacelen);
 						}
 						*ret = workspace;
 					} else if (c->cid.cid_name) {
-						strncpy(workspace, c->cid.cid_name, workspacelen - 1);
+						ast_copy_string(workspace, c->cid.cid_name, workspacelen);
 						*ret = workspace;
 					} else
 						*ret = NULL;
 				} else if (!strcmp(var + 8, "NUM")) {
 					/* CALLERIDNUM */
 					if (c->cid.cid_num) {
-						strncpy(workspace, c->cid.cid_num, workspacelen - 1);
+						ast_copy_string(workspace, c->cid.cid_num, workspacelen);
 						*ret = workspace;
 					} else
 						*ret = NULL;
 				} else if (!strcmp(var + 8, "NAME")) {
 					/* CALLERIDNAME */
 					if (c->cid.cid_name) {
-						strncpy(workspace, c->cid.cid_name, workspacelen - 1);
+						ast_copy_string(workspace, c->cid.cid_name, workspacelen);
 						*ret = workspace;
 					} else
 						*ret = NULL;
@@ -985,7 +985,7 @@
 			} else if (!strcmp(var + 6, "ANI")) {
 				/* CALLERANI */
 				if (c->cid.cid_ani) {
-					strncpy(workspace, c->cid.cid_ani, workspacelen - 1);
+					ast_copy_string(workspace, c->cid.cid_ani, workspacelen);
 					*ret = workspace;
 				} else
 					*ret = NULL;
@@ -1014,7 +1014,7 @@
 			goto icky;
 	} else if (c && !strcmp(var, "DNID")) {
 		if (c->cid.cid_dnid) {
-			strncpy(workspace, c->cid.cid_dnid, workspacelen - 1);
+			ast_copy_string(workspace, c->cid.cid_dnid, workspacelen);
 			*ret = workspace;
 		} else
 			*ret = NULL;
@@ -1029,22 +1029,22 @@
 		else
 			*ret = workspace;
 	} else if (c && !strcmp(var, "EXTEN")) {
-		strncpy(workspace, c->exten, workspacelen - 1);
+		ast_copy_string(workspace, c->exten, workspacelen);
 		*ret = workspace;
 	} else if (c && !strcmp(var, "RDNIS")) {
 		if (c->cid.cid_rdnis) {
-			strncpy(workspace, c->cid.cid_rdnis, workspacelen - 1);
+			ast_copy_string(workspace, c->cid.cid_rdnis, workspacelen);
 			*ret = workspace;
 		} else
 			*ret = NULL;
 	} else if (c && !strcmp(var, "CONTEXT")) {
-		strncpy(workspace, c->context, workspacelen - 1);
+		ast_copy_string(workspace, c->context, workspacelen);
 		*ret = workspace;
 	} else if (c && !strcmp(var, "PRIORITY")) {
 		snprintf(workspace, workspacelen, "%d", c->priority);
 		*ret = workspace;
 	} else if (c && !strcmp(var, "CHANNEL")) {
-		strncpy(workspace, c->name, workspacelen - 1);
+		ast_copy_string(workspace, c->name, workspacelen);
 		*ret = workspace;
 	} else if (!strcmp(var, "EPOCH")) {
 		snprintf(workspace, workspacelen, "%u",(int)time(NULL));
@@ -1081,10 +1081,10 @@
 		snprintf(workspace, workspacelen, "%d", c->hangupcause);
 		*ret = workspace;
 	} else if (c && !strcmp(var, "ACCOUNTCODE")) {
-		strncpy(workspace, c->accountcode, workspacelen - 1);
+		ast_copy_string(workspace, c->accountcode, workspacelen);
 		*ret = workspace;
 	} else if (c && !strcmp(var, "LANGUAGE")) {
-		strncpy(workspace, c->language, workspacelen - 1);
+		ast_copy_string(workspace, c->language, workspacelen);
 		*ret = workspace;
 	} else {
 icky:
@@ -1096,7 +1096,7 @@
 				if (strcasecmp(ast_var_name(variables),var)==0) {
 					*ret=ast_var_value(variables);
 					if (*ret) {
-						strncpy(workspace, *ret, workspacelen - 1);
+						ast_copy_string(workspace, *ret, workspacelen);
 						*ret = workspace;
 					}
 					break;
@@ -1112,7 +1112,7 @@
 				if (strcasecmp(ast_var_name(variables),var)==0) {
 					*ret=ast_var_value(variables);
 					if (*ret) {
-						strncpy(workspace, *ret, workspacelen - 1);
+						ast_copy_string(workspace, *ret, workspacelen);
 						*ret = workspace;
 					}
 				}
@@ -1444,7 +1444,7 @@
 
 			/* Store variable name (and truncate) */
 			memset(var, 0, sizeof(var));
-			strncpy(var, vars, sizeof(var) - 1);
+			ast_copy_string(var, vars, sizeof(var));
 			var[len] = '\0';
 
 			/* Substitute if necessary */
@@ -1508,7 +1508,7 @@
 			
 			/* Store variable name (and truncate) */
 			memset(var, 0, sizeof(var));
-			strncpy(var, vars, sizeof(var) - 1);
+			ast_copy_string(var, vars, sizeof(var));
 			var[len] = '\0';
 			
 			/* Substitute if necessary */
@@ -1555,7 +1555,7 @@
 		
 	/* No variables or expressions in e->data, so why scan it? */
 	if (!strstr(e->data,"${") && !strstr(e->data,"$[") && !strstr(e->data,"$(")) {
-		strncpy(passdata, e->data, datalen - 1);
+		ast_copy_string(passdata, e->data, datalen);
 		passdata[datalen-1] = '\0';
 		return;
 	}
@@ -1613,9 +1613,9 @@
 			ast_mutex_unlock(&conlock);
 			if (app) {
 				if (c->context != context)
-					strncpy(c->context, context, sizeof(c->context)-1);
+					ast_copy_string(c->context, context, sizeof(c->context));
 				if (c->exten != exten)
-					strncpy(c->exten, exten, sizeof(c->exten)-1);
+					ast_copy_string(c->exten, exten, sizeof(c->exten));
 				c->priority = priority;
 				pbx_substitute_variables(passdata, sizeof(passdata), c, e);
 				if (option_debug) {
@@ -1741,7 +1741,7 @@
 	if (!e)
 		return -1;
 
-	strncpy(hint, ast_get_extension_app(e), sizeof(hint)-1);
+	ast_copy_string(hint, ast_get_extension_app(e), sizeof(hint));
 
 	cur = hint;    	/* On or more devices separated with a & character */
 	do {
@@ -1845,7 +1845,7 @@
 
 	while (list) {
 
-		strncpy(hint, ast_get_extension_app(list->exten), sizeof(hint) - 1);
+		ast_copy_string(hint, ast_get_extension_app(list->exten), sizeof(hint));
 		cur = hint;
 		do {
 			rest = strchr(cur, '&');
@@ -2186,14 +2186,15 @@
 {
 	struct ast_exten *e;
 	void *tmp;
+
 	e = ast_hint_extension(c, context, exten);
 	if (e) {
 		if (hint) 
-		    strncpy(hint, ast_get_extension_app(e), hintsize - 1);
+		    ast_copy_string(hint, ast_get_extension_app(e), hintsize);
 		if (name) {
 			tmp = ast_get_extension_app_data(e);
 			if (tmp)
-				strncpy(name, (char *)tmp, namesize - 1);
+				ast_copy_string(name, (char *) tmp, namesize);
 		}
 	    return -1;
 	}
@@ -2277,12 +2278,12 @@
 		/* If not successful fall back to 's' */
 		if (option_verbose > 1)
 			ast_verbose( VERBOSE_PREFIX_2 "Starting %s at %s,%s,%d failed so falling back to exten 's'\n", c->name, c->context, c->exten, c->priority);
-		strncpy(c->exten, "s", sizeof(c->exten)-1);
+		ast_copy_string(c->exten, "s", sizeof(c->exten));
 		if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
 			/* JK02: And finally back to default if everything else failed */
 			if (option_verbose > 1)
 				ast_verbose( VERBOSE_PREFIX_2 "Starting %s at %s,%s,%d still failed so falling back to context 'default'\n", c->name, c->context, c->exten, c->priority);
-			strncpy(c->context, "default", sizeof(c->context)-1);
+			ast_copy_string(c->context, "default", sizeof(c->context));
 		}
 		c->priority = 1;
 	}
@@ -2332,7 +2333,7 @@
 				}
 			}
 			if ((c->_softhangup == AST_SOFTHANGUP_TIMEOUT) && (ast_exists_extension(c,c->context,"T",1,c->cid.cid_num))) {
-				strncpy(c->exten,"T",sizeof(c->exten) - 1);
+				ast_copy_string(c->exten, "T", sizeof(c->exten));
 				/* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
 				c->whentohangup = 0;
 				c->priority = 0;
@@ -2351,7 +2352,7 @@
 				if (option_verbose > 2)
 					ast_verbose(VERBOSE_PREFIX_3 "Sent into invalid extension '%s' in context '%s' on %s\n", c->exten, c->context, c->name);
 				pbx_builtin_setvar_helper(c, "INVALID_EXTEN", c->exten);
-				strncpy(c->exten, "i", sizeof(c->exten)-1);
+				ast_copy_string(c->exten, "i", sizeof(c->exten));
 				c->priority = 1;
 			} else {
 				ast_log(LOG_WARNING, "Channel '%s' sent into invalid extension '%s' in context '%s', but no invalid handler\n",
@@ -2388,7 +2389,7 @@
 				}
 				if (ast_exists_extension(c, c->context, exten, 1, c->cid.cid_num)) {
 					/* Prepare the next cycle */
-					strncpy(c->exten, exten, sizeof(c->exten)-1);
+					ast_copy_string(c->exten, exten, sizeof(c->exten));
 					c->priority = 1;
 				} else {
 					/* No such extension */
@@ -2398,7 +2399,7 @@
 							if (option_verbose > 2)
 								ast_verbose( VERBOSE_PREFIX_3 "Invalid extension '%s' in context '%s' on %s\n", exten, c->context, c->name);
 							pbx_builtin_setvar_helper(c, "INVALID_EXTEN", exten);
-							strncpy(c->exten, "i", sizeof(c->exten)-1);
+							ast_copy_string(c->exten, "i", sizeof(c->exten));
 							c->priority = 1;
 						} else {
 							ast_log(LOG_WARNING, "Invalid extension '%s', but no rule 'i' in context '%s'\n", exten, c->context);
@@ -2409,7 +2410,7 @@
 						if (ast_exists_extension(c, c->context, "t", 1, c->cid.cid_num)) {
 							if (option_verbose > 2)
 								ast_verbose( VERBOSE_PREFIX_3 "Timeout on %s\n", c->name);
-							strncpy(c->exten, "t", sizeof(c->exten)-1);
+							ast_copy_string(c->exten, "t", sizeof(c->exten));
 							c->priority = 1;
 						} else {
 							ast_log(LOG_WARNING, "Timeout, but no rule 't' in context '%s'\n", c->context);
@@ -3941,7 +3942,7 @@
 	if (ast_strlen_zero(info_in))
 		return 0;
 	/* make a copy just in case we were passed a static string */
-	strncpy(info_save, info_in, sizeof(info_save));
+	ast_copy_string(info_save, info_in, sizeof(info_save));
 	info = info_save;
 	/* Assume everything except time */
 	i->monthmask = (1 << 12) - 1;
@@ -4385,9 +4386,9 @@
 		return -1;
 
 	if (context && !ast_strlen_zero(context))
-		strncpy(chan->context, context, sizeof(chan->context) - 1);
+		ast_copy_string(chan->context, context, sizeof(chan->context));
 	if (exten && !ast_strlen_zero(exten))
-		strncpy(chan->exten, exten, sizeof(chan->exten) - 1);
+		ast_copy_string(chan->exten, exten, sizeof(chan->exten));
 	if (priority > -1) {
 		chan->priority = priority;
 		/* see flag description in channel.h for explanation */
@@ -4769,9 +4770,9 @@
 				ast_log(LOG_WARNING, "No such application '%s'\n", as->app);
 		} else {
 			if (!ast_strlen_zero(as->context))
-				strncpy(chan->context, as->context, sizeof(chan->context) - 1);
+				ast_copy_string(chan->context, as->context, sizeof(chan->context));
 			if (!ast_strlen_zero(as->exten))
-				strncpy(chan->exten, as->exten, sizeof(chan->exten) - 1);
+				ast_copy_string(chan->exten, as->exten, sizeof(chan->exten));
 			if (as->priority > 0)
 				chan->priority = as->priority;
 			/* Run the PBX */
@@ -4911,10 +4912,10 @@
 			if (ast_exists_extension(chan, context, "failed", 1, NULL)) {
 				chan = ast_channel_alloc(0);
 				if(chan) {
-					strncpy(chan->name, "OutgoingSpoolFailed", sizeof(chan->name) - 1);
+					ast_copy_string(chan->name, "OutgoingSpoolFailed", sizeof(chan->name));
 					if (context && !ast_strlen_zero(context))
-						strncpy(chan->context, context, sizeof(chan->context) - 1);
-					strncpy(chan->exten, "failed", sizeof(chan->exten) - 1);
+						ast_copy_string(chan->context, context, sizeof(chan->context));
+					ast_copy_string(chan->exten, "failed", sizeof(chan->exten));
 					chan->priority = 1;
 					if (variable) {
 						tmp = ast_strdupa(variable);
@@ -4945,8 +4946,8 @@
 		if (account)
 			ast_cdr_setaccount(chan, account);
 		as->chan = chan;
-		strncpy(as->context, context, sizeof(as->context) - 1);
-		strncpy(as->exten,  exten, sizeof(as->exten) - 1);
+		ast_copy_string(as->context, context, sizeof(as->context));
+		ast_copy_string(as->exten,  exten, sizeof(as->exten));
 		as->priority = priority;
 		as->timeout = timeout;
 		if (variable) {
@@ -5037,7 +5038,7 @@
 				tmp = malloc(sizeof(struct app_tmp));
 				if (tmp) {
 					memset(tmp, 0, sizeof(struct app_tmp));
-					strncpy(tmp->app, app, sizeof(tmp->app) - 1);
+					ast_copy_string(tmp->app, app, sizeof(tmp->app));
 					if (appdata)
 						ast_copy_string(tmp->data, appdata, sizeof(tmp->data));
 					tmp->chan = chan;
@@ -5101,9 +5102,9 @@
 		if (account)
 			ast_cdr_setaccount(chan, account);
 		as->chan = chan;
-		strncpy(as->app, app, sizeof(as->app) - 1);
+		ast_copy_string(as->app, app, sizeof(as->app));
 		if (appdata)
-			strncpy(as->appdata,  appdata, sizeof(as->appdata) - 1);
+			ast_copy_string(as->appdata,  appdata, sizeof(as->appdata));
 		as->timeout = timeout;
 		if (variable) {
 			vartmp = ast_strdupa(variable);
@@ -5290,7 +5291,7 @@
 
 	/* Copy the language as specified */
 	if (data)
-		strncpy(chan->language, (char *)data, sizeof(chan->language)-1);
+		ast_copy_string(chan->language, (char *) data, sizeof(chan->language));
 
 	return 0;
 }
@@ -5347,9 +5348,9 @@
 		return 0;
 	}
 	if (strlen(chan->exten) > atoi(data)) {
-		strncpy(newexten, chan->exten + atoi(data), sizeof(newexten)-1);
+		ast_copy_string(newexten, chan->exten + atoi(data), sizeof(newexten));
 	}
-	strncpy(chan->exten, newexten, sizeof(chan->exten)-1);
+	ast_copy_string(chan->exten, newexten, sizeof(chan->exten));
 	return 0;
 }
 
@@ -5362,7 +5363,7 @@
 		return 0;
 	}
 	snprintf(newexten, sizeof(newexten), "%s%s", (char *)data, chan->exten);
-	strncpy(chan->exten, newexten, sizeof(chan->exten)-1);
+	ast_copy_string(chan->exten, newexten, sizeof(chan->exten));
 	if (option_verbose > 2)
 		ast_verbose(VERBOSE_PREFIX_3 "Prepended prefix, new extension is %s\n", chan->exten);
 	return 0;
@@ -5377,7 +5378,7 @@
 		return 0;
 	}
 	snprintf(newexten, sizeof(newexten), "%s%s", chan->exten, (char *)data);
-	strncpy(chan->exten, newexten, sizeof(chan->exten)-1);
+	ast_copy_string(chan->exten, newexten, sizeof(chan->exten));
 	if (option_verbose > 2)
 		ast_verbose(VERBOSE_PREFIX_3 "Appended suffix, new extension is %s\n", chan->exten);
 	return 0;
@@ -5514,7 +5515,7 @@
 		} else if (ast_exists_extension(chan, chan->context, "t", 1, chan->cid.cid_num)) {
 			if (option_verbose > 2)
 				ast_verbose(VERBOSE_PREFIX_3 "Timeout on %s, going to 't'\n", chan->name);
-			strncpy(chan->exten, "t", sizeof(chan->exten));
+			ast_copy_string(chan->exten, "t", sizeof(chan->exten));
 			chan->priority = 0;
 		} else {
 			ast_log(LOG_WARNING, "Timeout but no rule 't' in context '%s'\n", chan->context);
@@ -5916,7 +5917,7 @@
 		ast_log(LOG_WARNING, "SayNumber requires an argument (number)\n");
 		return -1;
 	}
-	strncpy(tmp, (char *)data, sizeof(tmp)-1);
+	ast_copy_string(tmp, (char *) data, sizeof(tmp));
 	number=tmp;
 	strsep(&number, "|");
 	options = strsep(&number, "|");




More information about the svn-commits mailing list