Skip to contentSkip to conversation

tests/gem_concurrent_all: Please the compiler regarding fscanfs unused result.

PATCH In review Marius Vlad 2 participants 4 messages Apr 5, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/gem_concurrent_all: Please the compiler regarding fscanfs unused result.

---
 tests/gem_concurrent_all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/gem_concurrent_all.c +1 -1
index 10e5357..e84ded3 100644
@@ -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;
Signature · 6 lines
2.8.0.rc3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 10 lines · Marius Vlad
---
 tests/gem_concurrent_all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/gem_concurrent_all.c +0 -0
index 10e5357..e84ded3 100644

tests/gem_concurrent_all.c static int read_sysctl(const char *path) · line 653

Quoted 5 lines
tests/gem_concurrent_all.c +1 -1
@@ -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

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
Quoted 6 lines · Chris Wilson
Quoted 5 lines · Marius Vlad
---
 tests/gem_concurrent_all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

tests/gem_concurrent_all.c static int read_sysctl(const char *path) · line 653

Quoted 10 lines
tests/gem_concurrent_all.c +1 -1
index 10e5357..e84ded3 100644
@@ -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?

Quoted 4 lines

-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
Quoted 19 lines · Marius Vlad
Quoted 6 lines · Chris Wilson
Quoted 5 lines · Marius Vlad
---
 tests/gem_concurrent_all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

tests/gem_concurrent_all.c static int read_sysctl(const char *path) · line 653

Quoted 10 lines
tests/gem_concurrent_all.c +1 -1
index 10e5357..e84ded3 100644
@@ -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...

Quoted 3 lines

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

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx