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
Tatsuhiro Tsujikawa 2012-03-01 00:02:29 +09:00
parent 037f1512db
commit e73c3c53ff
18 changed files with 67 additions and 68 deletions

View File

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

View File

@ -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;

View File

@ -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) {

View File

@ -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)));

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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);

View File

@ -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 {