svn commit: r245057 - head/usr.bin/grep

Andrey Chernov ache at freebsd.org
Sat Jan 5 23:54:14 UTC 2013


Thanks. I think the fix below can be improved further, because strdup(3)
is unneeded here and can be omitted. We don't have either constant
argument nor want to preserve it.

On 05.01.2013 18:52, Gabor Kovesdan wrote:
>  		case 'e':
> -			add_pattern(optarg, strlen(optarg));
> +			{
> +				char *token;
> +				char *string = strdup(optarg);
> +
> +				while ((token = strsep(&string, "\n")) != NULL)
> +					add_pattern(token, strlen(token));
> +			}
>  			needpattern = 0;
>  			break;
>  		case 'F':
> @@ -668,7 +674,11 @@ main(int argc, char *argv[])
>  
>  	/* Process patterns from command line */
>  	if (aargc != 0 && needpattern) {
> -		add_pattern(*aargv, strlen(*aargv));
> +		char *token;
> +		char *string = strdup(*aargv);
> +
> +		while ((token = strsep(&string, "\n")) != NULL)
> +			add_pattern(token, strlen(token));
>  		--aargc;
>  		++aargv;
>  	}
> 



More information about the svn-src-head mailing list