[svn-commits] kpfleming: branch 1.4 r46200 - in /branches/1.4: apps/ cdr/ channels/ main/ p...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Oct 25 07:32:08 MST 2006


Author: kpfleming
Date: Wed Oct 25 09:32:08 2006
New Revision: 46200

URL: http://svn.digium.com/view/asterisk?rev=46200&view=rev
Log:
apparently developers are still not aware that they should be use ast_copy_string instead of strncpy... fix up many more users, and fix some bugs in the process

Modified:
    branches/1.4/apps/app_getcpeid.c
    branches/1.4/apps/app_ices.c
    branches/1.4/apps/app_parkandannounce.c
    branches/1.4/apps/app_queue.c
    branches/1.4/apps/app_record.c
    branches/1.4/apps/app_rpt.c
    branches/1.4/apps/app_sms.c
    branches/1.4/apps/app_softhangup.c
    branches/1.4/apps/app_voicemail.c
    branches/1.4/cdr/cdr_custom.c
    branches/1.4/channels/chan_alsa.c
    branches/1.4/channels/chan_features.c
    branches/1.4/channels/chan_h323.c
    branches/1.4/channels/chan_iax2.c
    branches/1.4/channels/chan_mgcp.c
    branches/1.4/channels/chan_nbs.c
    branches/1.4/channels/chan_phone.c
    branches/1.4/channels/chan_sip.c
    branches/1.4/main/cdr.c
    branches/1.4/main/cli.c
    branches/1.4/main/db.c
    branches/1.4/main/image.c
    branches/1.4/main/utils.c
    branches/1.4/pbx/dundi-parser.c
    branches/1.4/pbx/pbx_ael.c
    branches/1.4/pbx/pbx_realtime.c
    branches/1.4/pbx/pbx_spool.c
    branches/1.4/res/res_adsi.c

Modified: branches/1.4/apps/app_getcpeid.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_getcpeid.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/apps/app_getcpeid.c (original)
+++ branches/1.4/apps/app_getcpeid.c Wed Oct 25 09:32:08 2006
@@ -71,21 +71,20 @@
 	int gotgeometry = 0;
 	int gotcpeid = 0;
 	int width, height, buttons;
-	char data[4][80];
-	char *stuff[4];
+	char *data[4];
+	unsigned int x;
 
 	u = ast_module_user_add(chan);
-	stuff[0] = data[0];
-	stuff[1] = data[1];
-	stuff[2] = data[2];
-	stuff[3] = data[3];
-	memset(data, 0, sizeof(data));
-	strncpy(stuff[0], "** CPE Info **", sizeof(data[0]) - 1);
-	strncpy(stuff[1], "Identifying CPE...", sizeof(data[1]) - 1);
-	strncpy(stuff[2], "Please wait...", sizeof(data[2]) - 1);
+
+	for (x = 0; x < 4; x++)
+		data[x] = alloca(80);
+
+	strcpy(data[0], "** CPE Info **");
+	strcpy(data[1], "Identifying CPE...");
+	strcpy(data[2], "Please wait...");
 	res = ast_adsi_load_session(chan, NULL, 0, 1);
 	if (res > 0) {
-		cpeid_setstatus(chan, stuff, 0);
+		cpeid_setstatus(chan, data, 0);
 		res = ast_adsi_get_cpeid(chan, cpeid, 0);
 		if (res > 0) {
 			gotcpeid = 1;
@@ -93,9 +92,9 @@
 				ast_verbose(VERBOSE_PREFIX_3 "Got CPEID of '%02x:%02x:%02x:%02x' on '%s'\n", cpeid[0], cpeid[1], cpeid[2], cpeid[3], chan->name);
 		}
 		if (res > -1) {
-			strncpy(stuff[1], "Measuring CPE...", sizeof(data[1]) - 1);
-			strncpy(stuff[2], "Please wait...", sizeof(data[2]) - 1);
-			cpeid_setstatus(chan, stuff, 0);
+			strcpy(data[1], "Measuring CPE...");
+			strcpy(data[2], "Please wait...");
+			cpeid_setstatus(chan, data, 0);
 			res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
 			if (res > -1) {
 				if (option_verbose > 2)
@@ -105,15 +104,15 @@
 		}
 		if (res > -1) {
 			if (gotcpeid)
-				snprintf(stuff[1], sizeof(data[1]), "CPEID: %02x:%02x:%02x:%02x", cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
+				snprintf(data[1], 80, "CPEID: %02x:%02x:%02x:%02x", cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
 			else
-				strncpy(stuff[1], "CPEID Unknown", sizeof(data[1]) - 1);
+				strcpy(data[1], "CPEID Unknown");
 			if (gotgeometry) 
-				snprintf(stuff[2], sizeof(data[2]), "Geom: %dx%d, %d buttons", width, height, buttons);
+				snprintf(data[2], 80, "Geom: %dx%d, %d buttons", width, height, buttons);
 			else
-				strncpy(stuff[2], "Geometry unknown", sizeof(data[2]) - 1);
-			strncpy(stuff[3], "Press # to exit", sizeof(data[3]) - 1);
-			cpeid_setstatus(chan, stuff, 1);
+				strcpy(data[2], "Geometry unknown");
+			strcpy(data[3], "Press # to exit");
+			cpeid_setstatus(chan, data, 1);
 			for(;;) {
 				res = ast_waitfordigit(chan, 1000);
 				if (res < 0)

Modified: branches/1.4/apps/app_ices.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_ices.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/apps/app_ices.c (original)
+++ branches/1.4/apps/app_ices.c Wed Oct 25 09:32:08 2006
@@ -141,7 +141,7 @@
 		return -1;
 	}
 	if (((char *)data)[0] == '/')
-		strncpy(filename, (char *)data, sizeof(filename) - 1);
+		ast_copy_string(filename, (char *) data, sizeof(filename));
 	else
 		snprintf(filename, sizeof(filename), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, (char *)data);
 	/* Placeholder for options */		

Modified: branches/1.4/apps/app_parkandannounce.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_parkandannounce.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/apps/app_parkandannounce.c (original)
+++ branches/1.4/apps/app_parkandannounce.c Wed Oct 25 09:32:08 2006
@@ -78,13 +78,13 @@
 {
 	int res=0;
 	char *return_context;
-	int l, lot, timeout = 0, dres;
+	int lot, timeout = 0, dres;
 	char *working, *context, *exten, *priority, *dial, *dialtech, *dialstr;
 	char *template, *tpl_working, *tpl_current;
 	char *tmp[100];
 	char buf[13];
 	int looptemp=0,i=0;
-	char *s,*orig_s;
+	char *s;
 
 	struct ast_channel *dchan;
 	struct outgoing_helper oh;
@@ -99,18 +99,11 @@
   
 	u = ast_module_user_add(chan);
 
-	l=strlen(data)+2;	
-	if (!(orig_s = ast_malloc(l))) {
-		ast_module_user_remove(u);
-		return -1;
-	}
-	s=orig_s;
-	strncpy(s,data,l);
+	s = ast_strdupa(data);
 
 	template=strsep(&s,"|");
 	if(! template) {
 		ast_log(LOG_WARNING, "PARK: An announce template must be defined\n");
-		free(orig_s);
 		ast_module_user_remove(u);
 		return -1;
 	}
@@ -122,7 +115,6 @@
 	dial=strsep(&s, "|");
 	if(!dial) {
 		ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or Zap/g1/5551212\n");
-		free(orig_s);
 		ast_module_user_remove(u);
 		return -1;
 	} else {
@@ -155,16 +147,15 @@
 	}
 	if(atoi(priority) < 0) {
 		ast_log(LOG_WARNING, "Priority '%s' must be a number > 0\n", priority);
-		free(orig_s);
 		ast_module_user_remove(u);
 		return -1;
 	}
 	/* At this point we have a priority and maybe an extension and a context */
 	chan->priority = atoi(priority);
 	if (exten)
-		strncpy(chan->exten, exten, sizeof(chan->exten)-1);
+		ast_copy_string(chan->exten, exten, sizeof(chan->exten));
 	if (context)
-		strncpy(chan->context, context, sizeof(chan->context)-1);
+		ast_copy_string(chan->context, context, sizeof(chan->context));
 	} else {  /* increment the priority by default*/
 		chan->priority++;
 	}
@@ -202,13 +193,11 @@
 				ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", dchan->name);
         			ast_log(LOG_WARNING, "PARK: Channel %s was never answered for the announce.\n", dchan->name);
 			ast_hangup(dchan);
-			free(orig_s);
 			ast_module_user_remove(u);
 			return -1;
 		}
 	} else {
 		ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n");
-		free(orig_s);
 		ast_module_user_remove(u);
 		return -1; 
 	}
@@ -245,7 +234,6 @@
 
 	ast_stopstream(dchan);  
 	ast_hangup(dchan);
-	free(orig_s);
 	
 	ast_module_user_remove(u);
 	

Modified: branches/1.4/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_queue.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/apps/app_queue.c (original)
+++ branches/1.4/apps/app_queue.c Wed Oct 25 09:32:08 2006
@@ -776,10 +776,6 @@
    extra fields in the tables. */
 static void queue_set_param(struct call_queue *q, const char *param, const char *val, int linenum, int failunknown)
 {
-	int i = 0;
-	char *c, *lastc;
-	char buff[80];
-
 	if (!strcasecmp(param, "musicclass") || 
 		!strcasecmp(param, "music") || !strcasecmp(param, "musiconhold")) {
 		ast_copy_string(q->moh, val, sizeof(q->moh));
@@ -840,22 +836,18 @@
 		else
 			q->announceholdtime = 0;
 	} else if (!strcasecmp(param, "periodic-announce")) {
-		if (strchr(val,'|')) {
-			lastc = (char *)val;
-			while ((c = strchr(lastc,'|'))) {
-				if (i > MAX_PERIODIC_ANNOUNCEMENTS)
+		if (strchr(val, '|')) {
+			char *s, *buf = ast_strdupa(val);
+			unsigned int i = 0;
+
+			while ((s = strsep(&buf, "|"))) {
+				ast_copy_string(q->sound_periodicannounce[i], s, sizeof(q->sound_periodicannounce[i]));
+				i++;
+				if (i == MAX_PERIODIC_ANNOUNCEMENTS)
 					break;
-				strncpy(buff, lastc, abs(lastc - c));
-				buff[abs(lastc - c)] = '\0';
-				ast_copy_string(q->sound_periodicannounce[i], buff, sizeof(q->sound_periodicannounce[i]));
-				lastc = (c + 1);
-				i++;
-			}
-			if (strlen(lastc)) {
-				ast_copy_string(q->sound_periodicannounce[i], lastc, sizeof(q->sound_periodicannounce[i]));
 			}
 		} else {
-			ast_copy_string(q->sound_periodicannounce[i], val, sizeof(q->sound_periodicannounce[i]));
+			ast_copy_string(q->sound_periodicannounce[0], val, sizeof(q->sound_periodicannounce[0]));
 		}
 	} else if (!strcasecmp(param, "periodic-announce-frequency")) {
 		q->periodicannouncefrequency = atoi(val);

Modified: branches/1.4/apps/app_record.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_record.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/apps/app_record.c (original)
+++ branches/1.4/apps/app_record.c Wed Oct 25 09:32:08 2006
@@ -212,7 +212,7 @@
 		} while (ast_fileexists(tmp, ext, chan->language) > 0);
 		pbx_builtin_setvar_helper(chan, "RECORDED_FILE", tmp);
 	} else
-		strncpy(tmp, filename, sizeof(tmp)-1);
+		ast_copy_string(tmp, filename, sizeof(tmp));
 	/* end of routine mentioned */
 	
 	

Modified: branches/1.4/apps/app_rpt.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_rpt.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/apps/app_rpt.c (original)
+++ branches/1.4/apps/app_rpt.c Wed Oct 25 09:32:08 2006
@@ -1425,7 +1425,7 @@
 					return RESULT_FAILURE;
 				}
 				memset(s, 0, sizeof(struct rpt_lstat));
-				strncpy(s->name, l->name, MAXREMSTR - 1);
+				ast_copy_string(s->name, l->name, MAXREMSTR);
 				pbx_substitute_variables_helper(l->chan, "${IAXPEER(CURRENTCHANNEL)}", s->peer, MAXPEERSTR - 1);
 				s->mode = l->mode;
 				s->outbound = l->outbound;
@@ -2606,8 +2606,7 @@
 		}
 	}
 	else if ((mode == ARB_ALPHA) || (mode == REV_PATCH)) {
-		strncpy(tele->param, (char *) data, TELEPARAMSIZE - 1);
-		tele->param[TELEPARAMSIZE - 1] = 0;
+		ast_copy_string(tele->param, (char *) data, TELEPARAMSIZE);
 	}
 	insque((struct qelem *)tele, (struct qelem *)myrpt->tele.next);
 	rpt_mutex_unlock(&myrpt->lock);
@@ -2782,11 +2781,11 @@
 		}
 	}
 
-	strncpy(mychannel->exten, myrpt->exten, sizeof(mychannel->exten) - 1);
-	strncpy(mychannel->context, myrpt->patchcontext, sizeof(mychannel->context) - 1);
+	ast_copy_string(mychannel->exten, myrpt->exten, sizeof(mychannel->exten));
+	ast_copy_string(mychannel->context, myrpt->patchcontext, sizeof(mychannel->context));
 	
 	if (myrpt->p.acctcode)
-		strncpy((char *)mychannel->accountcode, myrpt->p.acctcode, sizeof(mychannel->accountcode) - 1);
+		ast_string_field_set(mychannel, accountcode, myrpt->p.acctcode);
 	mychannel->priority = 1;
 	ast_channel_undefer_dtmf(mychannel);
 	if (ast_pbx_start(mychannel) < 0)
@@ -2938,7 +2937,7 @@
 	if (!myrpt->enable)
 		return DC_ERROR;
 
-	strncpy(digitbuf,digits,MAXNODESTR - 1);
+	ast_copy_string(digitbuf,digits,MAXNODESTR);
 
 	if(debug)
 		printf("@@@@ ilink param = %s, digitbuf = %s\n", (param)? param : "(null)", digitbuf);
@@ -2953,7 +2952,7 @@
 					return DC_ERROR;
 				break;
 			}
-			strncpy(tmp,val,sizeof(tmp) - 1);
+			ast_copy_string(tmp,val,sizeof(tmp));
 			s = tmp;
 			s1 = strsep(&s,",");
 			s2 = strsep(&s,",");
@@ -2973,7 +2972,7 @@
 			}
 			if (l != &myrpt->links){ /* if found */
 				struct	ast_frame wf;
-				strncpy(myrpt->lastlinknode,digitbuf,MAXNODESTR - 1);
+				ast_copy_string(myrpt->lastlinknode,digitbuf,MAXNODESTR);
 				l->retries = MAX_RETRIES + 1;
 				l->disced = 1;
 				rpt_mutex_unlock(&myrpt->lock);
@@ -3004,7 +3003,7 @@
 					return DC_ERROR;
 				break;
 			}
-			strncpy(tmp,val,sizeof(tmp) - 1);
+			ast_copy_string(tmp, val, sizeof(tmp));
 			s = tmp;
 			s1 = strsep(&s,",");
 			s2 = strsep(&s,",");
@@ -3040,7 +3039,7 @@
 				modechange = 1;
 			} else
 				rpt_mutex_unlock(&myrpt->lock);
-			strncpy(myrpt->lastlinknode,digitbuf,MAXNODESTR - 1);
+			ast_copy_string(myrpt->lastlinknode,digitbuf,MAXNODESTR);
 			/* establish call in monitor mode */
 			l = malloc(sizeof(struct rpt_link));
 			if (!l){
@@ -3057,7 +3056,7 @@
 			}
 			*tele++ = 0;
 			l->isremote = (s && ast_true(s));
-			strncpy(l->name, digitbuf, MAXNODESTR - 1);
+			ast_copy_string(l->name, digitbuf, MAXNODESTR);
 			l->chan = ast_request(deststr,AST_FORMAT_SLINEAR,tele,NULL);
 			if (modechange) l->connected = 1;
 			if (l->chan){
@@ -3122,7 +3121,7 @@
 					return DC_ERROR;
 				break;
 			}
-			strncpy(tmp,val,sizeof(tmp) - 1);
+			ast_copy_string(tmp,val,sizeof(tmp));
 			s = tmp;
 			s1 = strsep(&s,",");
 			s2 = strsep(&s,",");
@@ -3156,7 +3155,7 @@
 				modechange = 1;
 			} else
 				rpt_mutex_unlock(&myrpt->lock);
-			strncpy(myrpt->lastlinknode,digitbuf,MAXNODESTR - 1);
+			ast_copy_string(myrpt->lastlinknode,digitbuf,MAXNODESTR);
 			/* establish call in tranceive mode */
 			l = malloc(sizeof(struct rpt_link));
 			if (!l){
@@ -3167,7 +3166,7 @@
 			memset((char *)l,0,sizeof(struct rpt_link));
 			l->mode = 1;
 			l->outbound = 1;
-			strncpy(l->name, digitbuf, MAXNODESTR - 1);
+			ast_copy_string(l->name, digitbuf, MAXNODESTR);
 			l->isremote = (s && ast_true(s));
 			if (modechange) l->connected = 1;
 			snprintf(deststr, sizeof(deststr), "IAX2/%s", s1);
@@ -3255,7 +3254,7 @@
 			}
 			rpt_mutex_lock(&myrpt->lock);
 			strcpy(myrpt->lastlinknode,digitbuf);
-			strncpy(myrpt->cmdnode, digitbuf, sizeof(myrpt->cmdnode) - 1);
+			ast_copy_string(myrpt->cmdnode, digitbuf, sizeof(myrpt->cmdnode));
 			rpt_mutex_unlock(&myrpt->lock);
 			rpt_telemetry(myrpt, REMGO, NULL);	
 			return DC_COMPLETE;
@@ -3320,7 +3319,7 @@
 		myrpt->patchdialtime = 0;
 		myrpt->patchfarenddisconnect = 0;
 		myrpt->patchquiet = 0;
-		strncpy(myrpt->patchcontext, myrpt->p.ourcontext, MAXPATCHCONTEXT);
+		ast_copy_string(myrpt->patchcontext, myrpt->p.ourcontext, MAXPATCHCONTEXT);
 
 		if(param){
 			/* Process parameter list */
@@ -3337,7 +3336,7 @@
 				switch(index){
 
 					case 1: /* context */
-						strncpy(myrpt->patchcontext, value, MAXPATCHCONTEXT - 1) ;
+						ast_copy_string(myrpt->patchcontext, value, MAXPATCHCONTEXT) ;
 						break;
 						
 					case 2: /* dialtime */
@@ -3545,16 +3544,16 @@
 	
 	if (command_source == SOURCE_DPHONE) {
 		if (!myrpt->p.dphone_functions) return DC_INDETERMINATE;
-		strncpy(function_table_name, myrpt->p.dphone_functions, sizeof(function_table_name) - 1);
+		ast_copy_string(function_table_name, myrpt->p.dphone_functions, sizeof(function_table_name));
 		}
 	else if (command_source == SOURCE_PHONE) {
 		if (!myrpt->p.phone_functions) return DC_INDETERMINATE;
-		strncpy(function_table_name, myrpt->p.phone_functions, sizeof(function_table_name) - 1);
+		ast_copy_string(function_table_name, myrpt->p.phone_functions, sizeof(function_table_name));
 		}
 	else if (command_source == SOURCE_LNK)
-		strncpy(function_table_name, myrpt->p.link_functions, sizeof(function_table_name) - 1);
+		ast_copy_string(function_table_name, myrpt->p.link_functions, sizeof(function_table_name));
 	else
-		strncpy(function_table_name, myrpt->p.functions, sizeof(function_table_name) - 1);
+		ast_copy_string(function_table_name, myrpt->p.functions, sizeof(function_table_name));
 	vp = ast_variable_browse(myrpt->cfg, function_table_name);
 	while(vp) {
 		if(!strncasecmp(vp->name, digits, strlen(vp->name)))
@@ -3577,7 +3576,7 @@
 			return DC_INDETERMINATE;
 	}	
 	/* Found a match, retrieve value part and parse */
-	strncpy(workstring, vp->value, sizeof(workstring) - 1 );
+	ast_copy_string(workstring, vp->value, sizeof(workstring));
 	stringp = workstring;
 	action = strsep(&stringp, ",");
 	param = stringp;
@@ -3620,7 +3619,7 @@
 	wf.datalen = strlen(str) + 1;
 	wf.samples = 0;
  	/* put string in our buffer */
-	strncpy(tmp,str,sizeof(tmp) - 1);
+	ast_copy_string(tmp, str, sizeof(tmp));
 
         if (!strcmp(tmp,discstr))
         {
@@ -3743,7 +3742,7 @@
 			myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
 			
 			rpt_mutex_unlock(&myrpt->lock);
-			strncpy(cmd, myrpt->rem_dtmfbuf, sizeof(cmd) - 1);
+			ast_copy_string(cmd, myrpt->rem_dtmfbuf, sizeof(cmd));
 			res = collect_function_digits(myrpt, cmd, SOURCE_LNK, mylink);
 			rpt_mutex_lock(&myrpt->lock);
 			
@@ -3761,7 +3760,7 @@
 				case DC_COMPLETE:
 					myrpt->totalexecdcommands++;
 					myrpt->dailyexecdcommands++;
-					strncpy(myrpt->lastdtmfcommand, cmd, MAXDTMF-1);
+					ast_copy_string(myrpt->lastdtmfcommand, cmd, MAXDTMF);
 					myrpt->lastdtmfcommand[MAXDTMF-1] = '\0';
 					myrpt->rem_dtmfbuf[0] = 0;
 					myrpt->rem_dtmfidx = -1;
@@ -3857,7 +3856,7 @@
 			myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
 			
 			rpt_mutex_unlock(&myrpt->lock);
-			strncpy(cmd, myrpt->rem_dtmfbuf, sizeof(cmd) - 1);
+			ast_copy_string(cmd, myrpt->rem_dtmfbuf, sizeof(cmd));
 			switch(mylink->phonemode)
 			{
 			    case 1:
@@ -3894,7 +3893,7 @@
 				case DC_COMPLETE:
 					myrpt->totalexecdcommands++;
 					myrpt->dailyexecdcommands++;
-					strncpy(myrpt->lastdtmfcommand, cmd, MAXDTMF-1);
+					ast_copy_string(myrpt->lastdtmfcommand, cmd, MAXDTMF);
 					myrpt->lastdtmfcommand[MAXDTMF-1] = '\0';
 					myrpt->rem_dtmfbuf[0] = 0;
 					myrpt->rem_dtmfidx = -1;
@@ -4165,7 +4164,7 @@
 	if (!myrpt->remote) return(0);
 	/* must have rbi hardware */
 	if (strncmp(myrpt->remote,remote_rig_rbi,3)) return(0);
-	strncpy(tmp, myrpt->freq, sizeof(tmp) - 1);
+	ast_copy_string(tmp, myrpt->freq, sizeof(tmp));
 	s = strchr(tmp,'.');
 	/* if no decimal, is invalid */
 	
@@ -4293,16 +4292,14 @@
  
 static int split_freq(char *mhz, char *decimals, char *freq)
 {
-	char freq_copy[MAXREMSTR];
 	char *decp;
 
-	decp = strchr(strncpy(freq_copy, freq, MAXREMSTR),'.');
-	if(decp){
+	freq = ast_strdupa(freq);
+	if ((decp = strchr(freq, '.'))) {
 		*decp++ = 0;
-		strncpy(mhz, freq_copy, MAXREMSTR);
+		ast_copy_string(mhz, freq, MAXREMSTR);
 		strcpy(decimals, "00000");
-		strncpy(decimals, decp, strlen(decp));
-		decimals[5] = 0;
+		ast_copy_string(decimals, decp, 6);
 		return 0;
 	}
 	else
@@ -4316,15 +4313,13 @@
  
 static int split_ctcss_freq(char *hertz, char *decimal, char *freq)
 {
-	char freq_copy[MAXREMSTR];
 	char *decp;
 
-	decp = strchr(strncpy(freq_copy, freq, MAXREMSTR),'.');
-	if(decp){
+	freq = ast_strdupa(freq);
+	if ((decp = strchr(freq, '.'))) {
 		*decp++ = 0;
-		strncpy(hertz, freq_copy, MAXREMSTR);
-		strncpy(decimal, decp, strlen(decp));
-		decimal[strlen(decp)] = '\0';
+		ast_copy_string(hertz, freq, MAXREMSTR);
+		ast_copy_string(decimal, decp, sizeof(decimal));
 		return 0;
 	}
 	else
@@ -4966,9 +4961,9 @@
 			if (!s1)
 				return DC_ERROR;
 			*s1++ = 0;
-			strncpy(myrpt->freq, tmp, sizeof(myrpt->freq) - 1);
-			strncpy(myrpt->rxpl, s, sizeof(myrpt->rxpl) - 1);
-			strncpy(myrpt->txpl, s, sizeof(myrpt->rxpl) - 1);
+			ast_copy_string(myrpt->freq, tmp, sizeof(myrpt->freq));
+			ast_copy_string(myrpt->rxpl, s, sizeof(myrpt->rxpl));
+			ast_copy_string(myrpt->txpl, s, sizeof(myrpt->rxpl));
 			myrpt->remmode = REM_MODE_FM;
 			myrpt->offset = REM_SIMPLEX;
 			myrpt->powerlevel = REM_MEDPWR;
@@ -5082,7 +5077,7 @@
 
 			/* We have a frequency */
 
-			strncpy(tmp, digitbuf ,sizeof(tmp) - 1);
+			ast_copy_string(tmp, digitbuf ,sizeof(tmp));
 			
 			s = tmp;
 			s1 = strsep(&s, "*"); /* Pick off MHz */
@@ -5167,15 +5162,15 @@
 			}	
 			offsave = myrpt->offset;
 			modesave = myrpt->remmode;
-			strncpy(savestr, myrpt->freq, sizeof(savestr) - 1);
-			strncpy(myrpt->freq, freq, sizeof(myrpt->freq) - 1);
+			ast_copy_string(savestr, myrpt->freq, sizeof(savestr));
+			ast_copy_string(myrpt->freq, freq, sizeof(myrpt->freq));
 			myrpt->offset = offset;
 			myrpt->remmode = defmode;
 
 			if (setrem(myrpt) == -1){
 				myrpt->offset = offsave;
 				myrpt->remmode = modesave;
-				strncpy(myrpt->freq, savestr, sizeof(myrpt->freq) - 1);
+				ast_copy_string(myrpt->freq, savestr, sizeof(myrpt->freq));
 				goto invalid_freq;
 			}
 
@@ -5212,16 +5207,16 @@
 			if(debug)
 				printf("PL digits entered %s\n", digitbuf);
 	    		
-			strncpy(tmp, digitbuf, sizeof(tmp) - 1);
+			ast_copy_string(tmp, digitbuf, sizeof(tmp));
 			/* see if we have at least 1 */
 			s = strchr(tmp,'*');
 			if(s)
 				*s = '.';
-			strncpy(savestr, myrpt->rxpl, sizeof(savestr) - 1);
-			strncpy(myrpt->rxpl, tmp, sizeof(myrpt->rxpl) - 1);
+			ast_copy_string(savestr, myrpt->rxpl, sizeof(savestr));
+			ast_copy_string(myrpt->rxpl, tmp, sizeof(myrpt->rxpl));
 			
 			if (setrem(myrpt) == -1){
-				strncpy(myrpt->rxpl, savestr, sizeof(myrpt->rxpl) - 1);
+				ast_copy_string(myrpt->rxpl, savestr, sizeof(myrpt->rxpl));
 				return DC_ERROR;
 			}
 		
@@ -5252,16 +5247,16 @@
 			if(debug)
 				printf("PL digits entered %s\n", digitbuf);
 	    		
-			strncpy(tmp, digitbuf, sizeof(tmp) - 1);
+			ast_copy_string(tmp, digitbuf, sizeof(tmp));
 			/* see if we have at least 1 */
 			s = strchr(tmp,'*');
 			if(s)
 				*s = '.';
-			strncpy(savestr, myrpt->txpl, sizeof(savestr) - 1);
-			strncpy(myrpt->txpl, tmp, sizeof(myrpt->txpl) - 1);
+			ast_copy_string(savestr, myrpt->txpl, sizeof(savestr));
+			ast_copy_string(myrpt->txpl, tmp, sizeof(myrpt->txpl));
 			
 			if (setrem(myrpt) == -1){
-				strncpy(myrpt->txpl, savestr, sizeof(myrpt->txpl) - 1);
+				ast_copy_string(myrpt->txpl, savestr, sizeof(myrpt->txpl) - 1);
 				return DC_ERROR;
 			}
 		
@@ -5693,8 +5688,7 @@
 		case DC_COMPLETE:
 			myrpt->totalexecdcommands++;
 			myrpt->dailyexecdcommands++;
-			strncpy(myrpt->lastdtmfcommand, myrpt->dtmfbuf, MAXDTMF-1);
-			myrpt->lastdtmfcommand[MAXDTMF-1] = '\0';
+			ast_copy_string(myrpt->lastdtmfcommand, myrpt->dtmfbuf, MAXDTMF);
 			myrpt->dtmfbuf[0] = 0;
 			myrpt->dtmfidx = -1;
 			myrpt->dtmf_time_rem = 0;
@@ -5719,7 +5713,7 @@
 int	seq,res;
 
  	/* put string in our buffer */
-	strncpy(tmp,str,sizeof(tmp) - 1);
+	ast_copy_string(tmp,str,sizeof(tmp));
 	if (!strcmp(tmp,discstr)) return 0;
 	if (sscanf(tmp,"%s %s %s %d %c",cmd,dest,src,&seq,&c) != 5)
 	{
@@ -5791,7 +5785,7 @@
 	/* remove from queue */
 	remque((struct qelem *) l);
 	rpt_mutex_unlock(&myrpt->lock);
-	strncpy(tmp,val,sizeof(tmp) - 1);
+	ast_copy_string(tmp,val,sizeof(tmp));
 	s = tmp;
 	s1 = strsep(&s,",");
 	s2 = strsep(&s,",");
@@ -5891,7 +5885,7 @@
 				myrpt->dtmfbuf[myrpt->dtmfidx++] = c;
 				myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
 				
-				strncpy(cmd, myrpt->dtmfbuf, sizeof(cmd) - 1);
+				ast_copy_string(cmd, myrpt->dtmfbuf, sizeof(cmd));
 				
 				rpt_mutex_unlock(&myrpt->lock);
 				res = collect_function_digits(myrpt, cmd, SOURCE_RPT, NULL);
@@ -5906,8 +5900,7 @@
 				    case DC_COMPLETE:
 					myrpt->totalexecdcommands++;
 					myrpt->dailyexecdcommands++;
-					strncpy(myrpt->lastdtmfcommand, cmd, MAXDTMF-1);
-					myrpt->lastdtmfcommand[MAXDTMF-1] = '\0';
+					ast_copy_string(myrpt->lastdtmfcommand, cmd, MAXDTMF);
 					myrpt->dtmfbuf[0] = 0;
 					myrpt->dtmfidx = -1;
 					myrpt->dtmf_time = 0;
@@ -5936,7 +5929,7 @@
 			myrpt->patchquiet = 0;
 			myrpt->patchfarenddisconnect = 0;
 			myrpt->patchdialtime = 0;
-			strncpy(myrpt->patchcontext, myrpt->p.ourcontext, MAXPATCHCONTEXT);
+			ast_copy_string(myrpt->patchcontext, myrpt->p.ourcontext, MAXPATCHCONTEXT);
 			myrpt->cidx = 0;
 			myrpt->exten[myrpt->cidx] = 0;
 			rpt_mutex_unlock(&myrpt->lock);
@@ -6051,7 +6044,7 @@
 		}
 	}
 	rpt_mutex_lock(&myrpt->lock);
-	strncpy(tmpstr,myrpt->rxchanname,sizeof(tmpstr) - 1);
+	ast_copy_string(tmpstr,myrpt->rxchanname,sizeof(tmpstr));
 	tele = strchr(tmpstr,'/');
 	if (!tele)
 	{
@@ -6098,7 +6091,7 @@
 	}
 	if (myrpt->txchanname)
 	{
-		strncpy(tmpstr,myrpt->txchanname,sizeof(tmpstr) - 1);
+		ast_copy_string(tmpstr,myrpt->txchanname,sizeof(tmpstr));
 		tele = strchr(tmpstr,'/');
 		if (!tele)
 		{
@@ -7209,10 +7202,9 @@
 		/* if is a remote, dont start one for it */
 		if (rpt_vars[i].remote)
 		{
-			strncpy(rpt_vars[i].freq, "146.580", sizeof(rpt_vars[i].freq) - 1);
-			strncpy(rpt_vars[i].rxpl, "100.0", sizeof(rpt_vars[i].rxpl) - 1);
-
-			strncpy(rpt_vars[i].txpl, "100.0", sizeof(rpt_vars[i].txpl) - 1);
+			strcpy(rpt_vars[i].freq, "146.580");
+			strcpy(rpt_vars[i].rxpl, "100.0");
+			strcpy(rpt_vars[i].txpl, "100.0");
 			rpt_vars[i].remmode = REM_MODE_FM;
 			rpt_vars[i].offset = REM_SIMPLEX;
 			rpt_vars[i].powerlevel = REM_MEDPWR;
@@ -7291,7 +7283,7 @@
 		ast_log(LOG_WARNING, "Rpt requires an argument (system node)\n");
 		return -1;
 	}
-	strncpy(tmp, (char *)data, sizeof(tmp)-1);
+	ast_copy_string(tmp, (char *)data, sizeof(tmp));
 	stringp=tmp;
 	strsep(&stringp, "|");
 	options = stringp;
@@ -7364,7 +7356,7 @@
 			return -1;
 		}
 		s=orig_s;
-		strncpy(s,options,l);
+		ast_copy_string(s,options,l);
 
 		template=strsep(&s,"|");
 		if(!template) {
@@ -7412,9 +7404,9 @@
 #else
 		if(exten)
 #endif
-			strncpy(chan->exten, exten, sizeof(chan->exten)-1);
+			ast_copy_string(chan->exten, exten, sizeof(chan->exten));
 		if(context)
-			strncpy(chan->context, context, sizeof(chan->context)-1);
+			ast_copy_string(chan->context, context, sizeof(chan->context));
 		} else {  /* increment the priority by default*/
 			chan->priority++;
 		}
@@ -7490,7 +7482,7 @@
 			ast_log(LOG_WARNING, "Reported node %s cannot be found!!\n",b1);
 			return -1;
 		}
-		strncpy(tmp,val,sizeof(tmp) - 1);
+		ast_copy_string(tmp,val,sizeof(tmp));
 		s = tmp;
 		s1 = strsep(&s,",");
 		s2 = strsep(&s,",");
@@ -7588,7 +7580,7 @@
 		/* zero the silly thing */
 		memset((char *)l,0,sizeof(struct rpt_link));
 		l->mode = 1;
-		strncpy(l->name,b1,MAXNODESTR - 1);
+		ast_copy_string(l->name,b1,MAXNODESTR);
 		l->isremote = 0;
 		l->chan = chan;
 		l->connected = 1;

Modified: branches/1.4/apps/app_sms.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_sms.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/apps/app_sms.c (original)
+++ branches/1.4/apps/app_sms.c Wed Oct 25 09:32:08 2006
@@ -1389,7 +1389,7 @@
 			ast_module_user_remove(u);
 			return -1;
 		}
-		strncpy (h.queue, (char *)d, p - d);
+		strncpy(h.queue, (char *)d, p - d);
 		if (*p == '|')
 			p++;
 		d = p;

Modified: branches/1.4/apps/app_softhangup.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_softhangup.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/apps/app_softhangup.c (original)
+++ branches/1.4/apps/app_softhangup.c Wed Oct 25 09:32:08 2006
@@ -74,7 +74,7 @@
 	all = options && strchr(options,'a');
 	c = ast_channel_walk_locked(NULL);
 	while (c) {
-		strncpy(name, c->name, sizeof(name)-1);
+		ast_copy_string(name, c->name, sizeof(name));
 		ast_mutex_unlock(&c->lock);
 		/* XXX watch out, i think it is wrong to access c-> after unlocking! */
 		if (all) {

Modified: branches/1.4/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_voicemail.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/apps/app_voicemail.c (original)
+++ branches/1.4/apps/app_voicemail.c Wed Oct 25 09:32:08 2006
@@ -7236,23 +7236,22 @@
 			char *tmpread, *tmpwrite;
 			emailbody = ast_strdup(s);
 
-			/* substitute strings \t and \n into the apropriate characters */
+			/* substitute strings \t and \n into the appropriate characters */
 			tmpread = tmpwrite = emailbody;
 			while ((tmpwrite = strchr(tmpread,'\\'))) {
-				int len = strlen("\n");
 				switch (tmpwrite[1]) {
 				case 'n':
-					strncpy(tmpwrite + len, tmpwrite + 2, strlen(tmpwrite + 2) + 1);
-					strncpy(tmpwrite, "\n", len);
+					*tmpwrite++ = '\n';
+					memmove(tmpwrite, tmpwrite + 1, strlen(tmpwrite + 1) + 1);
 					break;
 				case 't':
-					strncpy(tmpwrite + len, tmpwrite + 2, strlen(tmpwrite + 2) + 1);
-					strncpy(tmpwrite, "\t", len);
+					*tmpwrite++ = '\t';
+					memmove(tmpwrite, tmpwrite + 1, strlen(tmpwrite + 1) + 1);
 					break;
 				default:
 					ast_log(LOG_NOTICE, "Substitution routine does not support this character: %c\n", tmpwrite[1]);
 				}
-				tmpread = tmpwrite + len;
+				tmpread = tmpwrite + 1;
 			}
 		}
 		if ((s = ast_variable_retrieve(cfg, "general", "pagersubject")))
@@ -7261,23 +7260,22 @@
 			char *tmpread, *tmpwrite;
 			pagerbody = ast_strdup(s);
 
-			/* substitute strings \t and \n into the apropriate characters */
+			/* substitute strings \t and \n into the appropriate characters */
 			tmpread = tmpwrite = pagerbody;
 			while ((tmpwrite = strchr(tmpread, '\\'))) {
-				int len = strlen("\n");
 				switch (tmpwrite[1]) {
-					case 'n':
-						strncpy(tmpwrite + len, tmpwrite + 2, strlen(tmpwrite + 2) + 1);
-						strncpy(tmpwrite, "\n", len);
-						break;
-					case 't':
-						strncpy(tmpwrite + len, tmpwrite + 2, strlen(tmpwrite + 2) + 1);
-						strncpy(tmpwrite, "\t", len);
-						break;
-					default:
-						ast_log(LOG_NOTICE, "Substitution routine does not support this character: %c\n", tmpwrite[1]);
+				case 'n':
+					*tmpwrite++ = '\n';
+					memmove(tmpwrite, tmpwrite + 1, strlen(tmpwrite + 1) + 1);
+					break;
+				case 't':
+					*tmpwrite++ = '\t';
+					memmove(tmpwrite, tmpwrite + 1, strlen(tmpwrite + 1) + 1);
+					break;
+				default:
+					ast_log(LOG_NOTICE, "Substitution routine does not support this character: %c\n", tmpwrite[1]);
 				}
-				tmpread = tmpwrite + len;
+				tmpread = tmpwrite + 1;
 			}
 		}
 		AST_LIST_UNLOCK(&users);

Modified: branches/1.4/cdr/cdr_custom.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/cdr/cdr_custom.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/cdr/cdr_custom.c (original)
+++ branches/1.4/cdr/cdr_custom.c Wed Oct 25 09:32:08 2006
@@ -77,9 +77,9 @@
 		while(var) {
 			ast_mutex_lock(&lock);
 			if (!ast_strlen_zero(var->name) && !ast_strlen_zero(var->value)) {
-				if (strlen(var->value) > (sizeof(format) - 2))
+				if (strlen(var->value) > (sizeof(format) - 1))
 					ast_log(LOG_WARNING, "Format string too long, will be truncated, at line %d\n", var->lineno);
-				strncpy(format, var->value, sizeof(format) - 2);
+				ast_copy_string(format, var->value, sizeof(format) - 1);
 				strcat(format,"\n");
 				snprintf(master, sizeof(master),"%s/%s/%s", ast_config_AST_LOG_DIR, name, var->name);
 				ast_mutex_unlock(&lock);

Modified: branches/1.4/channels/chan_alsa.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_alsa.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/channels/chan_alsa.c (original)
+++ branches/1.4/channels/chan_alsa.c Wed Oct 25 09:32:08 2006
@@ -1158,7 +1158,7 @@
 		myc = context;
 		if (argc == 2) {
 			char *stringp = NULL;
-			strncpy(tmp, argv[1], sizeof(tmp) - 1);
+			ast_copy_string(tmp, argv[1], sizeof(tmp));
 			stringp = tmp;
 			strsep(&stringp, "@");
 			tmp2 = strsep(&stringp, "@");
@@ -1168,8 +1168,8 @@
 				myc = tmp2;
 		}
 		if (ast_exists_extension(NULL, myc, mye, 1, NULL)) {
-			strncpy(alsa.exten, mye, sizeof(alsa.exten) - 1);
-			strncpy(alsa.context, myc, sizeof(alsa.context) - 1);
+			ast_copy_string(alsa.exten, mye, sizeof(alsa.exten));
+			ast_copy_string(alsa.context, myc, sizeof(alsa.context));
 			hookstate = 1;
 			alsa_new(&alsa, AST_STATE_RINGING);
 		} else
@@ -1215,7 +1215,7 @@
 		myc = context;
 		if (argc == 3) {
 			char *stringp = NULL;
-			strncpy(tmp, argv[2], sizeof(tmp) - 1);
+			ast_copy_string(tmp, argv[2], sizeof(tmp));
 			stringp = tmp;
 			strsep(&stringp, "@");
 			tmp2 = strsep(&stringp, "@");
@@ -1225,8 +1225,8 @@
 				myc = tmp2;
 		}
 		if (ast_exists_extension(NULL, myc, mye, 1, NULL)) {
-			strncpy(alsa.exten, mye, sizeof(alsa.exten) - 1);
-			strncpy(alsa.context, myc, sizeof(alsa.context) - 1);
+			ast_copy_string(alsa.exten, mye, sizeof(alsa.exten));
+			ast_copy_string(alsa.context, myc, sizeof(alsa.context));
 			hookstate = 1;
 			alsa_new(&alsa, AST_STATE_RINGING);
 		} else

Modified: branches/1.4/channels/chan_features.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_features.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/channels/chan_features.c (original)
+++ branches/1.4/channels/chan_features.c Wed Oct 25 09:32:08 2006
@@ -436,8 +436,8 @@
 			for (x=0;x<3;x++)
 				init_sub(tmp->subs + x);
 			ast_mutex_init(&tmp->lock);
-			strncpy(tmp->tech, tech, sizeof(tmp->tech) - 1);
-			strncpy(tmp->dest, dest, sizeof(tmp->dest) - 1);
+			ast_copy_string(tmp->tech, tech, sizeof(tmp->tech));
+			ast_copy_string(tmp->dest, dest, sizeof(tmp->dest));
 			tmp->subchan = chan;
 			AST_LIST_LOCK(&features);
 			AST_LIST_INSERT_HEAD(&features, tmp, list);

Modified: branches/1.4/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_h323.c?rev=46200&r1=46199&r2=46200&view=diff
==============================================================================
--- branches/1.4/channels/chan_h323.c (original)
+++ branches/1.4/channels/chan_h323.c Wed Oct 25 09:32:08 2006
@@ -601,7 +601,7 @@
 	ast_mutex_lock(&pvt->lock);
 	if (!gatekeeper_disable) {
 		if (ast_strlen_zero(pvt->exten)) {
-			strncpy(called_addr, dest, sizeof(called_addr));
+			ast_copy_string(called_addr, dest, sizeof(called_addr));
 		} else {
 			snprintf(called_addr, sizeof(called_addr), "%s@%s", pvt->exten, dest);
 		}
@@ -618,13 +618,13 @@
 	called_addr[sizeof(called_addr) - 1] = '\0';
 
 	if (c->cid.cid_num)
-		strncpy(pvt->options.cid_num, c->cid.cid_num, sizeof(pvt->options.cid_num));
+		ast_copy_string(pvt->options.cid_num, c->cid.cid_num, sizeof(pvt->options.cid_num));
 
 	if (c->cid.cid_name)
-		strncpy(pvt->options.cid_name, c->cid.cid_name, sizeof(pvt->options.cid_name));
+		ast_copy_string(pvt->options.cid_name, c->cid.cid_name, sizeof(pvt->options.cid_name));
 
 	if (c->cid.cid_rdnis) {
-		strncpy(pvt->options.cid_rdnis, c->cid.cid_rdnis, sizeof(pvt->options.cid_rdnis));
+		ast_copy_string(pvt->options.cid_rdnis, c->cid.cid_rdnis, sizeof(pvt->options.cid_rdnis));
 	}
 
 	pvt->options.presentation = c->cid.cid_pres;
@@ -1046,8 +1046,8 @@
 		/* Set the owner of this channel */
 		pvt->owner = ch;
 
-		strncpy(ch->context, pvt->context, sizeof(ch->context) - 1);
-		strncpy(ch->exten, pvt->exten, sizeof(ch->exten) - 1);
+		ast_copy_string(ch->context, pvt->context, sizeof(ch->context));
+		ast_copy_string(ch->exten, pvt->exten, sizeof(ch->exten));
 		ch->priority = 1;
 		if (!ast_strlen_zero(pvt->accountcode)) {
 			ast_string_field_set(ch, accountcode, pvt->accountcode);
@@ -1128,7 +1128,7 @@
 	} else {
 		pvt->nonCodecCapability &= ~AST_RTP_DTMF;
 	}
-	strncpy(pvt->context, default_context, sizeof(pvt->context) - 1);
+	ast_copy_string(pvt->context, default_context, sizeof(pvt->context));
 	pvt->newstate = pvt->newcontrol = pvt->newdigit = pvt->update_rtp_info = pvt->DTMFsched = -1;
 	ast_mutex_init(&pvt->lock);
 	/* Add to interface list */
@@ -1201,16 +1201,16 @@
 		ASTOBJ_INIT(alias);
 	}
 	if (!found && name)
-		strncpy(alias->name, name, sizeof(alias->name) - 1);
+		ast_copy_string(alias->name, name, sizeof(alias->name));
 	for (; v || ((v = alt) && !(alt = NULL)); v = v->next) {
 		if (!strcasecmp(v->name, "e164")) {
-			strncpy(alias->e164, v->value, sizeof(alias->e164) - 1);
+			ast_copy_string(alias->e164, v->value, sizeof(alias->e164));
 		} else if (!strcasecmp(v->name, "prefix")) {
-			strncpy(alias->prefix, v->value, sizeof(alias->prefix) - 1);
+			ast_copy_string(alias->prefix, v->value, sizeof(alias->prefix));
 		} else if (!strcasecmp(v->name, "context")) {
-			strncpy(alias->context, v->value, sizeof(alias->context) - 1);
+			ast_copy_string(alias->context, v->value, sizeof(alias->context));
 		} else if (!strcasecmp(v->name, "secret")) {
-			strncpy(alias->secret, v->value, sizeof(alias->secret) - 1);
+			ast_copy_string(alias->secret, v->value, sizeof(alias->secret));
 		} else {
 			if (strcasecmp(v->value, "h323")) {
 				ast_log(LOG_WARNING, "Keyword %s does not make sense in type=h323\n", v->name);
@@ -1349,9 +1349,9 @@
 	user->ha = (struct ast_ha *)NULL;
 	memcpy(&user->options, &global_options, sizeof(user->options));
 	/* Set default context */
-	strncpy(user->context, default_context, sizeof(user->context) - 1);
+	ast_copy_string(user->context, default_context, sizeof(user->context));
 	if (user && !found)
-		strncpy(user->name, name, sizeof(user->name) - 1);
+		ast_copy_string(user->name, name, sizeof(user->name));
 
 #if 0 /* XXX Port channel variables functionality from chan_sip XXX */
 	if (user->chanvars) {
@@ -1364,11 +1364,11 @@
 		if (!update_common_options(v, &user->options))
 			continue;
 		if (!strcasecmp(v->name, "context")) {
-			strncpy(user->context, v->value, sizeof(user->context) - 1);
+			ast_copy_string(user->context, v->value, sizeof(user->context));
 		} else if (!strcasecmp(v->name, "secret")) {
-			strncpy(user->secret, v->value, sizeof(user->secret) - 1);
+			ast_copy_string(user->secret, v->value, sizeof(user->secret));
 		} else if (!strcasecmp(v->name, "accountcode")) {
-			strncpy(user->accountcode, v->value, sizeof(user->accountcode) - 1);
+			ast_copy_string(user->accountcode, v->value, sizeof(user->accountcode));
 		} else if (!strcasecmp(v->name, "host")) {
 			if (!strcasecmp(v->value, "dynamic")) {
 				ast_log(LOG_ERROR, "A dynamic host on a type=user does not make any sense\n");
@@ -1456,7 +1456,7 @@
 	peer->addr.sin_port = htons(h323_signalling_port);
 	peer->addr.sin_family = AF_INET;
 	if (!found && name)
-		strncpy(peer->name, name, sizeof(peer->name) - 1);
+		ast_copy_string(peer->name, name, sizeof(peer->name));
 
 #if 0 /* XXX Port channel variables functionality from chan_sip XXX */
 	if (peer->chanvars) {
@@ -1602,7 +1602,7 @@
 	char *hostn;
 	char peer[256] = "";
 
-	strncpy(peer, opeer, sizeof(peer) - 1);
+	ast_copy_string(peer, opeer, sizeof(peer));
 	port = strchr(peer, ':');
 	if (port) {
 		*port = '\0';
@@ -1690,7 +1690,7 @@
 			*cause = AST_CAUSE_INCOMPATIBLE_DESTINATION;
 		return NULL;
 	}
-	strncpy(tmp, dest, sizeof(tmp) - 1);
+	ast_copy_string(tmp, dest, sizeof(tmp));
 	host = strchr(tmp, '@');
 	if (host) {
 		*host = '\0';
@@ -1707,7 +1707,7 @@
 		h323_set_id(h323id);
 	}
 	if (ext) {
-		strncpy(pvt->exten, ext, sizeof(pvt->exten) - 1);
+		ast_copy_string(pvt->exten, ext, sizeof(pvt->exten));
 	}
 	if (h323debug)
 		ast_log(LOG_DEBUG, "Extension: %s Host: %s\n", pvt->exten, host);
@@ -1858,8 +1858,7 @@
 	ast_rtp_get_us(pvt->rtp, &us);
 	ast_mutex_unlock(&pvt->lock);
 
-	strncpy(info->addr, ast_inet_ntoa(us.sin_addr), sizeof(info->addr));
-	info->addr[sizeof(info->addr)-1] = '\0';
+	ast_copy_string(info->addr, ast_inet_ntoa(us.sin_addr), sizeof(info->addr));
 	info->port = ntohs(us.sin_port);
 	if (h323debug)
 		ast_log(LOG_DEBUG, "Sending RTP 'US' %s:%d\n", info->addr, info->port);
@@ -2077,8 +2076,8 @@
 	/* Decide if we are allowing Gatekeeper routed calls*/
 	if ((!strcasecmp(cd->sourceIp, gatekeeper)) && (gkroute == -1) && !gatekeeper_disable) {
 		if (!ast_strlen_zero(cd->call_dest_e164)) {
-			strncpy(pvt->exten, cd->call_dest_e164, sizeof(pvt->exten) - 1);

[... 714 lines stripped ...]


More information about the svn-commits mailing list