[3/5] lib/igt_core: 0 is a valid val for long options

Submitted by Lucas De Marchi on May 29, 2019, 11:27 p.m.

Details

Message ID 20190529232737.31515-3-lucas.demarchi@intel.com
State Accepted
Commit 94a28f391f77f676ab5d412c17d068f970dd4f78
Headers show
Series "Series without cover letter" ( rev: 1 ) in IGT (deprecated)

Not browsing as part of any series.

Commit Message

Lucas De Marchi May 29, 2019, 11:27 p.m.
This is usually used by long options when working with enum to set long
option values. So replace the strchr() with a memchr() to take that into
account.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
 lib/igt_core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 814f5c72..a0b7e581 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -680,6 +680,7 @@  static int common_init(int *argc, char **argv,
 	};
 	char *short_opts;
 	const char *std_short_opts = "h";
+	size_t std_short_opts_len = strlen(std_short_opts);
 	struct option *combined_opts;
 	int extra_opt_count;
 	int all_opt_count;
@@ -713,7 +714,7 @@  static int common_init(int *argc, char **argv,
 
 		/* check for conflicts with standard short options */
 		if (extra_long_opts[extra_opt_count].val != ':'
-		    && (conflicting_char = strchr(std_short_opts, extra_long_opts[extra_opt_count].val))) {
+		    && (conflicting_char = memchr(std_short_opts, extra_long_opts[extra_opt_count].val, std_short_opts_len))) {
 			igt_critical("Conflicting long and short option 'val' representation between --%s and -%c\n",
 				     extra_long_opts[extra_opt_count].name,
 				     *conflicting_char);
@@ -727,7 +728,7 @@  static int common_init(int *argc, char **argv,
 			continue;
 
 		/* check for conflicts with standard short options */
-		if (strchr(std_short_opts, extra_short_opts[i])) {
+		if (memchr(std_short_opts, extra_short_opts[i], std_short_opts_len)) {
 			igt_critical("Conflicting short option: -%c\n", std_short_opts[i]);
 			assert(0);
 		}

Comments

On Wed, May 29, 2019 at 04:27:35PM -0700, Lucas De Marchi wrote:
> This is usually used by long options when working with enum to set long
> option values. So replace the strchr() with a memchr() to take that into
> account.
> 
> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>

Reviewed-by: Petri Latvala <petri.latvala@intel.com>

The latter strchr-memchr change is needless but meh.


> ---
>  lib/igt_core.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index 814f5c72..a0b7e581 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -680,6 +680,7 @@ static int common_init(int *argc, char **argv,
>  	};
>  	char *short_opts;
>  	const char *std_short_opts = "h";
> +	size_t std_short_opts_len = strlen(std_short_opts);
>  	struct option *combined_opts;
>  	int extra_opt_count;
>  	int all_opt_count;
> @@ -713,7 +714,7 @@ static int common_init(int *argc, char **argv,
>  
>  		/* check for conflicts with standard short options */
>  		if (extra_long_opts[extra_opt_count].val != ':'
> -		    && (conflicting_char = strchr(std_short_opts, extra_long_opts[extra_opt_count].val))) {
> +		    && (conflicting_char = memchr(std_short_opts, extra_long_opts[extra_opt_count].val, std_short_opts_len))) {
>  			igt_critical("Conflicting long and short option 'val' representation between --%s and -%c\n",
>  				     extra_long_opts[extra_opt_count].name,
>  				     *conflicting_char);
> @@ -727,7 +728,7 @@ static int common_init(int *argc, char **argv,
>  			continue;
>  
>  		/* check for conflicts with standard short options */
> -		if (strchr(std_short_opts, extra_short_opts[i])) {
> +		if (memchr(std_short_opts, extra_short_opts[i], std_short_opts_len)) {
>  			igt_critical("Conflicting short option: -%c\n", std_short_opts[i]);
>  			assert(0);
>  		}
> -- 
> 2.21.0
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx