From 689eb749452c50a00ef637c3951679c5e40c4296 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 25 Aug 2012 19:21:58 +0200 Subject: [PATCH] Fix compiler warnings (mainly signed/unsigned comparisons) --- lib/config.cpp | 4 ++-- lib/dtsc.cpp | 6 ++++-- lib/dtsc.h | 2 +- lib/json.cpp | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/config.cpp b/lib/config.cpp index 194d85c2..68172c9e 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -61,10 +61,10 @@ void Util::Config::addOption(std::string optname, JSON::Value option){ /// Prints a usage message to the given output. void Util::Config::printHelp(std::ostream & output){ - int longest = 0; + unsigned int longest = 0; std::map args; for (JSON::ObjIter it = vals.ObjBegin(); it != vals.ObjEnd(); it++){ - int current = 0; + unsigned int current = 0; if (it->second.isMember("long")){current += it->second["long"].asString().size() + 4;} if (it->second.isMember("short")){current += it->second["short"].asString().size() + 3;} if (current > longest){longest = current;} diff --git a/lib/dtsc.cpp b/lib/dtsc.cpp index 86d36257..e18d7817 100644 --- a/lib/dtsc.cpp +++ b/lib/dtsc.cpp @@ -217,7 +217,8 @@ DTSC::File::File(std::string filename, bool create){ fwrite(buffer, 4, 1, F);//write 4 zero-bytes headerSize = 0; }else{ - headerSize = ntohl(((uint32_t *)buffer)[0]); + uint32_t * ubuffer = (uint32_t *)buffer; + headerSize = ntohl(ubuffer[0]); } fseek(F, 8+headerSize, SEEK_SET); } @@ -264,7 +265,8 @@ std::string & DTSC::File::getPacket(){ strbuffer = ""; return strbuffer; } - long packSize = ntohl(((uint32_t *)buffer)[0]); + uint32_t * ubuffer = (uint32_t *)buffer; + long packSize = ntohl(ubuffer[0]); strbuffer.resize(packSize); if (fread((void*)strbuffer.c_str(), packSize, 1, F) != 1){ fprintf(stderr, "Could not read packet\n"); diff --git a/lib/dtsc.h b/lib/dtsc.h index bc23d618..2a6ca87d 100644 --- a/lib/dtsc.h +++ b/lib/dtsc.h @@ -73,7 +73,7 @@ namespace DTSC{ private: std::string strbuffer; FILE * F; - long headerSize; + unsigned long headerSize; char buffer[4]; };//FileWriter diff --git a/lib/json.cpp b/lib/json.cpp index 7adf2d32..f5420d01 100644 --- a/lib/json.cpp +++ b/lib/json.cpp @@ -480,7 +480,7 @@ std::string JSON::Value::toPrettyString(int indentation){ break; } case STRING: { - for (int i = 0; i < 5 && i < strVal.size(); ++i){ + for (unsigned int i = 0; i < 5 && i < strVal.size(); ++i){ if (strVal[i] < 32 || strVal[i] > 125){ return JSON::Value((long long int)strVal.size()).asString()+" bytes of binary data"; }