From 8f7901dd257849dec0b8ed76813762fed3e039e5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 19 Aug 2016 01:05:43 -0400 Subject: [PATCH] build with warnings as errors in autotools build on travis (#1013) build with warnings as errors in autotools build on travis --- .travis.yml | 2 ++ examples/client_test.cpp | 11 ++++++----- examples/make_torrent.cpp | 8 +++++++- examples/simple_client.cpp | 3 ++- test/main.cpp | 11 +++++++++-- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5cd1445af..121f71a67 100644 --- a/.travis.yml +++ b/.travis.yml @@ -162,6 +162,8 @@ script: - 'if [[ "$autotools" == "1" ]]; then ./autotool.sh && export CXX=g++-5 && + export CC=gcc-5 && + export CXXFLAGS="-Werror -Wno-deprecated-declarations" && ./configure --enable-debug --enable-encryption --enable-examples --enable-tests --enable-python-binding && make -j2 check; fi' diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 3d20e58db..e30ae1a70 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -609,7 +609,8 @@ std::string path_to_url(std::string f) #if defined TORRENT_WINDOWS && !defined TORRENT_MINGW _getcwd(cwd, sizeof(cwd)); #else - getcwd(cwd, sizeof(cwd)); + char const* ret = getcwd(cwd, sizeof(cwd)); + (void)ret; // best effort #endif f = path_append(cwd, f); } @@ -1575,10 +1576,10 @@ int main(int argc, char* argv[]) { char url[4096]; puts("Enter magnet link:\n"); - std::scanf("%4095s", url); + int ret = std::scanf("%4095s", url); add_torrent_params p; - if (std::strstr(url, "magnet:") == url) + if (ret == 1 && std::strstr(url, "magnet:") == url) { add_torrent_params tmp; parse_magnet_uri(url, tmp, ec); @@ -1634,8 +1635,8 @@ int main(int argc, char* argv[]) std::printf("\n\nARE YOU SURE YOU WANT TO DELETE THE FILES FOR '%s'. THIS OPERATION CANNOT BE UNDONE. (y/N)" , st.name.c_str()); char response = 'n'; - std::scanf("%c", &response); - if (response == 'y') + int ret = std::scanf("%c", &response); + if (ret == 1 && response == 'y') { // also delete the .torrent file from the torrent directory handles_t::iterator i = std::find_if(files.begin(), files.end() diff --git a/examples/make_torrent.cpp b/examples/make_torrent.cpp index ef846be13..c4d032b8d 100644 --- a/examples/make_torrent.cpp +++ b/examples/make_torrent.cpp @@ -342,7 +342,13 @@ int main(int argc, char* argv[]) _getcwd(cwd, sizeof(cwd)); full_path = cwd + ("\\" + full_path); #else - getcwd(cwd, sizeof(cwd)); + char const* ret = getcwd(cwd, sizeof(cwd)); + if (ret == NULL) + { + std::fprintf(stderr, "failed to get current working directory: %s\n" + , strerror(errno)); + return 1; + } full_path = cwd + ("/" + full_path); #endif } diff --git a/examples/simple_client.cpp b/examples/simple_client.cpp index d143377fd..46734beb2 100644 --- a/examples/simple_client.cpp +++ b/examples/simple_client.cpp @@ -74,7 +74,8 @@ int main(int argc, char* argv[]) // wait for the user to end char a; - std::scanf("%c\n", &a); + int ret = std::scanf("%c\n", &a); + (void)ret; // ignore return 0; } diff --git a/test/main.cpp b/test/main.cpp index 817fa91ba..3b3b085c0 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -318,10 +318,17 @@ EXPORT int main(int argc, char const* argv[]) std::fprintf(stderr, "Failed to create test directory: %s\n", ec.message().c_str()); return 1; } + int ret; #ifdef TORRENT_WINDOWS SetCurrentDirectoryA(dir); #else - chdir(dir); + ret = chdir(dir); + if (ret != 0) + { + std::fprintf(stderr, "failed to change directory to \"%s\": %s" + , dir, strerror(errno)); + return 1; + } #endif std::fprintf(stderr, "test: %s\ncwd = \"%s\"\nrnd: %x\n" , executable, test_dir.c_str(), libtorrent::random(0xffffffff)); @@ -467,7 +474,7 @@ EXPORT int main(int argc, char const* argv[]) fflush(stderr); } - int ret = print_failures(); + ret = print_failures(); #if !defined TORRENT_LOGGING if (ret == 0 && !keep_files) {