diff --git a/src/bitdht/bdhistory.cc b/src/bitdht/bdhistory.cc index 49a664e..637a1ce 100644 --- a/src/bitdht/bdhistory.cc +++ b/src/bitdht/bdhistory.cc @@ -36,7 +36,6 @@ void bdMsgHistoryList::printHistory(std::ostream &out, int mode, time_t start_ts sit = msgHistory.lower_bound(start_ts); eit = msgHistory.upper_bound(end_ts); time_t curr_ts = 0; - time_t old_ts = 0; bool time_changed = false; bool first_line = true; @@ -45,7 +44,6 @@ void bdMsgHistoryList::printHistory(std::ostream &out, int mode, time_t start_ts time_changed = false; if (curr_ts != it->first) { - old_ts = curr_ts; curr_ts = it->first; time_changed = true; } diff --git a/src/bitdht/bdmanager.cc b/src/bitdht/bdmanager.cc index e0bb28b..55030d1 100644 --- a/src/bitdht/bdmanager.cc +++ b/src/bitdht/bdmanager.cc @@ -168,7 +168,7 @@ bool bdNodeManager::setAttachMode(bool on) } /* Friend Tracking */ -void bdNodeManager::addBadPeer(const struct sockaddr_in &addr, uint32_t source, uint32_t reason, uint32_t age) +void bdNodeManager::addBadPeer(const struct sockaddr_in &/*addr*/, uint32_t /*source*/, uint32_t /*reason*/, uint32_t /*age*/) { std::cerr << "bdNodeManager::addBadPeer() not implemented yet!"; std::cerr << std::endl; diff --git a/src/bitdht/bdpeer.cc b/src/bitdht/bdpeer.cc index 3d68daf..d5c4eea 100644 --- a/src/bitdht/bdpeer.cc +++ b/src/bitdht/bdpeer.cc @@ -27,6 +27,7 @@ #include "bitdht/bdpeer.h" #include "util/bdnet.h" #include "util/bdrandom.h" +#include "util/bdstring.h" #include "bitdht/bdiface.h" #include @@ -941,13 +942,13 @@ int bdSpace::printDHT() if (size) { if (doPrint) - fprintf(stderr, "Estimated NetSize >> %llu\n", no_nets); + bd_fprintf(stderr, "Estimated NetSize >> %llu\n", no_nets); } else { #ifdef BITDHT_DEBUG if (doPrint) - fprintf(stderr, " Bucket = Net / >> %llu\n", no_nets); + bd_fprintf(stderr, " Bucket = Net / >> %llu\n", no_nets); #endif } } @@ -957,14 +958,14 @@ int bdSpace::printDHT() if (size) { if (doPrint) - fprintf(stderr, "Estimated NetSize = %llu\n", no_peers); + bd_fprintf(stderr, "Estimated NetSize = %llu\n", no_peers); } else { #ifdef BITDHT_DEBUG if (doPrint) - fprintf(stderr, " Bucket = Net / %llu\n", no_nets); + bd_fprintf(stderr, " Bucket = Net / %llu\n", no_nets); #endif } @@ -994,7 +995,7 @@ int bdSpace::printDHT() } else { - fprintf(stderr, "Estimated Network Size = (%llu / %d) = %llu\n", sum, count, sum / count); + bd_fprintf(stderr, "Estimated Network Size = (%llu / %d) = %llu\n", sum, count, sum / count); } return 1; diff --git a/src/bitdht/bdquery.cc b/src/bitdht/bdquery.cc index b3f1624..9bcf365 100644 --- a/src/bitdht/bdquery.cc +++ b/src/bitdht/bdquery.cc @@ -364,7 +364,6 @@ int bdQuery::addClosestPeer(const bdId *id, uint32_t mode) #ifdef DEBUG_QUERY fprintf(stderr, "Dropping Peer that dont reply\n"); #endif - bool removed = false; for(it = mClosest.begin(); it != mClosest.end(); ++it) { time_t sendts = ts - it->second.mLastSendTime; @@ -379,7 +378,6 @@ int bdQuery::addClosestPeer(const bdId *id, uint32_t mode) fprintf(stderr, "\n"); #endif mClosest.erase(it); - removed = true; break ; } } @@ -568,12 +566,10 @@ int bdQuery::updatePotentialPeer(const bdId *id, uint32_t mode, uint32_t addType sit = mPotentialPeers.lower_bound(dist); eit = mPotentialPeers.upper_bound(dist); - bool found = false; for(it = sit; it != eit; it++) { if (mFns->bdSimilarId(id, &(it->second.mPeerId))) { - found = true; it->second.mPeerFlags |= mode; it->second.mLastRecvTime = now; diff --git a/src/bitdht/bdstore.cc b/src/bitdht/bdstore.cc index 10046ba..bf51b16 100644 --- a/src/bitdht/bdstore.cc +++ b/src/bitdht/bdstore.cc @@ -161,7 +161,6 @@ void bdStore::addStore(bdPeer *peer) #endif /* remove old entry */ - bool removed = false; std::list::iterator it; for(it = store.begin(); it != store.end(); ) @@ -169,7 +168,6 @@ void bdStore::addStore(bdPeer *peer) if ((it->mPeerId.addr.sin_addr.s_addr == peer->mPeerId.addr.sin_addr.s_addr) && (it->mPeerId.addr.sin_port == peer->mPeerId.addr.sin_port)) { - removed = true; #ifdef DEBUG_STORE std::cerr << "bdStore::addStore() Removed Existing Entry: "; mFns->bdPrintId(std::cerr, &(it->mPeerId)); diff --git a/src/bitdht/bencode.c b/src/bitdht/bencode.c index 60bc756..598dc76 100644 --- a/src/bitdht/bencode.c +++ b/src/bitdht/bencode.c @@ -22,6 +22,7 @@ #include #include /* malloc() realloc() free() strtoll() */ #include /* memset() */ +#include "util/bdstring.h" #include "bitdht/bencode.h" @@ -425,7 +426,7 @@ int be_encode(be_node *node, char *str, int len) switch (node->type) { case BE_STR: - snprintf(str, len, "%lli:", be_str_len(node)); + bd_snprintf(str, len, "%lli:", be_str_len(node)); loc += strlen(&(str[loc])); memcpy(&(str[loc]), node->val.s, be_str_len(node)); @@ -433,7 +434,7 @@ int be_encode(be_node *node, char *str, int len) break; case BE_INT: - snprintf(str, len, "i%llie", node->val.i); + bd_snprintf(str, len, "i%llie", node->val.i); loc += strlen(&(str[loc])); break; diff --git a/src/libbitdht.pro b/src/libbitdht.pro index c2f6c88..7b2ab6c 100644 --- a/src/libbitdht.pro +++ b/src/libbitdht.pro @@ -19,6 +19,10 @@ debug { QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer } +# treat warnings as error for better removing +#QMAKE_CFLAGS += -Werror +#QMAKE_CXXFLAGS += -Werror + ################################# Linux ########################################## linux-* { DESTDIR = lib @@ -59,6 +63,10 @@ win32 { #DEFINES *= WINDOWS_SYS WIN32 STATICLIB MINGW DESTDIR = lib + # Switch on extra warnings + QMAKE_CFLAGS += -Wextra + QMAKE_CXXFLAGS += -Wextra + # Switch off optimization for release version QMAKE_CXXFLAGS_RELEASE -= -O2 QMAKE_CXXFLAGS_RELEASE += -O0 @@ -107,6 +115,7 @@ HEADERS += \ util/bdnet.h \ util/bdthreads.h \ util/bdrandom.h \ + util/bdstring.h \ udp/udplayer.h \ udp/udpstack.h \ udp/udpbitdht.h \ diff --git a/src/util/bdstring.h b/src/util/bdstring.h new file mode 100644 index 0000000..fc7105d --- /dev/null +++ b/src/util/bdstring.h @@ -0,0 +1,35 @@ +#ifndef BITDHT_UTILS_BDSTRING_H +#define BITDHT_UTILS_BDSTRING_H + +/**************************************************************** + * libbitdht is distributed under the following license: + * + * Copyright (C) 2012 RetroShare Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#ifdef WIN32 +// for proper handling of %ll +#define bd_snprintf __mingw_snprintf +#define bd_fprintf __mingw_fprintf +#else +#define bd_snprintf snprintf +#define bd_fprintf fprintf +#endif + + +#endif