cl: Guard against CL version overflow.

Submitted by Vinson Lee on July 6, 2017, 9:59 p.m.

Details

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

Not browsing as part of any series.

Commit Message

Vinson Lee July 6, 2017, 9:59 p.m.
Fix Coverity overflowed return value defect.

CID: 1364163
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
---
 tests/util/piglit-framework-cl.c | 8 +++++++-
 1 file changed, 7 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..31346b7d8a17 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;
 
 	const char* version_str;
 
@@ -466,7 +467,12 @@  piglit_cl_get_version_arg(int argc, const char** argv)
 		}
 	}
 
-	return version_major*10 + version_minor;
+	version = version_major*10 + version_minor;
+	if (version < 0) {
+		version = 0;
+	}
+
+	return version;
 }
 
 bool

Comments

Would it make more sense to just make all of that unsigned?

On Thu, Jul 6, 2017 at 5:59 PM, Vinson Lee <vlee@freedesktop.org> wrote:
> Fix Coverity overflowed return value defect.
>
> CID: 1364163
> Signed-off-by: Vinson Lee <vlee@freedesktop.org>
> ---
>  tests/util/piglit-framework-cl.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/tests/util/piglit-framework-cl.c b/tests/util/piglit-framework-cl.c
> index 235f160877cf..31346b7d8a17 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;
>
>         const char* version_str;
>
> @@ -466,7 +467,12 @@ piglit_cl_get_version_arg(int argc, const char** argv)
>                 }
>         }
>
> -       return version_major*10 + version_minor;
> +       version = version_major*10 + version_minor;
> +       if (version < 0) {
> +               version = 0;
> +       }
> +
> +       return version;
>  }
>
>  bool
> --
> 2.11.0
>
> _______________________________________________
> Piglit mailing list
> Piglit@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/piglit
On Thu, 2017-07-06 at 18:46 -0400, Ilia Mirkin wrote:
> Would it make more sense to just make all of that unsigned?

or add an assert. This is a very stretched way to appease static
checker.

Jan

> 
> On Thu, Jul 6, 2017 at 5:59 PM, Vinson Lee <vlee@freedesktop.org> wrote:
> > Fix Coverity overflowed return value defect.
> > 
> > CID: 1364163
> > Signed-off-by: Vinson Lee <vlee@freedesktop.org>
> > ---
> >  tests/util/piglit-framework-cl.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tests/util/piglit-framework-cl.c b/tests/util/piglit-framework-cl.c
> > index 235f160877cf..31346b7d8a17 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;
> > 
> >         const char* version_str;
> > 
> > @@ -466,7 +467,12 @@ piglit_cl_get_version_arg(int argc, const char** argv)
> >                 }
> >         }
> > 
> > -       return version_major*10 + version_minor;
> > +       version = version_major*10 + version_minor;
> > +       if (version < 0) {
> > +               version = 0;
> > +       }
> > +
> > +       return version;
> >  }
> > 
> >  bool
> > --
> > 2.11.0
> > 
> > _______________________________________________
> > Piglit mailing list
> > Piglit@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/piglit
> 
> _______________________________________________
> Piglit mailing list
> Piglit@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/piglit