diff mbox

[i-g-t] tests/gem_concurrent_all: Please the compiler regarding fscanfs unused result.

Message ID 1459876403-4338-1-git-send-email-marius.c.vlad@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Marius Vlad April 5, 2016, 5:13 p.m. UTC
Signed-off-by: Marius Vlad <marius.c.vlad@intel.com>
---
 tests/gem_concurrent_all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Chris Wilson April 5, 2016, 5:23 p.m. UTC | #1
On Tue, Apr 05, 2016 at 08:13:23PM +0300, Marius Vlad wrote:
> Signed-off-by: Marius Vlad <marius.c.vlad@intel.com>
> ---
>  tests/gem_concurrent_all.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
> index 10e5357..e84ded3 100644
> --- a/tests/gem_concurrent_all.c
> +++ b/tests/gem_concurrent_all.c
> @@ -650,7 +650,7 @@ static int read_sysctl(const char *path)
>  	FILE *file = fopen(path, "r");
>  	int max = 0;
>  	if (file) {
> -		fscanf(file, "%d", &max);
> +		igt_assert(fscanf(file, "%d", &max) == 1);

But the code is written in case fscanf() actually fails...
-Chris
Marius Vlad April 5, 2016, 5:34 p.m. UTC | #2
On Tue, Apr 05, 2016 at 06:23:21PM +0100, Chris Wilson wrote:
> On Tue, Apr 05, 2016 at 08:13:23PM +0300, Marius Vlad wrote:
> > Signed-off-by: Marius Vlad <marius.c.vlad@intel.com>
> > ---
> >  tests/gem_concurrent_all.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
> > index 10e5357..e84ded3 100644
> > --- a/tests/gem_concurrent_all.c
> > +++ b/tests/gem_concurrent_all.c
> > @@ -650,7 +650,7 @@ static int read_sysctl(const char *path)
> >  	FILE *file = fopen(path, "r");
> >  	int max = 0;
> >  	if (file) {
> > -		fscanf(file, "%d", &max);
> > +		igt_assert(fscanf(file, "%d", &max) == 1);
> 
> But the code is written in case fscanf() actually fails...
It will never fail...

Would (void) fscanf() be better?

> -Chris
> 
> -- 
> Chris Wilson, Intel Open Source Technology Centre
Chris Wilson April 5, 2016, 5:45 p.m. UTC | #3
On Tue, Apr 05, 2016 at 08:34:02PM +0300, Marius Vlad wrote:
> On Tue, Apr 05, 2016 at 06:23:21PM +0100, Chris Wilson wrote:
> > On Tue, Apr 05, 2016 at 08:13:23PM +0300, Marius Vlad wrote:
> > > Signed-off-by: Marius Vlad <marius.c.vlad@intel.com>
> > > ---
> > >  tests/gem_concurrent_all.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
> > > index 10e5357..e84ded3 100644
> > > --- a/tests/gem_concurrent_all.c
> > > +++ b/tests/gem_concurrent_all.c
> > > @@ -650,7 +650,7 @@ static int read_sysctl(const char *path)
> > >  	FILE *file = fopen(path, "r");
> > >  	int max = 0;
> > >  	if (file) {
> > > -		fscanf(file, "%d", &max);
> > > +		igt_assert(fscanf(file, "%d", &max) == 1);
> > 
> > But the code is written in case fscanf() actually fails...
> It will never fail...
> 
> Would (void) fscanf() be better?

Not sure if that silences the compiler though. Last I recall having to
do

int ignored = fscanf();
(void) ignored;

and then you get compiler warnings about set-but-not-used variables!

#define ignore(x) if ((x)) {} else {}
#define ignore(x) ((x) ?: 0)

/o\
-Chris
diff mbox

Patch

diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
index 10e5357..e84ded3 100644
--- a/tests/gem_concurrent_all.c
+++ b/tests/gem_concurrent_all.c
@@ -650,7 +650,7 @@  static int read_sysctl(const char *path)
 	FILE *file = fopen(path, "r");
 	int max = 0;
 	if (file) {
-		fscanf(file, "%d", &max);
+		igt_assert(fscanf(file, "%d", &max) == 1);
 		fclose(file);
 	}
 	return max;