[Piglit] [PATCH] select: Fix Clang absolute-value warnings.

Brian Paul brianp at vmware.com
Mon Mar 23 07:37:33 PDT 2015


On 03/22/2015 12:50 AM, Vinson Lee wrote:
> select.c:126:10: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value]
>          diffz = abs(hit1[MIN_Z] - hit2[MIN_Z])/zscale;
>                  ^
> select.c:126:10: note: remove the call to 'abs' since unsigned values cannot be negative
>          diffz = abs(hit1[MIN_Z] - hit2[MIN_Z])/zscale;
>                  ^~~
> select.c:138:10: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value]
>          diffz = abs(hit1[MAX_Z] - hit2[MAX_Z])/zscale;
>                  ^
> select.c:138:10: note: remove the call to 'abs' since unsigned values cannot be negative
>          diffz = abs(hit1[MAX_Z] - hit2[MAX_Z])/zscale;
>                  ^~~
>
> Signed-off-by: Vinson Lee <vlee at freedesktop.org>
> ---
>   tests/general/select.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tests/general/select.c b/tests/general/select.c
> index 879a1e9..c90946e 100644
> --- a/tests/general/select.c
> +++ b/tests/general/select.c
> @@ -123,7 +123,7 @@ compare_hit_record(GLuint* hit1, GLuint* hit2)
>   		return false;
>   	}
>
> -	diffz = abs(hit1[MIN_Z] - hit2[MIN_Z])/zscale;
> +	diffz = (hit1[MIN_Z] - hit2[MIN_Z])/zscale;
>   	if (diffz > 0.1) {
>   		printf("\t%s : Incorrect Minz : %u %u (%f %f) %f\n",
>   			__FUNCTION__,
> @@ -135,7 +135,7 @@ compare_hit_record(GLuint* hit1, GLuint* hit2)
>   		return false;
>   	}
>
> -	diffz = abs(hit1[MAX_Z] - hit2[MAX_Z])/zscale;
> +	diffz = (hit1[MAX_Z] - hit2[MAX_Z])/zscale;
>   	if (diffz > 0.1) {
>   		printf("\t%s : Incorrect Maxz : %u %u (%f %f) %f\n",
>   			__FUNCTION__,
>

Same comment as the previous one.  We need to cast the terms of the 
subtraction to int.

-Brian



More information about the Piglit mailing list