From: Bart Van Assche Date: Mon, 29 Oct 2018 21:34:00 +0000 (-0700) Subject: src/discontiguous-io: Do not shadow variables X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a3e09ef28cc1d8ae30cf39cf19ec38a7577c77eb;p=users%2Fsagi%2Fblktests.git src/discontiguous-io: Do not shadow variables 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 --- diff --git a/src/Makefile b/src/Makefile index 15c1022..e1c1c14 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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) diff --git a/src/discontiguous-io.cpp b/src/discontiguous-io.cpp index f51a305..31a07ef 100644 --- a/src/discontiguous-io.cpp +++ b/src/discontiguous-io.cpp @@ -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); } }