Re: [PATCH nft] proto: revisit short-circuit loops over upper protocols

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2021-12-16, at 00:36:06 +0100, Pablo Neira Ayuso wrote:
> Move the check for NULL protocol description away from the loop to
> avoid too long line.

LGTM.

J.

> Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
>
> ---
>  src/proto.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/src/proto.c b/src/proto.c
> index 31a2f38065ad..a013a00d2c7b 100644
> --- a/src/proto.c
> +++ b/src/proto.c
> @@ -59,8 +59,9 @@ proto_find_upper(const struct proto_desc *base, unsigned int num)
>  {
>  	unsigned int i;
>
> -	for (i = 0; i < array_size(base->protocols) && base->protocols[i].desc;
> -	     i++) {
> +	for (i = 0; i < array_size(base->protocols); i++) {
> +		if (!base->protocols[i].desc)
> +			break;
>  		if (base->protocols[i].num == num)
>  			return base->protocols[i].desc;
>  	}
> @@ -78,8 +79,9 @@ int proto_find_num(const struct proto_desc *base,
>  {
>  	unsigned int i;
>
> -	for (i = 0; i < array_size(base->protocols) && base->protocols[i].desc;
> -	     i++) {
> +	for (i = 0; i < array_size(base->protocols); i++) {
> +		if (!base->protocols[i].desc)
> +			break;
>  		if (base->protocols[i].desc == desc)
>  			return base->protocols[i].num;
>  	}
> @@ -107,9 +109,9 @@ int proto_dev_type(const struct proto_desc *desc, uint16_t *res)
>  			*res = dev_proto_desc[i].type;
>  			return 0;
>  		}
> -		for (j = 0; j < array_size(base->protocols) &&
> -			     base->protocols[j].desc;
> -		     j++) {
> +		for (j = 0; j < array_size(base->protocols); j++) {
> +			if (!base->protocols[j].desc)
> +				break;
>  			if (base->protocols[j].desc == desc) {
>  				*res = dev_proto_desc[i].type;
>  				return 0;
> --
> 2.30.2
>
>

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux