attempt to run cppcheck on travis (#644)

run cppcheck on travis
This commit is contained in:
Arvid Norberg 2016-04-26 18:09:11 -04:00
parent 3c785b96fc
commit c557432431
11 changed files with 103 additions and 96 deletions

View File

@ -5,9 +5,10 @@ os:
- osx - osx
env: env:
- variant=test_release sim=0 coverage=1 docs=1 - variant=test_release coverage=1 docs=1
- variant=test_debug sim=1 coverage=0 - variant=test_debug sim=1
- variant=test_barebones sim=0 coverage=0 - variant=test_barebones
- analyze=1
git: git:
submodules: false submodules: false
@ -36,11 +37,13 @@ addons:
- libboost1.55-tools-dev - libboost1.55-tools-dev
- python2.7-dev - python2.7-dev
- g++-4.8 - g++-4.8
- cppcheck
before_install: before_install:
- git submodule update --init --recursive - git submodule update --init --recursive
- if [ $TRAVIS_OS_NAME == "osx" ]; then brew update > /dev/null && brew install --quiet ccache boost-build boost-python; fi - 'if [[ $TRAVIS_OS_NAME == "osx" && "$variant" != "" ]]; then brew update > /dev/null && brew install --quiet ccache boost-build boost-python; fi'
- 'if [[ $TRAVIS_OS_NAME == "osx" && $docs = "1" ]]; then - 'if [[ $TRAVIS_OS_NAME == "osx" && "$docs" = "1" ]]; then
brew install --quiet https://raw.githubusercontent.com/catap/homebrew/docutils/Library/Formula/docutils.rb; brew install --quiet https://raw.githubusercontent.com/catap/homebrew/docutils/Library/Formula/docutils.rb;
mkdir -p /Users/travis/Library/Python/2.7/lib/python/site-packages; mkdir -p /Users/travis/Library/Python/2.7/lib/python/site-packages;
echo ''import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")'' >> /Users/travis/Library/Python/2.7/lib/python/site-packages/homebrew.pth; echo ''import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")'' >> /Users/travis/Library/Python/2.7/lib/python/site-packages/homebrew.pth;
@ -54,7 +57,7 @@ before_install:
- if [ $TRAVIS_OS_NAME == "osx" ]; then export toolset="darwin"; export sim="0"; fi - if [ $TRAVIS_OS_NAME == "osx" ]; then export toolset="darwin"; export sim="0"; fi
- if [ $TRAVIS_OS_NAME == "osx" ]; then export target="osx-tests"; fi - if [ $TRAVIS_OS_NAME == "osx" ]; then export target="osx-tests"; fi
- if [ $TRAVIS_OS_NAME == "linux" ]; then export toolset="gcc"; fi - if [ $TRAVIS_OS_NAME == "linux" ]; then export toolset="gcc"; fi
- if [[ $TRAVIS_OS_NAME == "linux" && $coverage == "1" ]]; then - if [[ $TRAVIS_OS_NAME == "linux" && "$coverage" == "1" ]]; then
export coverage_toolset=gcc-coverage; export coverage_toolset=gcc-coverage;
pip install --user codecov; pip install --user codecov;
else else
@ -63,6 +66,7 @@ before_install:
- 'echo "using toolset: " ${toolset}' - 'echo "using toolset: " ${toolset}'
install: install:
- g++-4.8 --version - g++-4.8 --version
- 'echo "using gcc : : ccache g++-4.8 : <cflags>-std=c11 <cxxflags>-std=c++11 ;" > ~/user-config.jam' - 'echo "using gcc : : ccache g++-4.8 : <cflags>-std=c11 <cxxflags>-std=c++11 ;" > ~/user-config.jam'
- 'echo "using gcc : coverage : ccache g++-4.8 : <cflags>-std=c11 <cxxflags>-std=c++11 <compileflags>--coverage <linkflags>--coverage ;" >> ~/user-config.jam' - 'echo "using gcc : coverage : ccache g++-4.8 : <cflags>-std=c11 <cxxflags>-std=c++11 <compileflags>--coverage <linkflags>--coverage ;" >> ~/user-config.jam'
@ -72,41 +76,76 @@ install:
# we're building with -Werror, we can't have those warnings # we're building with -Werror, we can't have those warnings
- 'echo "using darwin : : ccache clang++ : <cflags>-std=c11 <cxxflags>-std=c++11 <compileflags>-Wno-deprecated-declarations ;" >> ~/user-config.jam' - 'echo "using darwin : : ccache clang++ : <cflags>-std=c11 <cxxflags>-std=c++11 <compileflags>-Wno-deprecated-declarations ;" >> ~/user-config.jam'
- 'echo "using python : 2.7 ;" >> ~/user-config.jam' - 'echo "using python : 2.7 ;" >> ~/user-config.jam'
- ccache -V && ccache --show-stats && ccache --zero-stats - 'if [[ "$variant" != "" ]]; then ccache -V && ccache --show-stats && ccache --zero-stats; fi'
- if [[ $docs == "1" && $TRAVIS_OS_NAME == "osx" ]]; then rst2html.py --version; fi - if [[ "$docs" == "1" && $TRAVIS_OS_NAME == "osx" ]]; then rst2html.py --version; fi
script: script:
# disable invoking docutils for now, until we can have a modern version of it
- cd docs
- if [[ $docs == "1" && $TRAVIS_OS_NAME == "osx" ]]; then make RST2HTML=rst2html.py; fi
- cd ..
- cd test - 'if [[ "$docs" == "1" && $TRAVIS_OS_NAME == "osx" ]]; then
- bjam --hash -j3 warnings-as-errors=on variant=$variant -l900 $coverage_toolset $target cd docs;
# if we're building with code coverage, report it as soon as possible make RST2HTML=rst2html.py;
- if [[ $TRAVIS_OS_NAME == "linux" && $coverage == "1" ]]; then cd ..;
codecov --root .. --gcov-exec gcov-4.8; fi'
fi
- cd ../examples # if variant is not set, we do not want to build anything
- bjam --hash -j3 warnings-as-errors=on variant=$variant $toolset link=shared bt-get bt-get2; # if we are building with code coverage, report it as soon as possible
- cd .. - 'if [ "$variant" != "" ]; then
cd test;
bjam --hash -j3 warnings-as-errors=on variant=$variant -l900 $coverage_toolset $target;
if [[ $TRAVIS_OS_NAME == "linux" && "$coverage" == "1" ]]; then
codecov --root .. --gcov-exec gcov-4.8;
fi;
cd ../examples;
bjam --hash -j3 warnings-as-errors=on variant=$variant $toolset link=shared bt-get bt-get2;
cd ..;
fi'
# build libtorrent separately and install it in a temporary (well known) dir # build libtorrent separately and install it in a temporary (well known) dir
# we have to do this because on linux the name of the python module is the same # we have to do this because on linux the name of the python module is the same
# as the main library, so we can't stage them to the same directory # as the main library, so we cannot stage them to the same directory
- bjam --hash -j3 warnings-as-errors=on link=shared variant=$variant $toolset install location=./lib
- cd bindings/python
# here we specify the temporary lib dir as a path to look for the main library # here we specify the temporary lib dir as a path to look for the main library
- bjam --hash -j3 warnings-as-errors=on variant=$variant $toolset stage_module libtorrent-link=shared install-type=LIB dll-path=../../lib - 'if [ "$variant" != "" ]; then
- LD_LIBRARY_PATH=../../lib DYLD_LIBRARY_PATH=../../lib python test.py bjam --hash -j3 warnings-as-errors=on link=shared variant=$variant $toolset install location=./lib;
- cd ../.. cd bindings/python;
bjam --hash -j3 warnings-as-errors=on variant=$variant $toolset stage_module libtorrent-link=shared install-type=LIB dll-path=../../lib;
LD_LIBRARY_PATH=../../lib DYLD_LIBRARY_PATH=../../lib python test.py;
cd ../..;
fi'
- cd simulation # simulation
- if [ $sim = "1" ]; then - 'if [ "$variant" != "" ]; then
bjam --hash -j2 crypto=built-in warnings-as-errors=on $coverage_toolset; cd simulation;
fi if [ "$sim" == "1" ]; then
- cd .. bjam --hash -j2 crypto=built-in warnings-as-errors=on $coverage_toolset;
- ccache --show-stats fi;
cd ..;
fi'
# run cppcheck if enabled
- 'if [[ "$analyze" == "1" ]]; then
if [[ $TRAVIS_OS_NAME == "linux" ]]; then
cppcheck --version;
find src -type f | grep ".*\.cpp$" >cppcheck.files;
cppcheck -DTORRENT_USE_IPV6="1" -DTORRENT_USE_I2P="1"
-DTORRENT_USE_OPENSSL="1" -DTORRENT_USE_INVARIANT_CHECKS="1"
-DTORRENT_EXPENSIVE_INVARIANT_CHECKS="1" -DTORRENT_USE_ASSERTS="1"
-UTORRENT_DISABLE_MUTABLE_TORRENTS -UTORRENT_DISABLE_LOGGING
-UTORRENT_DEBUG_BUFFERS -UTORRENT_EXPORT_EXTRA
--suppress=preprocessorErrorDirective
--suppress=syntaxError
--template "{file}({line}): {severity} ({id}): {message}"
--inline-suppr --force --std=c++11 -j2 -I include -I /usr/local/include
--file-list=cppcheck.files 2> cppcheck.txt;
if [ -s cppcheck.txt ]; then
echo " ======= CPPCHECK ERRORS =====";
cat cppcheck.txt;
exit 1;
fi;
fi;
if [[ $TRAVIS_OS_NAME == "osx" ]]; then
echo "nothing here yet";
fi;
fi'
- 'if [[ "$variant" != "" ]]; then ccache --show-stats; fi'

View File

@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_PACKET_BUFFER_HPP_INCLUDED #define TORRENT_PACKET_BUFFER_HPP_INCLUDED
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "boost/cstdint.hpp" #include <boost/cstdint.hpp>
#include <cstddef> #include <cstddef>
namespace libtorrent namespace libtorrent

View File

@ -1031,6 +1031,7 @@ namespace libtorrent
// skip the file we just put in place, so we put the pad // skip the file we just put in place, so we put the pad
// file after it // file after it
++i; ++i;
if (i == m_files.end()) break;
// tail-padding is enabled, and the offset after this file is not // tail-padding is enabled, and the offset after this file is not
// aligned and it's not the last file. The last file must be padded // aligned and it's not the last file. The last file must be padded

View File

@ -123,7 +123,7 @@ namespace
fingerprint ret("..", 0, 0, 0, 0); fingerprint ret("..", 0, 0, 0, 0);
ret.name[1] = 0; ret.name[1] = 0;
ret.tag_version = 0; ret.tag_version = 0;
if (sscanf(ids, "%c%d-%d-%d--", &ret.name[0], &ret.major_version, &ret.minor_version if (sscanf(ids, "%c%3d-%3d-%3d--", &ret.name[0], &ret.major_version, &ret.minor_version
, &ret.revision_version) != 4 , &ret.revision_version) != 4
|| !is_print(ret.name[0])) || !is_print(ret.name[0]))
return boost::optional<fingerprint>(); return boost::optional<fingerprint>();

View File

@ -228,7 +228,7 @@ namespace
bloom_filter<256> seeds; bloom_filter<256> seeds;
for (std::set<peer_entry>::const_iterator peer_it = v.peers.begin() for (std::set<peer_entry>::const_iterator peer_it = v.peers.begin()
, end(v.peers.end()); peer_it != end; ++peer_it) , end(v.peers.end()); peer_it != end; ++peer_it)
{ {
sha1_hash iphash; sha1_hash iphash;
hash_address(peer_it->addr.address(), iphash); hash_address(peer_it->addr.address(), iphash);

View File

@ -651,41 +651,6 @@ namespace libtorrent
if (p.index == piece_pos::we_have_index) if (p.index == piece_pos::we_have_index)
++num_have; ++num_have;
#if 0
if (t != 0)
{
int actual_peer_count = 0;
for (torrent::const_peer_iterator peer = t->begin();
peer != t->end(); ++peer)
{
if (peer->second->has_piece(index)) actual_peer_count++;
}
TORRENT_ASSERT((int)i->peer_count == actual_peer_count);
/*
int num_downloaders = 0;
for (std::vector<peer_connection*>::const_iterator peer = t->begin();
peer != t->end();
++peer)
{
const std::vector<piece_block>& queue = (*peer)->download_queue();
if (std::find_if(queue.begin(), queue.end(), has_index(index)) == queue.end()) continue;
++num_downloaders;
}
if (i->downloading())
{
TORRENT_ASSERT(num_downloaders == 1);
}
else
{
TORRENT_ASSERT(num_downloaders == 0);
}
*/
}
#endif
if (p.index == piece_pos::we_have_index) if (p.index == piece_pos::we_have_index)
{ {
TORRENT_ASSERT(t == 0 || t->have_piece(index)); TORRENT_ASSERT(t == 0 || t->have_piece(index));
@ -730,22 +695,22 @@ namespace libtorrent
} }
} }
int count_downloading = std::count_if( int const count_downloading = std::count_if(
m_downloads[piece_pos::piece_downloading].begin() m_downloads[piece_pos::piece_downloading].begin()
, m_downloads[piece_pos::piece_downloading].end() , m_downloads[piece_pos::piece_downloading].end()
, has_index(index)); , has_index(index));
int count_full = std::count_if( int const count_full = std::count_if(
m_downloads[piece_pos::piece_full].begin() m_downloads[piece_pos::piece_full].begin()
, m_downloads[piece_pos::piece_full].end() , m_downloads[piece_pos::piece_full].end()
, has_index(index)); , has_index(index));
int count_finished = std::count_if( int const count_finished = std::count_if(
m_downloads[piece_pos::piece_finished].begin() m_downloads[piece_pos::piece_finished].begin()
, m_downloads[piece_pos::piece_finished].end() , m_downloads[piece_pos::piece_finished].end()
, has_index(index)); , has_index(index));
int count_zero = std::count_if( int const count_zero = std::count_if(
m_downloads[piece_pos::piece_zero_prio].begin() m_downloads[piece_pos::piece_zero_prio].begin()
, m_downloads[piece_pos::piece_zero_prio].end() , m_downloads[piece_pos::piece_zero_prio].end()
, has_index(index)); , has_index(index));

View File

@ -5997,10 +5997,10 @@ namespace aux {
if (f != NULL) if (f != NULL)
{ {
time_point m = min_time(); time_point m = min_time();
if (_wakeups.size() > 0) m = _wakeups[0].timestamp; if (!_wakeups.empty()) m = _wakeups[0].timestamp;
time_point prev = m; time_point prev = m;
boost::uint64_t prev_csw = 0; boost::uint64_t prev_csw = 0;
if (_wakeups.size() > 0) prev_csw = _wakeups[0].context_switches; if (!_wakeups.empty()) prev_csw = _wakeups[0].context_switches;
fprintf(f, "abs. time\trel. time\tctx switch\tidle-wakeup\toperation\n"); fprintf(f, "abs. time\trel. time\tctx switch\tidle-wakeup\toperation\n");
for (int i = 0; i < _wakeups.size(); ++i) for (int i = 0; i < _wakeups.size(); ++i)
{ {

View File

@ -856,7 +856,7 @@ namespace libtorrent
bdecode_node e; bdecode_node e;
error_code ec; error_code ec;
if (tmp.size() == 0 || bdecode(&tmp[0], &tmp[0] + tmp.size(), e, ec) != 0) if (tmp.empty() || bdecode(&tmp[0], &tmp[0] + tmp.size(), e, ec) != 0)
{ {
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
throw invalid_torrent_file(ec); throw invalid_torrent_file(ec);
@ -926,7 +926,7 @@ namespace libtorrent
if (ret < 0) throw invalid_torrent_file(ec); if (ret < 0) throw invalid_torrent_file(ec);
bdecode_node e; bdecode_node e;
if (buf.size() == 0 || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0) if (buf.empty() || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
throw invalid_torrent_file(ec); throw invalid_torrent_file(ec);
if (!parse_torrent_file(e, ec, flags)) if (!parse_torrent_file(e, ec, flags))
@ -954,7 +954,7 @@ namespace libtorrent
if (ret < 0) throw invalid_torrent_file(ec); if (ret < 0) throw invalid_torrent_file(ec);
bdecode_node e; bdecode_node e;
if (buf.size() == 0 || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0) if (buf.empty() || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
throw invalid_torrent_file(ec); throw invalid_torrent_file(ec);
if (!parse_torrent_file(e, ec, flags)) if (!parse_torrent_file(e, ec, flags))
@ -1019,7 +1019,7 @@ namespace libtorrent
if (ret < 0) return; if (ret < 0) return;
bdecode_node e; bdecode_node e;
if (buf.size() == 0 || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0) if (buf.empty() || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
return; return;
parse_torrent_file(e, ec, flags); parse_torrent_file(e, ec, flags);
@ -1045,7 +1045,7 @@ namespace libtorrent
if (ret < 0) return; if (ret < 0) return;
bdecode_node e; bdecode_node e;
if (buf.size() == 0 || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0) if (buf.empty() || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
return; return;
parse_torrent_file(e, ec, flags); parse_torrent_file(e, ec, flags);

View File

@ -79,7 +79,9 @@ struct socks5 : boost::enable_shared_from_this<socks5>
, m_timer(ios) , m_timer(ios)
, m_abort(false) , m_abort(false)
, m_active(false) , m_active(false)
{} {
memset(m_tmp_buf, 0, sizeof(m_tmp_buf));
}
void start(aux::proxy_settings const& ps); void start(aux::proxy_settings const& ps);
void close(); void close();

View File

@ -302,14 +302,14 @@ namespace libtorrent { namespace
return true; return true;
} }
const int num_pex_timers = sizeof(m_last_pex)/sizeof(m_last_pex[0]); int const num_pex_timers = sizeof(m_last_pex)/sizeof(m_last_pex[0]);
for (int i = 0; i < num_pex_timers-1; ++i) for (int i = 0; i < num_pex_timers-1; ++i)
m_last_pex[i] = m_last_pex[i+1]; m_last_pex[i] = m_last_pex[i+1];
m_last_pex[num_pex_timers-1] = now; m_last_pex[num_pex_timers-1] = now;
bdecode_node pex_msg; bdecode_node pex_msg;
error_code ec; error_code ec;
int ret = bdecode(body.begin, body.end, pex_msg, ec); int const ret = bdecode(body.begin, body.end, pex_msg, ec);
if (ret != 0 || pex_msg.type() != bdecode_node::dict_t) if (ret != 0 || pex_msg.type() != bdecode_node::dict_t)
{ {
m_pc.disconnect(errors::invalid_pex_message, op_bittorrent, 2); m_pc.disconnect(errors::invalid_pex_message, op_bittorrent, 2);
@ -325,7 +325,7 @@ namespace libtorrent { namespace
#endif #endif
if (p) if (p)
{ {
int num_peers = p.string_length() / 6; int const num_peers = p.string_length() / 6;
char const* in = p.string_ptr(); char const* in = p.string_ptr();
for (int i = 0; i < num_peers; ++i) for (int i = 0; i < num_peers; ++i)
@ -345,14 +345,14 @@ namespace libtorrent { namespace
#endif #endif
if (p && pf && pf.string_length() == p.string_length() / 6) if (p && pf && pf.string_length() == p.string_length() / 6)
{ {
int num_peers = pf.string_length(); int const num_peers = pf.string_length();
char const* in = p.string_ptr(); char const* in = p.string_ptr();
char const* fin = pf.string_ptr(); char const* fin = pf.string_ptr();
for (int i = 0; i < num_peers; ++i) for (int i = 0; i < num_peers; ++i)
{ {
tcp::endpoint adr = detail::read_v4_endpoint<tcp::endpoint>(in); tcp::endpoint adr = detail::read_v4_endpoint<tcp::endpoint>(in);
char flags = *fin++; char const flags = *fin++;
if (int(m_peers.size()) >= m_torrent.settings().get_int(settings_pack::max_pex_peers)) if (int(m_peers.size()) >= m_torrent.settings().get_int(settings_pack::max_pex_peers))
break; break;
@ -377,7 +377,7 @@ namespace libtorrent { namespace
#endif #endif
if (p6 != 0 && p6.type() == bdecode_node::string_t) if (p6 != 0 && p6.type() == bdecode_node::string_t)
{ {
int num_peers = p6.string_length() / 18; int const num_peers = p6.string_length() / 18;
char const* in = p6.string_ptr(); char const* in = p6.string_ptr();
for (int i = 0; i < num_peers; ++i) for (int i = 0; i < num_peers; ++i)
@ -400,14 +400,14 @@ namespace libtorrent { namespace
&& p6f.type() == bdecode_node::string_t && p6f.type() == bdecode_node::string_t
&& p6f.string_length() == p6.string_length() / 18) && p6f.string_length() == p6.string_length() / 18)
{ {
int num_peers = p6f.string_length(); int const num_peers = p6f.string_length();
char const* in = p6.string_ptr(); char const* in = p6.string_ptr();
char const* fin = p6f.string_ptr(); char const* fin = p6f.string_ptr();
for (int i = 0; i < num_peers; ++i) for (int i = 0; i < num_peers; ++i)
{ {
tcp::endpoint adr = detail::read_v6_endpoint<tcp::endpoint>(in); tcp::endpoint adr = detail::read_v6_endpoint<tcp::endpoint>(in);
char flags = *fin++; char const flags = *fin++;
// ignore local addresses unless the peer is local to us // ignore local addresses unless the peer is local to us
if (is_local(adr.address()) && !is_local(m_pc.remote().address())) continue; if (is_local(adr.address()) && !is_local(m_pc.remote().address())) continue;
if (int(m_peers6.size()) >= m_torrent.settings().get_int(settings_pack::max_pex_peers)) if (int(m_peers6.size()) >= m_torrent.settings().get_int(settings_pack::max_pex_peers))
@ -419,7 +419,7 @@ namespace libtorrent { namespace
if (j != m_peers6.end() && *j == v) continue; if (j != m_peers6.end() && *j == v) continue;
m_peers6.insert(j, v); m_peers6.insert(j, v);
m_torrent.add_peer(adr, peer_info::pex, flags); m_torrent.add_peer(adr, peer_info::pex, flags);
} }
} }
#endif #endif
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
@ -438,7 +438,7 @@ namespace libtorrent { namespace
// no handshake yet // no handshake yet
if (!m_message_index) return; if (!m_message_index) return;
time_point now = aux::time_now(); time_point const now = aux::time_now();
if (now - seconds(60) < m_last_msg) if (now - seconds(60) < m_last_msg)
{ {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
@ -449,7 +449,7 @@ namespace libtorrent { namespace
} }
static time_point global_last = min_time(); static time_point global_last = min_time();
int num_peers = m_torrent.num_peers(); int const num_peers = m_torrent.num_peers();
if (num_peers <= 1) return; if (num_peers <= 1) return;
// don't send pex messages more often than 1 every 100 ms, and // don't send pex messages more often than 1 every 100 ms, and

View File

@ -2111,7 +2111,7 @@ bool utp_socket_impl::send_pkt(int flags)
} }
else if (ec) else if (ec)
{ {
TORRENT_ASSERT(stack_alloced != (payload_size != 0)); TORRENT_ASSERT(stack_alloced != bool(payload_size != 0));
m_error = ec; m_error = ec;
set_state(UTP_STATE_ERROR_WAIT); set_state(UTP_STATE_ERROR_WAIT);
test_socket_state(); test_socket_state();