Browse Source

Fixed clang warning and errors.

Test for the zero-length array with A2_ARRAY_LEN was commented out
since it is only used in unit test code and clang and old gcc 3.4.3
emit error.
Tatsuhiro Tsujikawa 13 năm trước cách đây
mục cha
commit
e73c3c53ff

+ 1 - 1
src/AbstractOptionHandler.h

@@ -44,7 +44,7 @@
 namespace aria2 {
 
 class Option;
-class Pref;
+struct Pref;
 
 class AbstractOptionHandler : public OptionHandler {
 protected:

+ 1 - 1
src/BitfieldMan.cc

@@ -871,7 +871,7 @@ off_t BitfieldMan::getOffsetCompletedLength
 
 off_t BitfieldMan::getMissingUnusedLength(size_t startingIndex) const
 {
-  if(startingIndex < 0 || blocks_ <= startingIndex) {
+  if(blocks_ <= startingIndex) {
     return 0;
   }
   off_t length = 0;

+ 1 - 2
src/DefaultBtProgressInfoFile.cc

@@ -241,8 +241,7 @@ void DefaultBtProgressInfoFile::load()
   if(version >= 1) {
     infoHashLength = ntohl(infoHashLength);
   }
-  if((infoHashLength < 0) ||
-     ((infoHashLength == 0) && infoHashCheckEnabled)) {
+  if(infoHashLength == 0 && infoHashCheckEnabled) {
     throw DL_ABORT_EX(fmt("Invalid info hash length: %d", infoHashLength));
   }
   if(infoHashLength > 0) {

+ 1 - 1
src/DefaultPieceStorage.cc

@@ -124,7 +124,7 @@ SharedHandle<Piece> DefaultPieceStorage::checkOutPiece
 SharedHandle<Piece> DefaultPieceStorage::getPiece(size_t index)
 {
   SharedHandle<Piece> piece;
-  if(0 <= index && index <= bitfieldMan_->getMaxIndex()) {
+  if(index <= bitfieldMan_->getMaxIndex()) {
     piece = findUsedPiece(index);
     if(!piece) {
       piece.reset(new Piece(index, bitfieldMan_->getBlockLength(index)));

+ 1 - 1
src/DownloadContext.h

@@ -52,7 +52,7 @@ namespace aria2 {
 class RequestGroup;
 class Signature;
 class FileEntry;
-class ContextAttribute;
+struct ContextAttribute;
 
 class DownloadContext
 {

+ 1 - 1
src/HttpResponse.h

@@ -49,7 +49,7 @@ namespace aria2 {
 class HttpRequest;
 class HttpHeader;
 class StreamFilter;
-class MetalinkHttpEntry;
+struct MetalinkHttpEntry;
 class Option;
 class Checksum;
 

+ 1 - 1
src/LpdMessageReceiver.h

@@ -42,7 +42,7 @@
 namespace aria2 {
 
 class SocketCore;
-class LpdMessage;
+struct LpdMessage;
 
 class LpdMessageReceiver {
 private:

+ 1 - 1
src/MetalinkParserState.h

@@ -43,7 +43,7 @@
 namespace aria2 {
 
 class MetalinkParserStateMachine;
-class XmlAttr;
+struct XmlAttr;
 
 class MetalinkParserState
 {

+ 1 - 1
src/Option.h

@@ -42,7 +42,7 @@
 
 namespace aria2 {
 
-class Pref;
+struct Pref;
 
 class Option {
 private:

+ 1 - 1
src/OptionHandler.h

@@ -57,7 +57,7 @@ extern const std::string PATH_TO_DIR;
 extern const std::string PATH_TO_COMMAND;
 
 class Option;
-class Pref;
+struct Pref;
 
 class OptionHandler {
 public:

+ 1 - 1
src/OptionHandlerException.h

@@ -38,7 +38,7 @@
 
 namespace aria2 {
 
-class Pref;
+struct Pref;
 
 class OptionHandlerException:public RecoverableException {
 private:

+ 1 - 1
src/OptionHandlerImpl.h

@@ -44,7 +44,7 @@
 namespace aria2 {
 
 class Option;
-class Pref;
+struct Pref;
 
 class BooleanOptionHandler : public AbstractOptionHandler {
 public:

+ 1 - 1
src/OptionParser.h

@@ -47,7 +47,7 @@ namespace aria2 {
 
 class Option;
 class OptionHandler;
-class Pref;
+struct Pref;
 
 class OptionParser {
 private:

+ 1 - 1
src/ParserStateMachine.h

@@ -42,7 +42,7 @@
 
 namespace aria2 {
 
-class XmlAttr;
+struct XmlAttr;
 
 class ParserStateMachine {
 public:

+ 1 - 1
src/XmlRpcRequestParserState.h

@@ -42,7 +42,7 @@
 
 namespace aria2 {
 
-class XmlAttr;
+struct XmlAttr;
 
 namespace rpc {
 

+ 1 - 1
src/rpc_helper.h

@@ -43,7 +43,7 @@ namespace aria2 {
 
 namespace rpc {
 
-class RpcRequest;
+struct RpcRequest;
 
 #ifdef ENABLE_XML_RPC
 RpcRequest xmlParseMemory(const char* xml, size_t size);

+ 47 - 47
src/util.h

@@ -71,7 +71,7 @@ class BinaryStream;
 class FileEntry;
 class RequestGroup;
 class Option;
-class Pref;
+struct Pref;
 
 #define STRTOLL(X) strtoll(X, reinterpret_cast<char**>(0), 10)
 #define STRTOULL(X) strtoull(X, reinterpret_cast<char**>(0), 10)
@@ -111,6 +111,52 @@ std::string nativeToUtf8(const std::string& src);
 
 namespace util {
 
+extern const std::string DEFAULT_STRIP_CHARSET;
+
+template<typename InputIterator>
+std::pair<InputIterator, InputIterator> stripIter
+(InputIterator first, InputIterator last,
+ const std::string& chars = DEFAULT_STRIP_CHARSET)
+{
+  for(; first != last &&
+        std::find(chars.begin(), chars.end(), *first) != chars.end(); ++first);
+  if(first == last) {
+    return std::make_pair(first, last);
+  }
+  InputIterator left = last-1;
+  for(; left != first &&
+        std::find(chars.begin(), chars.end(), *left) != chars.end(); --left);
+  return std::make_pair(first, left+1);
+}
+
+template<typename InputIterator>
+InputIterator lstripIter
+(InputIterator first, InputIterator last, char ch)
+{
+  for(; first != last && *first == ch; ++first);
+  return first;
+}
+
+template<typename InputIterator, typename InputIterator2>
+InputIterator lstripIter
+(InputIterator first, InputIterator last,
+ InputIterator2 cfirst, InputIterator2 clast)
+{
+  for(; first != last && std::find(cfirst, clast, *first) != clast; ++first);
+  return first;
+}
+
+template<typename InputIterator>
+InputIterator lstripIter
+(InputIterator first, InputIterator last)
+{
+  return lstripIter(first, last,
+                    DEFAULT_STRIP_CHARSET.begin(), DEFAULT_STRIP_CHARSET.end());
+}
+
+std::string strip
+(const std::string& str, const std::string& chars = DEFAULT_STRIP_CHARSET);
+
 template<typename InputIterator>
 void divide
 (std::pair<std::pair<InputIterator, InputIterator>,
@@ -161,52 +207,6 @@ std::string itos(int64_t value, bool comma = false);
 int64_t difftv(struct timeval tv1, struct timeval tv2);
 int32_t difftvsec(struct timeval tv1, struct timeval tv2);
 
-extern const std::string DEFAULT_STRIP_CHARSET;
-
-template<typename InputIterator>
-std::pair<InputIterator, InputIterator> stripIter
-(InputIterator first, InputIterator last,
- const std::string& chars = DEFAULT_STRIP_CHARSET)
-{
-  for(; first != last &&
-        std::find(chars.begin(), chars.end(), *first) != chars.end(); ++first);
-  if(first == last) {
-    return std::make_pair(first, last);
-  }
-  InputIterator left = last-1;
-  for(; left != first &&
-        std::find(chars.begin(), chars.end(), *left) != chars.end(); --left);
-  return std::make_pair(first, left+1);
-}
-
-template<typename InputIterator>
-InputIterator lstripIter
-(InputIterator first, InputIterator last, char ch)
-{
-  for(; first != last && *first == ch; ++first);
-  return first;
-}
-
-template<typename InputIterator, typename InputIterator2>
-InputIterator lstripIter
-(InputIterator first, InputIterator last,
- InputIterator2 cfirst, InputIterator2 clast)
-{
-  for(; first != last && std::find(cfirst, clast, *first) != clast; ++first);
-  return first;
-}
-
-template<typename InputIterator>
-InputIterator lstripIter
-(InputIterator first, InputIterator last)
-{
-  return lstripIter(first, last,
-                    DEFAULT_STRIP_CHARSET.begin(), DEFAULT_STRIP_CHARSET.end());
-}
-
-std::string strip
-(const std::string& str, const std::string& chars = DEFAULT_STRIP_CHARSET);
-
 std::string replace(const std::string& target, const std::string& oldstr, const std::string& newstr);
 
 std::string percentEncode(const unsigned char* target, size_t len);

+ 4 - 4
test/array_funTest.cc

@@ -65,11 +65,11 @@ void array_funTest::testArray_and()
 void array_funTest::testArrayLength()
 {
   int64_t ia[] = { 1, 2, 3, 4, 5 };
-  int64_t zeroLengthArray[] = {};
-
   CPPUNIT_ASSERT_EQUAL((size_t)5, A2_ARRAY_LEN(ia));
-  // This causes compile error under gcc v3.4.3 opensolaris 5.11
-  CPPUNIT_ASSERT_EQUAL((size_t)0, A2_ARRAY_LEN(zeroLengthArray));
+  // This causes compile error under clang and gcc v3.4.3 opensolaris
+  // 5.11
+  // int64_t zeroLengthArray[] = {};
+  // CPPUNIT_ASSERT_EQUAL((size_t)0, A2_ARRAY_LEN(zeroLengthArray));
 }
 
 namespace {