From edbc500b7734ec5d8aff00d928984902bf65608f Mon Sep 17 00:00:00 2001
From: Russell Bryant <russell@russellbryant.com>
Date: Sun, 10 Jul 2005 22:56:21 +0000
Subject: [PATCH] more ast_copy_string conversions

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6073 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 acl.c      |  4 ++--
 astmm.c    |  8 ++++----
 callerid.c | 14 +++++++-------
 cli.c      |  6 +++---
 config.c   | 10 +++++-----
 enum.c     | 20 ++++++++++----------
 frame.c    |  6 +++---
 logger.c   | 10 +++++-----
 manager.c  | 30 +++++++++++++++---------------
 privacy.c  | 10 +++++-----
 srv.c      |  2 +-
 term.c     | 14 +++++++-------
 12 files changed, 67 insertions(+), 67 deletions(-)

diff --git a/acl.c b/acl.c
index 7cd4cd1ee4..85abe84f7b 100755
--- a/acl.c
+++ b/acl.c
@@ -146,7 +146,7 @@ struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path)
 		path = path->next;
 	}
 	if (ha) {
-		strncpy(tmp, stuff, sizeof(tmp) - 1);
+		ast_copy_string(tmp, stuff, sizeof(tmp));
 		nm = strchr(tmp, '/');
 		if (!nm)
 			nm = "255.255.255.255";
@@ -248,7 +248,7 @@ int ast_lookup_iface(char *iface, struct in_addr *address)
 	struct my_ifreq ifreq;
 
 	memset(&ifreq, 0, sizeof(ifreq));
-	strncpy(ifreq.ifrn_name,iface,sizeof(ifreq.ifrn_name) - 1);
+	ast_copy_string(ifreq.ifrn_name,iface,sizeof(ifreq.ifrn_name));
 
 	mysock = socket(PF_INET,SOCK_DGRAM,IPPROTO_IP);
 	res = ioctl(mysock,SIOCGIFADDR,&ifreq);
diff --git a/astmm.c b/astmm.c
index 4cce430589..f4fc3f2dbd 100755
--- a/astmm.c
+++ b/astmm.c
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- A telephony toolkit for Linux.
  *
- * Channel Variables
+ * Memory Management
  * 
  * Copyright (C) 2002-2005, Mark Spencer
  *
@@ -73,9 +73,9 @@ static inline void *__ast_alloc_region(size_t size, int which, const char *file,
 	reg = malloc(size + sizeof(struct ast_region));
 	ast_mutex_lock(&reglock);
 	if (reg) {
-		strncpy(reg->file, file, sizeof(reg->file) - 1);
+		ast_copy_string(reg->file, file, sizeof(reg->file));
 		reg->file[sizeof(reg->file) - 1] = '\0';
-		strncpy(reg->func, func, sizeof(reg->func) - 1);
+		ast_copy_string(reg->func, func, sizeof(reg->func));
 		reg->func[sizeof(reg->func) - 1] = '\0';
 		reg->lineno = lineno;
 		reg->len = size;
@@ -305,7 +305,7 @@ static int handle_show_memory_summary(int fd, int argc, char *argv[])
 				if (!cur) {
 					cur = alloca(sizeof(struct file_summary));
 					memset(cur, 0, sizeof(struct file_summary));
-					strncpy(cur->fn, fn ? reg->func : reg->file, sizeof(cur->fn) - 1);
+					ast_copy_string(cur->fn, fn ? reg->func : reg->file, sizeof(cur->fn));
 					cur->next = list;
 					list = cur;
 				}
diff --git a/callerid.c b/callerid.c
index 79fde4d893..339c334c66 100755
--- a/callerid.c
+++ b/callerid.c
@@ -364,7 +364,7 @@ int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len, int
 					}
 				} else {
 					/* SDMF */
-					strncpy(cid->number, cid->rawdata + 8, sizeof(cid->number)-1);
+					ast_copy_string(cid->number, cid->rawdata + 8, sizeof(cid->number));
 				}
 				/* Update flags */
 				cid->flags = 0;
@@ -646,7 +646,7 @@ int ast_callerid_parse(char *instr, char **name, char **location)
 			return 0;
 		}
 	} else {
-		strncpy(tmp, instr, sizeof(tmp)-1);
+		ast_copy_string(tmp, instr, sizeof(tmp));
 		ast_shrink_phone_number(tmp);
 		if (ast_isphonenumber(tmp)) {
 			/* Assume it's just a location */
@@ -691,11 +691,11 @@ char *ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *nu
 	if (name && num)
 		snprintf(buf, bufsiz, "\"%s\" <%s>", name, num);
 	else if (name) 
-		strncpy(buf, name, bufsiz - 1);
+		ast_copy_string(buf, name, bufsiz);
 	else if (num)
-		strncpy(buf, num, bufsiz - 1);
+		ast_copy_string(buf, num, bufsiz);
 	else
-		strncpy(buf, unknown, bufsiz - 1);
+		ast_copy_string(buf, unknown, bufsiz);
 	return buf;
 }
 int ast_callerid_split(const char *buf, char *name, int namelen, char *num, int numlen)
@@ -710,12 +710,12 @@ int ast_callerid_split(const char *buf, char *name, int namelen, char *num, int
 	}
 	ast_callerid_parse(tmp, &n, &l);
 	if (n)
-		strncpy(name, n, namelen - 1);
+		ast_copy_string(name, n, namelen);
 	else
 		name[0] = '\0';
 	if (l) {
 		ast_shrink_phone_number(l);
-		strncpy(num, l, numlen - 1);
+		ast_copy_string(num, l, numlen);
 	} else
 		num[0] = '\0';
 	return 0;
diff --git a/cli.c b/cli.c
index f027dd6db5..af77b5af5a 100755
--- a/cli.c
+++ b/cli.c
@@ -587,7 +587,7 @@ static int handle_debuglevel(int fd, int argc, char *argv[])
 	option_debug = newlevel;
 	if (argc == 4) {
 		filename = argv[3];
-		strncpy(debug_filename, filename, sizeof(debug_filename) - 1);
+		ast_copy_string(debug_filename, filename, sizeof(debug_filename));
 	} else {
 		debug_filename[0] = '\0';
 	}
@@ -686,7 +686,7 @@ static int handle_showchan(int fd, int argc, char *argv[])
 		sec = elapsed_seconds % 60;
 		snprintf(cdrtime, sizeof(cdrtime), "%dh%dm%ds", hour, min, sec);
 	} else
-		strncpy(cdrtime, "N/A", sizeof(cdrtime) -1);
+		strcpy(cdrtime, "N/A");
 	ast_cli(fd, 
 		" -- General --\n"
 		"           Name: %s\n"
@@ -784,7 +784,7 @@ static char *complete_fn(char *line, char *word, int pos, int state)
 	if (pos != 1)
 		return NULL;
 	if (word[0] == '/')
-		strncpy(filename, word, sizeof(filename)-1);
+		ast_copy_string(filename, word, sizeof(filename));
 	else
 		snprintf(filename, sizeof(filename), "%s/%s", (char *)ast_config_AST_MODULE_DIR, word);
 	c = (char*)filename_completion_function(filename, state);
diff --git a/config.c b/config.c
index cef3d61cf1..8b9e44156b 100755
--- a/config.c
+++ b/config.c
@@ -192,7 +192,7 @@ struct ast_category *ast_category_new(const char *name)
 	category = malloc(sizeof(struct ast_category));
 	if (category) {
 		memset(category, 0, sizeof(struct ast_category));
-		strncpy(category->name, name, sizeof(category->name) - 1);
+		ast_copy_string(category->name, name, sizeof(category->name));
 	}
 
 	return category;
@@ -295,7 +295,7 @@ struct ast_variable *ast_category_detach_variables(struct ast_category *cat)
 
 void ast_category_rename(struct ast_category *cat, const char *name)
 {
-	strncpy(cat->name, name, sizeof(cat->name) - 1);
+	ast_copy_string(cat->name, name, sizeof(cat->name));
 }
 
 static void inherit_category(struct ast_category *new, const struct ast_category *base)
@@ -531,7 +531,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
 	cat = ast_config_get_current_category(cfg);
 
 	if (filename[0] == '/') {
-		strncpy(fn, filename, sizeof(fn)-1);
+		ast_copy_string(fn, filename, sizeof(fn));
 	} else {
 		snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, filename);
 	}
@@ -556,7 +556,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
 			/* loop over expanded files */
 			int i;
 			for (i=0; i<globbuf.gl_pathc; i++) {
-				strncpy(fn, globbuf.gl_pathv[i], sizeof(fn)-1);
+				ast_copy_string(fn, globbuf.gl_pathv[i], sizeof(fn));
 #endif
 	if ((option_verbose > 1) && !option_debug) {
 		ast_verbose(  VERBOSE_PREFIX_2 "Parsing '%s': ", fn);
@@ -668,7 +668,7 @@ int config_text_file_save(const char *configfile, const struct ast_config *cfg,
 		snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile);
 	}
 	time(&t);
-	strncpy(date, ctime(&t), sizeof(date) - 1);
+	ast_copy_string(date, ctime(&t), sizeof(date));
 	if ((f = fopen(fn, "w"))) {
 		if ((option_verbose > 1) && !option_debug)
 			ast_verbose(  VERBOSE_PREFIX_2 "Saving '%s': ", fn);
diff --git a/enum.c b/enum.c
index d79d24a148..e96f49d66b 100755
--- a/enum.c
+++ b/enum.c
@@ -148,23 +148,23 @@ static int parse_naptr(unsigned char *dst, int dstsize, char *tech, int techsize
 
 	if ((!strncasecmp(services, "e2u+sip", 7)) || 
 	    (!strncasecmp(services, "sip+e2u", 7))) {
-		strncpy(tech, "sip", techsize -1); 
+		ast_copy_string(tech, "sip", techsize); 
 	} else if ((!strncasecmp(services, "e2u+h323", 8)) || 
 	    (!strncasecmp(services, "h323+e2u", 8))) {
-		strncpy(tech, "h323", techsize -1); 
+		ast_copy_string(tech, "h323", techsize); 
 	} else if ((!strncasecmp(services, "e2u+x-iax2", 10)) || 
 	    (!strncasecmp(services, "e2u+iax2", 8)) ||
 	    (!strncasecmp(services, "iax2+e2u", 8))) {
-		strncpy(tech, "iax2", techsize -1); 
+		ast_copy_string(tech, "iax2", techsize); 
 	} else if ((!strncasecmp(services, "e2u+x-iax", 9)) ||
 	    (!strncasecmp(services, "e2u+iax", 7)) ||
 	    (!strncasecmp(services, "iax+e2u", 7))) {
-		strncpy(tech, "iax", techsize -1); 
+		ast_copy_string(tech, "iax", techsize); 
 	} else if ((!strncasecmp(services, "e2u+tel", 7)) || 
 	    (!strncasecmp(services, "tel+e2u", 7))) {
-		strncpy(tech, "tel", techsize -1); 
+		ast_copy_string(tech, "tel", techsize); 
 	} else if (!strncasecmp(services, "e2u+voice:", 10)) {
-		strncpy(tech, services+10, techsize -1); 
+		ast_copy_string(tech, services+10, techsize); 
 	} else {
 		ast_log(LOG_DEBUG, 
 		"Services must be e2u+${tech}, ${tech}+e2u, or e2u+voice: where $tech is from (sip, h323, tel, iax, iax2). \n");
@@ -172,7 +172,7 @@ static int parse_naptr(unsigned char *dst, int dstsize, char *tech, int techsize
 	}
 
 	/* DEDBUGGING STUB
-	strncpy(regexp, "!^\\+43(.*)$!\\1@bla.fasel!", sizeof(regexp) - 1);
+	ast_copy_string(regexp, "!^\\+43(.*)$!\\1@bla.fasel!", sizeof(regexp) - 1);
 	*/
 
 	regexp_len = strlen(regexp);
@@ -244,7 +244,7 @@ static int parse_naptr(unsigned char *dst, int dstsize, char *tech, int techsize
 		}
 	}
 	*d = 0;
-	strncpy(dst, temp, dstsize - 1);
+	ast_copy_string(dst, temp, dstsize);
 	dst[dstsize - 1] = '\0';
 	return 0;
 }
@@ -286,7 +286,7 @@ static int txt_callback(void *context, u_char *answer, int len, u_char *fullansw
 	len +=1;
 
 	/* finally, copy the answer into c->txt */
-	strncpy(c->txt, answer, len < c->txtlen ? len-1 : (c->txtlen)-1);
+	ast_copy_string(c->txt, answer, len < c->txtlen ? len : (c->txtlen));
 	
 	/* just to be safe, let's make sure c->txt is null terminated */
 	c->txt[(c->txtlen)-1] = '\0';
@@ -439,7 +439,7 @@ static struct enum_search *enum_newtoplev(char *s)
 	tmp = malloc(sizeof(struct enum_search));
 	if (tmp) {
 		memset(tmp, 0, sizeof(struct enum_search));
-		strncpy(tmp->toplev, s, sizeof(tmp->toplev) - 1);
+		ast_copy_string(tmp->toplev, s, sizeof(tmp->toplev));
 	}
 	return tmp;
 }
diff --git a/frame.c b/frame.c
index 457ca1a047..9a32c29665 100755
--- a/frame.c
+++ b/frame.c
@@ -739,7 +739,7 @@ void ast_frame_dump(char *name, struct ast_frame *f, char *prefix)
 	case AST_FRAME_TEXT:
 		strcpy(ftype, "Text");
 		strcpy(subclass, "N/A");
-		strncpy(moreinfo, f->data, sizeof(moreinfo) - 1);
+		ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
 		break;
 	case AST_FRAME_IMAGE:
 		strcpy(ftype, "Image");
@@ -750,7 +750,7 @@ void ast_frame_dump(char *name, struct ast_frame *f, char *prefix)
 		switch(f->subclass) {
 		case AST_HTML_URL:
 			strcpy(subclass, "URL");
-			strncpy(moreinfo, f->data, sizeof(moreinfo) - 1);
+			ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
 			break;
 		case AST_HTML_DATA:
 			strcpy(subclass, "Data");
@@ -769,7 +769,7 @@ void ast_frame_dump(char *name, struct ast_frame *f, char *prefix)
 			break;
 		case AST_HTML_LINKURL:
 			strcpy(subclass, "Link URL");
-			strncpy(moreinfo, f->data, sizeof(moreinfo) - 1);
+			ast_copy_string(moreinfo, f->data, sizeof(moreinfo));
 			break;
 		case AST_HTML_UNLINK:
 			strcpy(subclass, "Unlink");
diff --git a/logger.c b/logger.c
index 4033161831..cc55f1e77e 100755
--- a/logger.c
+++ b/logger.c
@@ -245,7 +245,7 @@ static struct logchannel *make_logchannel(char *channel, char *components, int l
 			if(!ast_strlen_zero(hostname)) { 
 				snprintf(chan->filename, sizeof(chan->filename) - 1,"%s.%s", channel, hostname);
 			} else {
-				strncpy(chan->filename, channel, sizeof(chan->filename) - 1);
+				ast_copy_string(chan->filename, channel, sizeof(chan->filename));
 			}
 		}		  
 		
@@ -297,7 +297,7 @@ static void init_logger_chain(void)
 	if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) {
 		if(ast_true(s)) {
 			if(gethostname(hostname, sizeof(hostname)-1)) {
-				strncpy(hostname, "unknown", sizeof(hostname)-1);
+				ast_copy_string(hostname, "unknown", sizeof(hostname));
 				ast_log(LOG_WARNING, "What box has no hostname???\n");
 			}
 		} else
@@ -305,9 +305,9 @@ static void init_logger_chain(void)
 	} else
 		hostname[0] = '\0';
 	if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) {
-		strncpy(dateformat, s, sizeof(dateformat) - 1);
+		ast_copy_string(dateformat, s, sizeof(dateformat));
 	} else
-		strncpy(dateformat, "%b %e %T", sizeof(dateformat) - 1);
+		ast_copy_string(dateformat, "%b %e %T", sizeof(dateformat));
 	if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) {
 		logfiles.queue_log = ast_true(s);
 	}
@@ -417,7 +417,7 @@ int reload_logger(int rotate)
 			fclose(f->fileptr);	/* Close file */
 			f->fileptr = NULL;
 			if(rotate) {
-				strncpy(old, f->filename, sizeof(old) - 1);
+				ast_copy_string(old, f->filename, sizeof(old));
 	
 				for(x=0;;x++) {
 					snprintf(new, sizeof(new), "%s.%d", f->filename, x);
diff --git a/manager.c b/manager.c
index 4f968cd197..8f39b35e2f 100755
--- a/manager.c
+++ b/manager.c
@@ -135,7 +135,7 @@ static char *authority_to_str(int authority, char *res, int reslen)
 		}
 	}
 	if (ast_strlen_zero(res)) {
-		strncpy(res, "<none>", reslen);
+		ast_copy_string(res, "<none>", reslen);
 	}
 	return res;
 }
@@ -480,7 +480,7 @@ static int authenticate(struct mansession *s, struct message *m)
 		cat = ast_category_browse(cfg, cat);
 	}
 	if (cat) {
-		strncpy(s->username, cat, sizeof(s->username) - 1);
+		ast_copy_string(s->username, cat, sizeof(s->username));
 		s->readperm = get_perm(ast_variable_retrieve(cfg, cat, "read"));
 		s->writeperm = get_perm(ast_variable_retrieve(cfg, cat, "write"));
 		ast_config_destroy(cfg);
@@ -953,7 +953,7 @@ static int action_originate(struct mansession *s, struct message *m)
 		astman_send_error(s, m, "Invalid timeout\n");
 		return 0;
 	}
-	strncpy(tmp, name, sizeof(tmp) - 1);
+	ast_copy_string(tmp, name, sizeof(tmp));
 	tech = tmp;
 	data = strchr(tmp, '/');
 	if (!data) {
@@ -962,7 +962,7 @@ static int action_originate(struct mansession *s, struct message *m)
 	}
 	*data = '\0';
 	data++;
-	strncpy(tmp2, callerid, sizeof(tmp2) - 1);
+	ast_copy_string(tmp2, callerid, sizeof(tmp2));
 	ast_callerid_parse(tmp2, &n, &l);
 	if (n) {
 		if (ast_strlen_zero(n))
@@ -981,18 +981,18 @@ static int action_originate(struct mansession *s, struct message *m)
 			memset(fast, 0, sizeof(struct fast_originate_helper));
 			if (id && !ast_strlen_zero(id))
 				snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s\r\n", id);
-			strncpy(fast->tech, tech, sizeof(fast->tech) - 1);
-   			strncpy(fast->data, data, sizeof(fast->data) - 1);
-			strncpy(fast->app, app, sizeof(fast->app) - 1);
-			strncpy(fast->appdata, appdata, sizeof(fast->appdata) - 1);
+			ast_copy_string(fast->tech, tech, sizeof(fast->tech));
+   			ast_copy_string(fast->data, data, sizeof(fast->data));
+			ast_copy_string(fast->app, app, sizeof(fast->app));
+			ast_copy_string(fast->appdata, appdata, sizeof(fast->appdata));
 			if (l)
-				strncpy(fast->cid_num, l, sizeof(fast->cid_num) - 1);
+				ast_copy_string(fast->cid_num, l, sizeof(fast->cid_num));
 			if (n)
-				strncpy(fast->cid_name, n, sizeof(fast->cid_name) - 1);
-			strncpy(fast->variable, variable, sizeof(fast->variable) - 1);
-			strncpy(fast->account, account, sizeof(fast->account) - 1);
-			strncpy(fast->context, context, sizeof(fast->context) - 1);
-			strncpy(fast->exten, exten, sizeof(fast->exten) - 1);
+				ast_copy_string(fast->cid_name, n, sizeof(fast->cid_name));
+			ast_copy_string(fast->variable, variable, sizeof(fast->variable));
+			ast_copy_string(fast->account, account, sizeof(fast->account));
+			ast_copy_string(fast->context, context, sizeof(fast->context));
+			ast_copy_string(fast->exten, exten, sizeof(fast->exten));
 			fast->timeout = to;
 			fast->priority = pi;
 			pthread_attr_init(&attr);
@@ -1173,7 +1173,7 @@ static int process_message(struct mansession *s, struct message *m)
 	char idText[256] = "";
 	char iabuf[INET_ADDRSTRLEN];
 
-	strncpy(action, astman_get_header(m, "Action"), sizeof(action) - 1);
+	ast_copy_string(action, astman_get_header(m, "Action"), sizeof(action));
 	ast_log( LOG_DEBUG, "Manager received command '%s'\n", action );
 
 	if (ast_strlen_zero(action)) {
diff --git a/privacy.c b/privacy.c
index c02f093e0f..2cef6cae23 100755
--- a/privacy.c
+++ b/privacy.c
@@ -1,11 +1,11 @@
 /*
  * Asterisk -- A telephony toolkit for Linux.
  *
- * Channel Management
+ * Privacy Routines
  * 
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999 - 2005, Mark Spencer
  *
- * Mark Spencer <markster@linux-support.net>
+ * Mark Spencer <markster@digium.com>
  *
  * This program is free software, distributed under the terms of
  * the GNU General Public License
@@ -44,7 +44,7 @@ int ast_privacy_check(char *dest, char *cid)
 	int res;
 	char key[256], result[256];
 	if (cid)
-		strncpy(tmp, cid, sizeof(tmp) - 1);
+		ast_copy_string(tmp, cid, sizeof(tmp));
 	ast_callerid_parse(tmp, &n, &l);
 	if (l) {
 		ast_shrink_phone_number(l);
@@ -80,7 +80,7 @@ int ast_privacy_set(char *dest, char *cid, int status)
 	int res;
 	char key[256];
 	if (cid)
-		strncpy(tmp, cid, sizeof(tmp) - 1);
+		ast_copy_string(tmp, cid, sizeof(tmp));
 	ast_callerid_parse(tmp, &n, &l);
 	if (l) {
 		ast_shrink_phone_number(l);
diff --git a/srv.c b/srv.c
index 572f1c2638..f7d23533b8 100755
--- a/srv.c
+++ b/srv.c
@@ -65,7 +65,7 @@ static int parse_srv(unsigned char *host, int hostlen, int *portno, unsigned cha
 		if (option_verbose > 3)
 			ast_verbose( VERBOSE_PREFIX_3 "parse_srv: SRV mapped to host %s, port %d\n", repl, ntohs(srv->portnum));
 		if (host) {
-			strncpy(host, repl, hostlen - 1);
+			ast_copy_string(host, repl, hostlen);
 			host[hostlen-1] = '\0';
 		}
 		if (portno)
diff --git a/term.c b/term.c
index 27cdf1e8b3..5719c76a34 100755
--- a/term.c
+++ b/term.c
@@ -1,11 +1,11 @@
 /*
  * Asterisk -- A telephony toolkit for Linux.
  *
- * Channel Management
+ * Terminal Routines 
  * 
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999 - 2005, Mark Spencer
  *
- * Mark Spencer <markster@linux-support.net>
+ * Mark Spencer <markster@digium.com>
  *
  * This program is free software, distributed under the terms of
  * the GNU General Public License
@@ -140,16 +140,16 @@ char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int
 	int attr=0;
 	char tmp[40];
 	if (!vt100compat) {
-		strncpy(outbuf, inbuf, maxout -1);
+		ast_copy_string(outbuf, inbuf, maxout);
 		return outbuf;
 	}
 	if (!fgcolor && !bgcolor) {
-		strncpy(outbuf, inbuf, maxout - 1);
+		ast_copy_string(outbuf, inbuf, maxout);
 		return outbuf;
 	}
 	if ((fgcolor & 128) && (bgcolor & 128)) {
 		/* Can't both be highlighted */
-		strncpy(outbuf, inbuf, maxout - 1);
+		ast_copy_string(outbuf, inbuf, maxout);
 		return outbuf;
 	}
 	if (!bgcolor)
@@ -241,7 +241,7 @@ char *term_strip(char *outbuf, char *inbuf, int maxout)
 char *term_prompt(char *outbuf, const char *inbuf, int maxout)
 {
 	if (!vt100compat) {
-		strncpy(outbuf, inbuf, maxout -1);
+		ast_copy_string(outbuf, inbuf, maxout);
 		return outbuf;
 	}
 	snprintf(outbuf, maxout, "%c[%d;%d;%dm%c%c[%d;%d;%dm%s",
-- 
GitLab