[dpdk-dev,v3] examples/ipsec-secgw: fix pointer to local outside scope

Message ID 1478539537-225559-1-git-send-email-roy.fan.zhang@intel.com (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
tmonjalo/checkpatch warning coding style issues

Commit Message

Fan Zhang Nov. 7, 2016, 5:25 p.m. UTC
  Coverity issue: 137871
Fixes: 0d547ed03717 ("examples/ipsec-secgw: support configuration file")

Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
---
 examples/ipsec-secgw/parser.c | 116 +++++++++++++++++++-----------------------
 1 file changed, 52 insertions(+), 64 deletions(-)
  

Comments

Ferruh Yigit Nov. 7, 2016, 5:31 p.m. UTC | #1
On 11/7/2016 5:25 PM, Fan Zhang wrote:
> Coverity issue: 137871
> Fixes: 0d547ed03717 ("examples/ipsec-secgw: support configuration file")
> 
> Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
> ---

Although checkpatch will complain about long lines, I believe it is
better not to wrap log messages.

Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
  
Thomas Monjalon Nov. 7, 2016, 8:48 p.m. UTC | #2
2016-11-07 17:31, Ferruh Yigit:
> On 11/7/2016 5:25 PM, Fan Zhang wrote:
> > Coverity issue: 137871
> > Fixes: 0d547ed03717 ("examples/ipsec-secgw: support configuration file")
> > 
> > Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
> 
> Although checkpatch will complain about long lines, I believe it is
> better not to wrap log messages.
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>

Wrapped after "error: " to avoid too long lines
while being able to grep the rest of the message,
and applied.
  

Patch

diff --git a/examples/ipsec-secgw/parser.c b/examples/ipsec-secgw/parser.c
index 598f435..c5f2508 100644
--- a/examples/ipsec-secgw/parser.c
+++ b/examples/ipsec-secgw/parser.c
@@ -487,8 +487,7 @@  parse_cfg_file(const char *cfg_filename)
 	struct parse_status status = {0};
 
 	if (f == NULL) {
-		rte_panic("Error: invalid file descriptor %s\n",
-			cfg_filename);
+		rte_panic("Error: invalid file descriptor %s\n", cfg_filename);
 		goto error_exit;
 	}
 
@@ -503,86 +502,75 @@  parse_cfg_file(const char *cfg_filename)
 
 	do {
 		char oneline[1024];
-
+		char *pos;
 		get_s = fgets(oneline, 1024, f);
-		if (get_s) {
-			char *pos;
 
-			line_num++;
+		if (!get_s)
+			break;
 
-			if (strlen(oneline) > 1022) {
-				rte_panic("%s:%u: error: the line "
-					"contains more characters the "
-					"parser can handle\n",
-					cfg_filename, line_num);
-				goto error_exit;
-			}
+		line_num++;
 
-			/* process comment char '#' */
-			if (oneline[0] == '#')
-				continue;
+		if (strlen(oneline) > 1022) {
+			rte_panic("%s:%u: error: the line contains more characters the parser can handle\n",
+				cfg_filename, line_num);
+			goto error_exit;
+		}
 
-			pos = strchr(oneline, '#');
-			if (pos != NULL)
-				*pos = '\0';
-
-			/* process line concatenator '\' */
-			pos = strchr(oneline, 92);
-			if (pos != NULL) {
-				if (pos != oneline+strlen(oneline) - 2) {
-					rte_panic("%s:%u: error: no "
-						"character should exist "
-						"after '\\' symbol\n",
-						cfg_filename, line_num);
-					goto error_exit;
-				}
-
-				*pos = '\0';
-
-				if (strlen(oneline) + strlen(str) > 1022) {
-					rte_panic("%s:%u: error: the "
-						"concatenated line "
-						"contains more characters "
-						"the parser can handle\n",
-						cfg_filename, line_num);
-					goto error_exit;
-				}
-
-				strncpy(str + strlen(str), oneline,
-					strlen(oneline));
+		/* process comment char '#' */
+		if (oneline[0] == '#')
+			continue;
 
-				continue;
+		pos = strchr(oneline, '#');
+		if (pos != NULL)
+			*pos = '\0';
+
+		/* process line concatenator '\' */
+		pos = strchr(oneline, 92);
+		if (pos != NULL) {
+			if (pos != oneline+strlen(oneline) - 2) {
+				rte_panic("%s:%u: error: no character should exist after '\\'\n",
+					cfg_filename, line_num);
+				goto error_exit;
 			}
 
-			/* copy the line to str and process */
+			*pos = '\0';
+
 			if (strlen(oneline) + strlen(str) > 1022) {
-				rte_panic("%s:%u: error: the line "
-					"contains more characters the "
-					"parser can handle\n",
+				rte_panic("%s:%u: error: the concatenated line contains more characters the parser can handle\n",
 					cfg_filename, line_num);
 				goto error_exit;
 			}
+
 			strncpy(str + strlen(str), oneline,
 				strlen(oneline));
 
-			str[strlen(str)] = '\n';
-			if (cmdline_parse(cl, str) < 0) {
-				rte_panic("%s:%u: error: parsing \"%s\" "
-					"failed\n", cfg_filename,
-					line_num, str);
-				goto error_exit;
-			}
+			continue;
+		}
 
-			if (status.status < 0) {
-				rte_panic("%s:%u: error: %s",
-					cfg_filename, line_num,
-					status.parse_msg);
-				goto error_exit;
-			}
+		/* copy the line to str and process */
+		if (strlen(oneline) + strlen(str) > 1022) {
+			rte_panic("%s:%u: error: the line contains more characters the parser can handle\n",
+				cfg_filename, line_num);
+			goto error_exit;
+		}
+		strncpy(str + strlen(str), oneline,
+			strlen(oneline));
+
+		str[strlen(str)] = '\n';
+		if (cmdline_parse(cl, str) < 0) {
+			rte_panic("%s:%u: error: parsing \"%s\" failed\n",
+				cfg_filename, line_num, str);
+			goto error_exit;
+		}
 
-			memset(str, 0, 1024);
+		if (status.status < 0) {
+			rte_panic("%s:%u: error: %s", cfg_filename,
+				line_num, status.parse_msg);
+			goto error_exit;
 		}
-	} while (get_s != NULL);
+
+		memset(str, 0, 1024);
+	} while (1);
 
 	cmdline_stdin_exit(cl);
 	fclose(f);