From: Gavin Andresen Date: Fri, 13 Jan 2012 01:02:47 +0000 (-0500) Subject: Compile with extra warnings turned on. And more makefile/code tidying up. X-Git-Tag: v0.4.0-unstable~129^2~274 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=a1de57a063af397612bb77f87c803c578d04f8e5 Compile with extra warnings turned on. And more makefile/code tidying up. This turns on most gcc warnings, and removes some unused variables and other code that triggers warnings. Exceptions are: -Wno-sign-compare : triggered by lots of comparisons of signed integer to foo.size(), which is unsigned. -Wno-char-subscripts : triggered by the convert-to-hex functions (I may fix this in a future commit). --- diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index ce29840..67edf8d 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1418,7 +1418,7 @@ Value listsinceblock(const Array& params, bool fHelp) CBlockIndex *block; for (block = pindexBest; block && block->nHeight > target_height; - block = block->pprev); + block = block->pprev) { } lastblock = block ? block->GetBlockHash() : 0; } diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index c7e054d..508f72b 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -52,7 +52,6 @@ namespace Checkpoints { if (fTestNet) return NULL; - int64 nResult; BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, mapCheckpoints) { const uint256& hash = i.second; diff --git a/src/headers.h b/src/headers.h index 6a2a3e4..127cf41 100644 --- a/src/headers.h +++ b/src/headers.h @@ -79,8 +79,6 @@ #endif -#pragma hdrstop - #include "serialize.h" #include "uint256.h" #include "util.h" diff --git a/src/makefile.linux-mingw b/src/makefile.linux-mingw index 5868a18..9212698 100644 --- a/src/makefile.linux-mingw +++ b/src/makefile.linux-mingw @@ -62,23 +62,22 @@ OBJS= \ all: bitcoind.exe -obj/nogui/%.o: %.cpp $(HEADERS) +obj/%.o: %.cpp $(HEADERS) i586-mingw32msvc-g++ -c $(CFLAGS) -o $@ $< -bitcoind.exe: $(OBJS:obj/%=obj/nogui/%) +bitcoind.exe: $(OBJS:obj/%=obj/%) i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) obj/test/%.o: obj/test/%.cpp $(HEADERS) i586-mingw32msvc-g++ -c $(CFLAGS) -o $@ $< -test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%)) +test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework-mt-s clean: -rm -f obj/*.o - -rm -f obj/nogui/*.o -rm -f obj/test/*.o -rm -f test/*.o -rm -f headers.h.gch diff --git a/src/makefile.mingw b/src/makefile.mingw index 0837940..c55e17a 100644 --- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -61,16 +61,16 @@ OBJS= \ all: bitcoind.exe -obj/nogui/%.o: %.cpp $(HEADERS) +obj/%.o: %.cpp $(HEADERS) g++ -c $(CFLAGS) -o $@ $< -bitcoind.exe: $(OBJS:obj/%=obj/nogui/%) +bitcoind.exe: $(OBJS:obj/%=obj/%) g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) obj/test/test_bitcoin.o: $(wildcard test/*.cpp) $(HEADERS) g++ -c $(CFLAGS) -o $@ test/test_bitcoin.cpp -test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%)) +test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) clean: diff --git a/src/makefile.osx b/src/makefile.osx index 78ecdb8..fd60f62 100644 --- a/src/makefile.osx +++ b/src/makefile.osx @@ -46,7 +46,9 @@ DEFS=-DMAC_OSX -DMSG_NOSIGNAL=0 -DUSE_SSL DEBUGFLAGS=-g # ppc doesn't work because we don't support big-endian -CFLAGS=-mmacosx-version-min=10.5 -arch i386 -O3 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) +CFLAGS=-mmacosx-version-min=10.5 -arch i386 -O3 \ + -Wextra -Wno-sign-compare -Wno-char-subscripts -Wno-invalid-offsetof -Wformat-security \ + $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) OBJS= \ obj/checkpoints.o \ @@ -78,17 +80,17 @@ endif all: bitcoind # auto-generated dependencies: --include obj/nogui/*.P +-include obj/*.P -include obj/test/*.P -obj/nogui/%.o: %.cpp +obj/%.o: %.cpp $(CXX) -c $(CFLAGS) -MMD -o $@ $< @cp $(@:%.o=%.d) $(@:%.o=%.P); \ sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ rm -f $(@:%.o=%.d) -bitcoind: $(OBJS:obj/%=obj/nogui/%) +bitcoind: $(OBJS:obj/%=obj/%) $(CXX) $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) TESTOBJS := $(patsubst test/%.cpp,obj/test/%.o,$(wildcard test/*.cpp)) @@ -100,14 +102,12 @@ obj/test/%.o: test/%.cpp -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ rm -f $(@:%.o=%.d) -test_bitcoin: $(TESTOBJS) $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%)) +test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) $(CXX) $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) $(DEPSDIR)/lib/libboost_unit_test_framework-mt.a clean: -rm -f bitcoind test_bitcoin -rm -f obj/*.o - -rm -f obj/nogui/*.o -rm -f obj/test/*.o -rm -f obj/*.P - -rm -f obj/nogui/*.P -rm -f obj/test/*.P diff --git a/src/makefile.unix b/src/makefile.unix index dad100d..3c6be3e 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -83,7 +83,8 @@ LIBS+= \ DEBUGFLAGS=-g CXXFLAGS=-O2 -xCXXFLAGS=-pthread -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS) +xCXXFLAGS=-pthread -Wextra -Wno-sign-compare -Wno-char-subscripts -Wno-invalid-offsetof -Wformat-security \ + $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS) OBJS= \ obj/checkpoints.o \ @@ -107,17 +108,17 @@ OBJS= \ all: bitcoind # auto-generated dependencies: --include obj/nogui/*.P +-include obj/*.P -include obj/test/*.P -obj/nogui/%.o: %.cpp +obj/%.o: %.cpp $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $< @cp $(@:%.o=%.d) $(@:%.o=%.P); \ sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ rm -f $(@:%.o=%.d) -bitcoind: $(OBJS:obj/%=obj/nogui/%) +bitcoind: $(OBJS:obj/%=obj/%) $(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) TESTOBJS := $(patsubst test/%.cpp,obj/test/%.o,$(wildcard test/*.cpp)) @@ -129,14 +130,12 @@ obj/test/%.o: test/%.cpp -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ rm -f $(@:%.o=%.d) -test_bitcoin: $(TESTOBJS) $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%)) +test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) $(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-Bstatic -lboost_unit_test_framework $(LDFLAGS) $(LIBS) clean: -rm -f bitcoind test_bitcoin -rm -f obj/*.o - -rm -f obj/nogui/*.o -rm -f obj/test/*.o -rm -f obj/*.P - -rm -f obj/nogui/*.P -rm -f obj/test/*.P diff --git a/src/net.cpp b/src/net.cpp index 7289768..817203b 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -938,7 +938,6 @@ void ThreadMapPort2(void* parg) char port[6]; sprintf(port, "%d", GetListenPort()); - const char * rootdescurl = 0; const char * multicastif = 0; const char * minissdpdpath = 0; struct UPNPDev * devlist = 0; @@ -960,8 +959,6 @@ void ThreadMapPort2(void* parg) r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr)); if (r == 1) { - char intClient[16]; - char intPort[6]; string strDesc = "Bitcoin " + FormatFullVersion(); #ifndef UPNPDISCOVER_SUCCESS /* miniupnpc 1.5 */ diff --git a/src/net.h b/src/net.h index 61daf03..9f58d1e 100644 --- a/src/net.h +++ b/src/net.h @@ -266,7 +266,9 @@ public: // Make sure not to reuse time indexes to keep things in the same order int64 nNow = (GetTime() - 1) * 1000000; static int64 nLastTime; - nLastTime = nNow = std::max(nNow, ++nLastTime); + ++nLastTime; + nNow = std::max(nNow, nLastTime); + nLastTime = nNow; // Each retry is 2 minutes after the last nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow); diff --git a/src/netbase.cpp b/src/netbase.cpp index 2c4df7f..ca27c2a 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -25,7 +25,9 @@ static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0 bool static LookupIntern(const char *pszName, std::vector& vIP, int nMaxSolutions, bool fAllowLookup) { vIP.clear(); - struct addrinfo aiHint = {}; + struct addrinfo aiHint; + memset(&aiHint, 0, sizeof(struct addrinfo)); + aiHint.ai_socktype = SOCK_STREAM; aiHint.ai_protocol = IPPROTO_TCP; #ifdef WIN32 diff --git a/src/serialize.h b/src/serialize.h index 626f7d6..c9dbdf7 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -89,6 +89,7 @@ enum const bool fRead = false; \ unsigned int nSerSize = 0; \ ser_streamplaceholder s; \ + assert(fGetSize||fWrite||fRead); /* suppress warning */ \ s.nType = nType; \ s.nVersion = nVersion; \ {statements} \ @@ -102,6 +103,7 @@ enum const bool fWrite = true; \ const bool fRead = false; \ unsigned int nSerSize = 0; \ + assert(fGetSize||fWrite||fRead); /* suppress warning */ \ {statements} \ } \ template \ @@ -112,6 +114,7 @@ enum const bool fWrite = false; \ const bool fRead = true; \ unsigned int nSerSize = 0; \ + assert(fGetSize||fWrite||fRead); /* suppress warning */ \ {statements} \ }