summaryrefslogtreecommitdiff
blob: 739488b53f971ada608368618e115e353e0124ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
From 77d2ceb374ff70b64e95a41f0e05486575147b53 Mon Sep 17 00:00:00 2001
From: Michel Machado <michel@digirati.com.br>
Date: Mon, 4 Jan 2016 13:49:05 -0500
Subject: [PATCH] f3probe: avoid compiler warning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When using -O2, GCC was issuing the following warning:

cc -O2 -std=c99 -Wall -Wextra -pedantic -MMD -ggdb -c -o f3probe.o f3probe.c
f3probe.c: In function ‘main’:
f3probe.c:446:13: warning: ‘sdev’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   sdev_flush(sdev);
             ^
f3probe.c:369:30: note: ‘sdev’ was declared here
  struct device *dev, *pdev, *sdev;
                              ^

NOTE: The warning was wrong.
      GCC could not follow that @args->save being true implied
      @sdev to not be NULL.

This patch addresses one of the issues discussed here:
https://github.com/AltraMayor/f3/issues/34
---
 f3probe.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/f3probe.c b/f3probe.c
index e647d7c..9f214ab 100644
--- a/f3probe.c
+++ b/f3probe.c
@@ -393,6 +393,7 @@ static int test_device(struct args *args)
 		pdev = NULL;
 	}
 
+	sdev = NULL;
 	if (args->save) {
 		sdev = create_safe_device(dev,
 			probe_device_max_blocks(dev), args->min_mem);
@@ -434,7 +435,7 @@ static int test_device(struct args *args)
 			&read_count, &read_time_us,
 			&write_count, &write_time_us,
 			&reset_count, &reset_time_us);
-	if (args->save) {
+	if (sdev) {
 		uint64_t very_last_pos = real_size_byte >> block_order;
 		printf("Probe finished, recovering blocks...");
 		fflush(stdout);