batctl: exit on parse error in batctl ll

Message ID 1327238532-8433-1-git-send-email-siwu@hrz.tu-chemnitz.de (mailing list archive)
State Superseded, archived
Headers

Commit Message

Simon Wunderlich Jan. 22, 2012, 1:22 p.m. UTC
  If the argument could not be understood, we should not try to
apply something, but return from the function.

Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
---
 sys.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
  

Comments

Marek Lindner Jan. 22, 2012, 1:46 p.m. UTC | #1
On Sunday, January 22, 2012 21:22:12 Simon Wunderlich wrote:
> If the argument could not be understood, we should not try to
> apply something, but return from the function.
> 
> Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
> ---
>  sys.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/sys.c b/sys.c
> index 9cdccba..ab7d75f 100644
> --- a/sys.c
> +++ b/sys.c
> @@ -221,8 +221,11 @@ int handle_loglevel(char *mesh_iface, int argc, char
> **argv) log_level |= (1 << 1);
>  			else if (strcmp(argv[i], "tt") == 0)
>  				log_level |= (1 << 2);
> -			else
> +			else {
>  				log_level_usage();
> +				free(path_buff);
> +				return EXIT_FAILURE;
> +			}
>  		}
> 
>  		snprintf(str, sizeof(str), "%i", log_level);


Can't we do "goto out" instead of duplicating the free/return. If we do so, 
res should be initialized with EXIT_FAILURE.

Regards,
Marek
  

Patch

diff --git a/sys.c b/sys.c
index 9cdccba..ab7d75f 100644
--- a/sys.c
+++ b/sys.c
@@ -221,8 +221,11 @@  int handle_loglevel(char *mesh_iface, int argc, char **argv)
 				log_level |= (1 << 1);
 			else if (strcmp(argv[i], "tt") == 0)
 				log_level |= (1 << 2);
-			else
+			else {
 				log_level_usage();
+				free(path_buff);
+				return EXIT_FAILURE;
+			}
 		}
 
 		snprintf(str, sizeof(str), "%i", log_level);