From a5ad1269ef42bd302fa053d95fc8584664b163ba Mon Sep 17 00:00:00 2001
From: Mark Spencer <markster@digium.com>
Date: Tue, 4 May 2004 14:54:42 +0000
Subject: [PATCH] More strlen_zero checks (bug #1549)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2887 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 asterisk.c | 13 +++++++------
 config.c   |  7 ++++---
 enum.c     |  3 ++-
 say.c      |  7 ++++---
 srv.c      |  3 ++-
 5 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/asterisk.c b/asterisk.c
index d1b0dad3cc..a1c1647f6c 100755
--- a/asterisk.c
+++ b/asterisk.c
@@ -31,6 +31,7 @@
 #include <asterisk/rtp.h>
 #include <asterisk/app.h>
 #include <asterisk/lock.h>
+#include <asterisk/utils.h>
 #include <sys/resource.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -546,7 +547,7 @@ static void quit_handler(int num, int nice, int safeshutdown, int restart)
 	if (option_console || option_remote) {
 		if (getenv("HOME")) 
 			snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
-		if (strlen(filename))
+		if (!ast_strlen_zero(filename))
 			ast_el_write_history(filename);
 		if (el != NULL)
 			el_end(el);
@@ -640,7 +641,7 @@ static void consolehandler(char *s)
 	printf(term_end());
 	fflush(stdout);
 	/* Called when readline data is available */
-	if (s && strlen(s))
+	if (s && !ast_strlen_zero(s))
 		ast_el_add_history(s);
 	/* Give the console access to the shell */
 	if (s) {
@@ -660,7 +661,7 @@ static int remoteconsolehandler(char *s)
 {
 	int ret = 0;
 	/* Called when readline data is available */
-	if (s && strlen(s))
+	if (s && !ast_strlen_zero(s))
 		ast_el_add_history(s);
 	/* Give the console access to the shell */
 	if (s) {
@@ -1334,7 +1335,7 @@ static void ast_remotecontrol(char * data)
 
 	el_set(el, EL_GETCFN, ast_el_read_char);
 
-	if (strlen(filename))
+	if (!ast_strlen_zero(filename))
 		ast_el_read_history(filename);
 
 	ast_cli_register(&quit);
@@ -1350,7 +1351,7 @@ static void ast_remotecontrol(char * data)
 	for(;;) {
 		ebuf = (char *)el_gets(el, &num);
 
-		if (ebuf && strlen(ebuf)) {
+		if (ebuf && !ast_strlen_zero(ebuf)) {
 			if (ebuf[strlen(ebuf)-1] == '\n')
 				ebuf[strlen(ebuf)-1] = '\0';
 			if (!remoteconsolehandler(ebuf)) {
@@ -1555,7 +1556,7 @@ int main(int argc, char *argv[])
                 if (el_hist == NULL || el == NULL)
                         ast_el_initialize();
 
-                if (strlen(filename))
+                if (!ast_strlen_zero(filename))
                         ast_el_read_history(filename);
 	}
 
diff --git a/config.c b/config.c
index e25b242359..574561ab3c 100755
--- a/config.c
+++ b/config.c
@@ -20,6 +20,7 @@
 #include <asterisk/config.h>
 #include <asterisk/options.h>
 #include <asterisk/logger.h>
+#include <asterisk/utils.h>
 #include "asterisk.h"
 #include "astconf.h"
 
@@ -57,7 +58,7 @@ static char *strip(char *buf)
 {
 	char *start;
 	/* Strip off trailing whitespace, returns, etc */
-	while(strlen(buf) && (buf[strlen(buf)-1]<33))
+	while(!ast_strlen_zero(buf) && (buf[strlen(buf)-1]<33))
 		buf[strlen(buf)-1] = '\0';
 	start = buf;
 	/* Strip off leading whitespace, returns, etc */
@@ -469,7 +470,7 @@ static int cfg_process(struct ast_config *tmp, struct ast_category **_tmpc, stru
 #endif			
 	}
 	cur = strip(buf);
-	if (strlen(cur)) {
+	if (!ast_strlen_zero(cur)) {
 		/* Actually parse the entry */
 		if (cur[0] == '[') {
 			/* A category header */
@@ -525,7 +526,7 @@ static int cfg_process(struct ast_config *tmp, struct ast_category **_tmpc, stru
 					while((*c == '<') || (*c == '>') || (*c == '\"')) c++;
 					/* Get rid of leading mess */
 					cur = c;
-					while(strlen(cur)) {
+					while(!ast_strlen_zero(cur)) {
 						c = cur + strlen(cur) - 1;
 						if ((*c == '>') || (*c == '<') || (*c == '\"'))
 							*c = '\0';
diff --git a/enum.c b/enum.c
index 48531dfe9d..a0fa980831 100755
--- a/enum.c
+++ b/enum.c
@@ -32,6 +32,7 @@
 #include <asterisk/dns.h>
 #include <asterisk/channel.h>
 #include <asterisk/config.h>
+#include <asterisk/utils.h>
 
 #ifdef __APPLE__
 #undef T_NAPTR
@@ -237,7 +238,7 @@ static int enum_callback(void *context, u_char *answer, int len, u_char *fullans
 		return -1;
 	}
 
-	if (strlen(c->dst))
+	if (!ast_strlen_zero(c->dst))
 		return 1;
 
 	return 0;
diff --git a/say.c b/say.c
index 92dfcd19d5..4867ef0556 100755
--- a/say.c
+++ b/say.c
@@ -23,6 +23,7 @@
 #include <asterisk/say.h>
 #include <asterisk/lock.h>
 #include <asterisk/localtime.h>
+#include <asterisk/utils.h>
 #include "asterisk.h"
 #include <stdio.h>
 
@@ -50,7 +51,7 @@ int ast_say_digit_str(struct ast_channel *chan, char *fn2, char *ints, char *lan
 					snprintf(fn, sizeof(fn), "digits/%c", fn2[num]);
 				}
 		}
-		if(strlen(fn)){ /* if length == 0, then skip this digit as it is invalid */
+		if(!ast_strlen_zero(fn)){ /* if length == 0, then skip this digit as it is invalid */
 			res = ast_streamfile(chan, fn, lang);
 			if (!res)
 				res = ast_waitstream(chan, ints);
@@ -121,7 +122,7 @@ int ast_say_character_str(struct ast_channel *chan, char *fn2, char *ints, char
  				if ('A' <= ltr && ltr <= 'Z') ltr += 'a' - 'A';		/* file names are all lower-case */
  				snprintf(fn, sizeof(fn), "letters/%c", ltr);
   		}
-		if(strlen(fn)){ /* if length == 0, then skip this digit as it is invalid */
+		if(!ast_strlen_zero(fn)) { /* if length == 0, then skip this digit as it is invalid */
 			res = ast_streamfile(chan, fn, lang);
 			if (!res) 
 				res = ast_waitstream(chan, ints);
@@ -192,7 +193,7 @@ int ast_say_phonetic_str(struct ast_channel *chan, char *fn2, char *ints, char *
 			case ('%'):
 				play=0;
 				/* check if we have 2 chars after the % */
-				if (strlen(fn2)>num+2)
+				if (strlen(fn2) > num+2)
 				{
 				    hex[0]=fn2[num+1];
 				    hex[1]=fn2[num+2];
diff --git a/srv.c b/srv.c
index 299d3eed3b..98df484dde 100755
--- a/srv.c
+++ b/srv.c
@@ -27,6 +27,7 @@
 #include <asterisk/srv.h>
 #include <asterisk/dns.h>
 #include <asterisk/options.h>
+#include <asterisk/utils.h>
 
 #ifdef __APPLE__
 #undef T_SRV
@@ -84,7 +85,7 @@ static int srv_callback(void *context, u_char *answer, int len, u_char *fullansw
 		return -1;
 	}
 
-	if (strlen(c->host))
+	if (!ast_strlen_zero(c->host))
 		return 1;
 
     return 0;
-- 
GitLab