diff mbox series

[04/12] utils: don't check unsigned for < 0.

Message ID 20200422003735.3891-4-rosenp@gmail.com (mailing list archive)
State New, archived
Headers show
Series [01/12] utils: fix compilation with C++98 | expand

Commit Message

Rosen Penev April 22, 2020, 12:37 a.m. UTC
Found with -Wtautological-unsigned-zero-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 utils/v4l2-compliance/v4l2-test-controls.cpp | 2 --
 1 file changed, 2 deletions(-)

Comments

Hans Verkuil April 23, 2020, 8:30 a.m. UTC | #1
On 22/04/2020 02:37, Rosen Penev wrote:
> Found with -Wtautological-unsigned-zero-compare
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  utils/v4l2-compliance/v4l2-test-controls.cpp | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/utils/v4l2-compliance/v4l2-test-controls.cpp b/utils/v4l2-compliance/v4l2-test-controls.cpp
> index 8c4480be..251a6049 100644
> --- a/utils/v4l2-compliance/v4l2-test-controls.cpp
> +++ b/utils/v4l2-compliance/v4l2-test-controls.cpp
> @@ -80,8 +80,6 @@ static int checkQCtrl(struct node *node, struct test_query_ext_ctrl &qctrl)
>  			return fail("min > max\n");
>  		if (qctrl.step == 0)
>  			return fail("step == 0\n");
> -		if (qctrl.step < 0)
> -			return fail("step < 0\n");

Ah, nice. This is actually a bug since this test needs to be done for
struct v4l2_queryctl (where step is signed) instead of struct v4l2_query_ext_ctrl
(where step is unsigned).

I've made a patch fixing this correctly.

Regards,

	Hans

>  		if (static_cast<unsigned>(qctrl.step) > static_cast<unsigned>(qctrl.maximum - qctrl.minimum) &&
>  		    qctrl.maximum != qctrl.minimum)
>  			return fail("step > max - min\n");
>
Rosen Penev April 23, 2020, 8:33 a.m. UTC | #2
> On Apr 23, 2020, at 1:30 AM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
> 
> On 22/04/2020 02:37, Rosen Penev wrote:
>> Found with -Wtautological-unsigned-zero-compare
>> 
>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>> ---
>> utils/v4l2-compliance/v4l2-test-controls.cpp | 2 --
>> 1 file changed, 2 deletions(-)
>> 
>> diff --git a/utils/v4l2-compliance/v4l2-test-controls.cpp b/utils/v4l2-compliance/v4l2-test-controls.cpp
>> index 8c4480be..251a6049 100644
>> --- a/utils/v4l2-compliance/v4l2-test-controls.cpp
>> +++ b/utils/v4l2-compliance/v4l2-test-controls.cpp
>> @@ -80,8 +80,6 @@ static int checkQCtrl(struct node *node, struct test_query_ext_ctrl &qctrl)
>>            return fail("min > max\n");
>>        if (qctrl.step == 0)
>>            return fail("step == 0\n");
>> -        if (qctrl.step < 0)
>> -            return fail("step < 0\n");
> 
> Ah, nice. This is actually a bug since this test needs to be done for
> struct v4l2_queryctl (where step is signed) instead of struct v4l2_query_ext_ctrl
> (where step is unsigned).
> 
> I've made a patch fixing this correctly.
Sounds good.
> 
> Regards,
> 
>    Hans
> 
>>        if (static_cast<unsigned>(qctrl.step) > static_cast<unsigned>(qctrl.maximum - qctrl.minimum) &&
>>            qctrl.maximum != qctrl.minimum)
>>            return fail("step > max - min\n");
>> 
>
diff mbox series

Patch

diff --git a/utils/v4l2-compliance/v4l2-test-controls.cpp b/utils/v4l2-compliance/v4l2-test-controls.cpp
index 8c4480be..251a6049 100644
--- a/utils/v4l2-compliance/v4l2-test-controls.cpp
+++ b/utils/v4l2-compliance/v4l2-test-controls.cpp
@@ -80,8 +80,6 @@  static int checkQCtrl(struct node *node, struct test_query_ext_ctrl &qctrl)
 			return fail("min > max\n");
 		if (qctrl.step == 0)
 			return fail("step == 0\n");
-		if (qctrl.step < 0)
-			return fail("step < 0\n");
 		if (static_cast<unsigned>(qctrl.step) > static_cast<unsigned>(qctrl.maximum - qctrl.minimum) &&
 		    qctrl.maximum != qctrl.minimum)
 			return fail("step > max - min\n");