mirror of https://github.com/aria2/aria2
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.pull/13/head
parent
037f1512db
commit
e73c3c53ff
|
@ -44,7 +44,7 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class Option;
|
class Option;
|
||||||
class Pref;
|
struct Pref;
|
||||||
|
|
||||||
class AbstractOptionHandler : public OptionHandler {
|
class AbstractOptionHandler : public OptionHandler {
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -871,7 +871,7 @@ off_t BitfieldMan::getOffsetCompletedLength
|
||||||
|
|
||||||
off_t BitfieldMan::getMissingUnusedLength(size_t startingIndex) const
|
off_t BitfieldMan::getMissingUnusedLength(size_t startingIndex) const
|
||||||
{
|
{
|
||||||
if(startingIndex < 0 || blocks_ <= startingIndex) {
|
if(blocks_ <= startingIndex) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
off_t length = 0;
|
off_t length = 0;
|
||||||
|
|
|
@ -241,8 +241,7 @@ void DefaultBtProgressInfoFile::load()
|
||||||
if(version >= 1) {
|
if(version >= 1) {
|
||||||
infoHashLength = ntohl(infoHashLength);
|
infoHashLength = ntohl(infoHashLength);
|
||||||
}
|
}
|
||||||
if((infoHashLength < 0) ||
|
if(infoHashLength == 0 && infoHashCheckEnabled) {
|
||||||
((infoHashLength == 0) && infoHashCheckEnabled)) {
|
|
||||||
throw DL_ABORT_EX(fmt("Invalid info hash length: %d", infoHashLength));
|
throw DL_ABORT_EX(fmt("Invalid info hash length: %d", infoHashLength));
|
||||||
}
|
}
|
||||||
if(infoHashLength > 0) {
|
if(infoHashLength > 0) {
|
||||||
|
|
|
@ -124,7 +124,7 @@ SharedHandle<Piece> DefaultPieceStorage::checkOutPiece
|
||||||
SharedHandle<Piece> DefaultPieceStorage::getPiece(size_t index)
|
SharedHandle<Piece> DefaultPieceStorage::getPiece(size_t index)
|
||||||
{
|
{
|
||||||
SharedHandle<Piece> piece;
|
SharedHandle<Piece> piece;
|
||||||
if(0 <= index && index <= bitfieldMan_->getMaxIndex()) {
|
if(index <= bitfieldMan_->getMaxIndex()) {
|
||||||
piece = findUsedPiece(index);
|
piece = findUsedPiece(index);
|
||||||
if(!piece) {
|
if(!piece) {
|
||||||
piece.reset(new Piece(index, bitfieldMan_->getBlockLength(index)));
|
piece.reset(new Piece(index, bitfieldMan_->getBlockLength(index)));
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace aria2 {
|
||||||
class RequestGroup;
|
class RequestGroup;
|
||||||
class Signature;
|
class Signature;
|
||||||
class FileEntry;
|
class FileEntry;
|
||||||
class ContextAttribute;
|
struct ContextAttribute;
|
||||||
|
|
||||||
class DownloadContext
|
class DownloadContext
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace aria2 {
|
||||||
class HttpRequest;
|
class HttpRequest;
|
||||||
class HttpHeader;
|
class HttpHeader;
|
||||||
class StreamFilter;
|
class StreamFilter;
|
||||||
class MetalinkHttpEntry;
|
struct MetalinkHttpEntry;
|
||||||
class Option;
|
class Option;
|
||||||
class Checksum;
|
class Checksum;
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class SocketCore;
|
class SocketCore;
|
||||||
class LpdMessage;
|
struct LpdMessage;
|
||||||
|
|
||||||
class LpdMessageReceiver {
|
class LpdMessageReceiver {
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class MetalinkParserStateMachine;
|
class MetalinkParserStateMachine;
|
||||||
class XmlAttr;
|
struct XmlAttr;
|
||||||
|
|
||||||
class MetalinkParserState
|
class MetalinkParserState
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class Pref;
|
struct Pref;
|
||||||
|
|
||||||
class Option {
|
class Option {
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -57,7 +57,7 @@ extern const std::string PATH_TO_DIR;
|
||||||
extern const std::string PATH_TO_COMMAND;
|
extern const std::string PATH_TO_COMMAND;
|
||||||
|
|
||||||
class Option;
|
class Option;
|
||||||
class Pref;
|
struct Pref;
|
||||||
|
|
||||||
class OptionHandler {
|
class OptionHandler {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class Pref;
|
struct Pref;
|
||||||
|
|
||||||
class OptionHandlerException:public RecoverableException {
|
class OptionHandlerException:public RecoverableException {
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class Option;
|
class Option;
|
||||||
class Pref;
|
struct Pref;
|
||||||
|
|
||||||
class BooleanOptionHandler : public AbstractOptionHandler {
|
class BooleanOptionHandler : public AbstractOptionHandler {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace aria2 {
|
||||||
|
|
||||||
class Option;
|
class Option;
|
||||||
class OptionHandler;
|
class OptionHandler;
|
||||||
class Pref;
|
struct Pref;
|
||||||
|
|
||||||
class OptionParser {
|
class OptionParser {
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class XmlAttr;
|
struct XmlAttr;
|
||||||
|
|
||||||
class ParserStateMachine {
|
class ParserStateMachine {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class XmlAttr;
|
struct XmlAttr;
|
||||||
|
|
||||||
namespace rpc {
|
namespace rpc {
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace aria2 {
|
||||||
|
|
||||||
namespace rpc {
|
namespace rpc {
|
||||||
|
|
||||||
class RpcRequest;
|
struct RpcRequest;
|
||||||
|
|
||||||
#ifdef ENABLE_XML_RPC
|
#ifdef ENABLE_XML_RPC
|
||||||
RpcRequest xmlParseMemory(const char* xml, size_t size);
|
RpcRequest xmlParseMemory(const char* xml, size_t size);
|
||||||
|
|
94
src/util.h
94
src/util.h
|
@ -71,7 +71,7 @@ class BinaryStream;
|
||||||
class FileEntry;
|
class FileEntry;
|
||||||
class RequestGroup;
|
class RequestGroup;
|
||||||
class Option;
|
class Option;
|
||||||
class Pref;
|
struct Pref;
|
||||||
|
|
||||||
#define STRTOLL(X) strtoll(X, reinterpret_cast<char**>(0), 10)
|
#define STRTOLL(X) strtoll(X, reinterpret_cast<char**>(0), 10)
|
||||||
#define STRTOULL(X) strtoull(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 {
|
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>
|
template<typename InputIterator>
|
||||||
void divide
|
void divide
|
||||||
(std::pair<std::pair<InputIterator, InputIterator>,
|
(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);
|
int64_t difftv(struct timeval tv1, struct timeval tv2);
|
||||||
int32_t difftvsec(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 replace(const std::string& target, const std::string& oldstr, const std::string& newstr);
|
||||||
|
|
||||||
std::string percentEncode(const unsigned char* target, size_t len);
|
std::string percentEncode(const unsigned char* target, size_t len);
|
||||||
|
|
|
@ -65,11 +65,11 @@ void array_funTest::testArray_and()
|
||||||
void array_funTest::testArrayLength()
|
void array_funTest::testArrayLength()
|
||||||
{
|
{
|
||||||
int64_t ia[] = { 1, 2, 3, 4, 5 };
|
int64_t ia[] = { 1, 2, 3, 4, 5 };
|
||||||
int64_t zeroLengthArray[] = {};
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)5, A2_ARRAY_LEN(ia));
|
CPPUNIT_ASSERT_EQUAL((size_t)5, A2_ARRAY_LEN(ia));
|
||||||
// This causes compile error under gcc v3.4.3 opensolaris 5.11
|
// This causes compile error under clang and gcc v3.4.3 opensolaris
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)0, A2_ARRAY_LEN(zeroLengthArray));
|
// 5.11
|
||||||
|
// int64_t zeroLengthArray[] = {};
|
||||||
|
// CPPUNIT_ASSERT_EQUAL((size_t)0, A2_ARRAY_LEN(zeroLengthArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
Loading…
Reference in New Issue