[pacman-dev,1/3] vercmp: fail when the wrong number of arguments are provided

Message ID 20171217192824.26777-1-eschwartz@archlinux.org
State Superseded, archived
Headers show
Series [pacman-dev,1/3] vercmp: fail when the wrong number of arguments are provided | expand

Commit Message

Eli Schwartz Dec. 17, 2017, 7:28 p.m. UTC
Fixes FS#49093

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
---
 src/util/vercmp.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

Comments

Andrew Gregory Dec. 18, 2017, 2:53 a.m. UTC | #1
On 12/17/17 at 02:28pm, Eli Schwartz wrote:
> Fixes FS#49093
> 
> Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
> ---
>  src/util/vercmp.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/src/util/vercmp.c b/src/util/vercmp.c
> index 3521a96a..7b34b30a 100644
> --- a/src/util/vercmp.c
> +++ b/src/util/vercmp.c
> @@ -40,8 +40,6 @@ static void usage(void)
>  
>  int main(int argc, char *argv[])
>  {
> -	const char *s1 = "";
> -	const char *s2 = "";
>  	int ret;
>  
>  	if(argc == 1) {
> @@ -54,14 +52,12 @@ int main(int argc, char *argv[])
>  		usage();
>  		return 0;
>  	}
> -	if(argc > 2) {
> -		s2 = argv[2];
> -	}
> -	if(argc > 1) {
> -		s1 = argv[1];
> +	if(argc != 3) {
> +		printf("error: %d arguments specified but vercmp needs 2\n", argc-1);

Errors should go to stderr, not stdout, and our style guidelines
require spaces around arithmetic operators.

> +		return EXIT_FAILURE;
>  	}
>  
> -	ret = alpm_pkg_vercmp(s1, s2);
> +	ret = alpm_pkg_vercmp(argv[1], argv[2]);
>  	printf("%d\n", ret);
>  	return EXIT_SUCCESS;
>  }
> -- 
> 2.15.1

Patch

diff --git a/src/util/vercmp.c b/src/util/vercmp.c
index 3521a96a..7b34b30a 100644
--- a/src/util/vercmp.c
+++ b/src/util/vercmp.c
@@ -40,8 +40,6 @@  static void usage(void)
 
 int main(int argc, char *argv[])
 {
-	const char *s1 = "";
-	const char *s2 = "";
 	int ret;
 
 	if(argc == 1) {
@@ -54,14 +52,12 @@  int main(int argc, char *argv[])
 		usage();
 		return 0;
 	}
-	if(argc > 2) {
-		s2 = argv[2];
-	}
-	if(argc > 1) {
-		s1 = argv[1];
+	if(argc != 3) {
+		printf("error: %d arguments specified but vercmp needs 2\n", argc-1);
+		return EXIT_FAILURE;
 	}
 
-	ret = alpm_pkg_vercmp(s1, s2);
+	ret = alpm_pkg_vercmp(argv[1], argv[2]);
 	printf("%d\n", ret);
 	return EXIT_SUCCESS;
 }