From 44f43f9eb18cf96635f8a529beb958ddd623991b Mon Sep 17 00:00:00 2001
From: Luigi Rizzo <rizzo@icir.org>
Date: Sun, 30 Apr 2006 23:04:58 +0000
Subject: [PATCH] another small set of simplifications

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@23780 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 pbx/ael/ael.flex | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/pbx/ael/ael.flex b/pbx/ael/ael.flex
index 5d360141e0..24a621acfe 100644
--- a/pbx/ael/ael.flex
+++ b/pbx/ael/ael.flex
@@ -239,10 +239,11 @@ includes	{ STORE_POS; return KW_INCLUDES;}
 		} else {
 			STORE_LOC;
 			yylval->str = strdup(yytext);
-			yylval->str[strlen(yylval->str)-1] = '\0'; /* trim trailing ')' */
+			yylval->str[yyleng - 1] = '\0'; /* trim trailing ')' */
 			unput(')');
+			/* XXX should do my_col-- as we do in other cases ? */
 			BEGIN(0);
-			return word;
+			return word;	/* note it can be an empty string */
 		}
 	}
 
@@ -289,7 +290,10 @@ includes	{ STORE_POS; return KW_INCLUDES;}
 			yymore();
 		} else {
 			STORE_LOC;
-			/* we have at least 1 char. If it is a single ')', just return it */
+			/* we have at least 1 char.
+			 * If it is a single ')', just return it.
+			 * XXX this means we never return an empty 'word' in this context
+			 */
 			if ( !strcmp(yytext, ")") )
 				return RP;
 			yylval->str = strdup(yytext);
@@ -306,14 +310,17 @@ includes	{ STORE_POS; return KW_INCLUDES;}
 			yymore();
 		} else  {
 			STORE_LOC;
-			/* we have at least 1 char. If it is a single comma, just return it */
+			/* we have at least 1 char.
+			 * If it is a single ',', just return it.
+			 * XXX this means we never return an empty 'word' in this context
+			 */
 			if (!strcmp(yytext, "," ) )
 				return COMMA;
-			yylval->str = strdup(yytext);
 			/* otherwise return the string first, then the comma. */
+			yylval->str = strdup(yytext);
+			yylval->str[yyleng-1] = '\0'; /* trim the comma off the string */
 			unput(',');
 			my_col--;	/* XXX not entirely correct, should go 'back' by 1 char */
-			yylval->str[yyleng-1] = '\0'; /* trim the comma off the string */
 			return word;
 		}
 	}
@@ -353,8 +360,7 @@ includes	{ STORE_POS; return KW_INCLUDES;}
 <semic>{NOSEMIC};	{
 		STORE_LOC;
 		yylval->str = strdup(yytext);
-		if(yyleng > 1)
-			*(yylval->str+yyleng-1)=0;
+		yylval->str[yyleng-1] = '\0';
 		unput(';');
 		BEGIN(0);
 		return word;
-- 
GitLab