[v2] cl: Guard against CL version overflow.

Submitted by Vinson Lee on July 25, 2017, 12:09 a.m.

Details

Message ID 1500941377-28590-1-git-send-email-vlee@freedesktop.org
State New
Headers show
Series "cl: Guard against CL version overflow." ( rev: 2 ) in Piglit

Not browsing as part of any series.

Commit Message

Vinson Lee July 25, 2017, 12:09 a.m.
Fix Coverity overflowed return value defect.

CID: 1364163
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
---
 tests/util/piglit-framework-cl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/tests/util/piglit-framework-cl.c b/tests/util/piglit-framework-cl.c
index 235f160877cf..758508ff902f 100644
--- a/tests/util/piglit-framework-cl.c
+++ b/tests/util/piglit-framework-cl.c
@@ -450,6 +450,7 @@  piglit_cl_get_version_arg(int argc, const char** argv)
 {
 	int version_major = 0;
 	int version_minor = 0;
+	int version = 0;
 
 	const char* version_str;
 
@@ -466,7 +467,9 @@  piglit_cl_get_version_arg(int argc, const char** argv)
 		}
 	}
 
-	return version_major*10 + version_minor;
+	version = version_major*10 + version_minor;
+	assert(version > 0);
+	return version;
 }
 
 bool

Comments

On Tue, 2017-07-25 at 00:09 +0000, Vinson Lee wrote:
> Fix Coverity overflowed return value defect.
> 
> CID: 1364163
> Signed-off-by: Vinson Lee <vlee@freedesktop.org>

although it relies on signed overflow wraparound. if it cleans up
coverity output
Acked-by: Jan Vesely <jan.vesely@rutgers.edu>

Jan

> ---
>  tests/util/piglit-framework-cl.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/util/piglit-framework-cl.c b/tests/util/piglit-framework-cl.c
> index 235f160877cf..758508ff902f 100644
> --- a/tests/util/piglit-framework-cl.c
> +++ b/tests/util/piglit-framework-cl.c
> @@ -450,6 +450,7 @@ piglit_cl_get_version_arg(int argc, const char** argv)
>  {
>  	int version_major = 0;
>  	int version_minor = 0;
> +	int version = 0;
>  
>  	const char* version_str;
>  
> @@ -466,7 +467,9 @@ piglit_cl_get_version_arg(int argc, const char** argv)
>  		}
>  	}
>  
> -	return version_major*10 + version_minor;
> +	version = version_major*10 + version_minor;
> +	assert(version > 0);
> +	return version;
>  }
>  
>  bool
On 07/24/2017 06:09 PM, Vinson Lee wrote:
> Fix Coverity overflowed return value defect.
>
> CID: 1364163
> Signed-off-by: Vinson Lee <vlee@freedesktop.org>
> ---
>   tests/util/piglit-framework-cl.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tests/util/piglit-framework-cl.c b/tests/util/piglit-framework-cl.c
> index 235f160877cf..758508ff902f 100644
> --- a/tests/util/piglit-framework-cl.c
> +++ b/tests/util/piglit-framework-cl.c
> @@ -450,6 +450,7 @@ piglit_cl_get_version_arg(int argc, const char** argv)
>   {
>   	int version_major = 0;
>   	int version_minor = 0;
> +	int version = 0;
>
>   	const char* version_str;
>
> @@ -466,7 +467,9 @@ piglit_cl_get_version_arg(int argc, const char** argv)
>   		}
>   	}
>
> -	return version_major*10 + version_minor;
> +	version = version_major*10 + version_minor;
> +	assert(version > 0);
> +	return version;
>   }
>
>   bool
>

I'm kind of surprised by that warning.  By that example, it would seem 
that almost any function which does integer arithmetic would be flagged.

Reviewed-by: Brian Paul <brianp@vmware.com>