]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
src/discontiguous-io: Do not shadow variables
authorBart Van Assche <bvanassche@acm.org>
Mon, 29 Oct 2018 21:34:00 +0000 (14:34 -0700)
committerBart Van Assche <bvanassche@acm.org>
Thu, 1 Nov 2018 17:40:42 +0000 (10:40 -0700)
Avoid using variables in an inner scope with the same name as variables in
an outer scope. Enable the -Wshadow compiler flag for C and C++ source
files such that in the future the compiler will complain about shadowing.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
src/Makefile
src/discontiguous-io.cpp

index 15c10226ccb74d82932c0ef657ed179bae9b68f5..e1c1c144fd428eecc20bd64183598948fa641fa2 100644 (file)
@@ -12,8 +12,8 @@ CXX_TARGETS := \
 
 TARGETS := $(C_TARGETS) $(CXX_TARGETS)
 
-CFLAGS := -O2 -Wall
-CXXFLAGS := -O2 -std=c++11 -Wall -Wextra -Wno-sign-compare -Werror
+CFLAGS := -O2 -Wall -Wshadow
+CXXFLAGS := -O2 -std=c++11 -Wall -Wextra -Wshadow -Wno-sign-compare -Werror
 
 all: $(TARGETS)
 
index f51a305f94bbda6c19b56655a8e254e9e305e32b..31a07ef3b359aa982e681342bb5fab2ac5f66c1d 100644 (file)
@@ -306,17 +306,17 @@ int main(int argc, char **argv)
                                        break;
                                }
                        }
-                       ssize_t len = sg_write(fd, offs / block_size, iov);
-                       if (len >= 0)
-                               std::cout << "Wrote " << len << "/"
+                       ssize_t written = sg_write(fd, offs / block_size, iov);
+                       if (written >= 0)
+                               std::cout << "Wrote " << written << "/"
                                          << iov.data_len()
                                          << " bytes of data.\n";
                } else {
-                       ssize_t len = sg_read(fd, offs / block_size, iov);
-                       if (len >= 0) {
-                               std::cerr << "Read " << len
+                       ssize_t read = sg_read(fd, offs / block_size, iov);
+                       if (read >= 0) {
+                               std::cerr << "Read " << read
                                          << " bytes of data:\n";
-                               iov.trunc(len);
+                               iov.trunc(read);
                                iov.write(std::cout);
                        }
                }