|
@@ -101,7 +101,8 @@ std::pair<std::string, std::string> Util::split(const std::string& src, const st
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int64_t Util::difftv(struct timeval tv1, struct timeval tv2) {
|
|
int64_t Util::difftv(struct timeval tv1, struct timeval tv2) {
|
|
|
- if(tv1.tv_sec < tv2.tv_sec || tv1.tv_sec == tv2.tv_sec && tv1.tv_usec < tv2.tv_usec) {
|
|
|
|
|
|
|
+ if((tv1.tv_sec < tv2.tv_sec) ||
|
|
|
|
|
+ ((tv1.tv_sec == tv2.tv_sec) && (tv1.tv_usec < tv2.tv_usec))) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
return ((int64_t)(tv1.tv_sec-tv2.tv_sec)*1000000+
|
|
return ((int64_t)(tv1.tv_sec-tv2.tv_sec)*1000000+
|
|
@@ -188,9 +189,9 @@ std::string Util::replace(const std::string& target, const std::string& oldstr,
|
|
|
bool Util::shouldUrlencode(const char c)
|
|
bool Util::shouldUrlencode(const char c)
|
|
|
{
|
|
{
|
|
|
return !(// ALPHA
|
|
return !(// ALPHA
|
|
|
- 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' ||
|
|
|
|
|
|
|
+ ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') ||
|
|
|
// DIGIT
|
|
// DIGIT
|
|
|
- '0' <= c && c <= '9' ||
|
|
|
|
|
|
|
+ ('0' <= c && c <= '9') ||
|
|
|
// safe
|
|
// safe
|
|
|
'$' == c || '-' == c || '_' == c || '.' == c ||
|
|
'$' == c || '-' == c || '_' == c || '.' == c ||
|
|
|
// extra
|
|
// extra
|
|
@@ -219,9 +220,9 @@ std::string Util::urlencode(const unsigned char* target, int32_t len) {
|
|
|
std::string Util::torrentUrlencode(const unsigned char* target, int32_t len) {
|
|
std::string Util::torrentUrlencode(const unsigned char* target, int32_t len) {
|
|
|
std::string dest;
|
|
std::string dest;
|
|
|
for(int32_t i = 0; i < len; i++) {
|
|
for(int32_t i = 0; i < len; i++) {
|
|
|
- if('0' <= target[i] && target[i] <= '9' ||
|
|
|
|
|
- 'A' <= target[i] && target[i] <= 'Z' ||
|
|
|
|
|
- 'a' <= target[i] && target[i] <= 'z') {
|
|
|
|
|
|
|
+ if(('0' <= target[i] && target[i] <= '9') ||
|
|
|
|
|
+ ('A' <= target[i] && target[i] <= 'Z') ||
|
|
|
|
|
+ ('a' <= target[i] && target[i] <= 'z')) {
|
|
|
dest += target[i];
|
|
dest += target[i];
|
|
|
} else {
|
|
} else {
|
|
|
char temp[4];
|
|
char temp[4];
|
|
@@ -409,7 +410,9 @@ int32_t Util::parseInt(const std::string& s, int32_t base)
|
|
|
if(*stop != '\0') {
|
|
if(*stop != '\0') {
|
|
|
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
|
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
|
|
trimed.c_str());
|
|
trimed.c_str());
|
|
|
- } else if((v == LONG_MIN || v == LONG_MAX) && errno == ERANGE || v > INT32_MAX || v < INT32_MIN) {
|
|
|
|
|
|
|
+ } else if((((v == LONG_MIN) || (v == LONG_MAX)) && (errno == ERANGE)) ||
|
|
|
|
|
+ (v > INT32_MAX) ||
|
|
|
|
|
+ (v < INT32_MIN)) {
|
|
|
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
|
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
|
|
trimed.c_str());
|
|
trimed.c_str());
|
|
|
}
|
|
}
|
|
@@ -429,7 +432,7 @@ int64_t Util::parseLLInt(const std::string& s, int32_t base)
|
|
|
if(*stop != '\0') {
|
|
if(*stop != '\0') {
|
|
|
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
|
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
|
|
trimed.c_str());
|
|
trimed.c_str());
|
|
|
- } else if((v == INT64_MIN || v == INT64_MAX) && errno == ERANGE) {
|
|
|
|
|
|
|
+ } else if(((v == INT64_MIN) || (v == INT64_MAX)) && (errno == ERANGE)) {
|
|
|
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
|
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
|
|
trimed.c_str());
|
|
trimed.c_str());
|
|
|
}
|
|
}
|
|
@@ -596,7 +599,7 @@ int64_t Util::getRealSize(const std::string& sizeWithUnit)
|
|
|
|
|
|
|
|
if(v < 0) {
|
|
if(v < 0) {
|
|
|
throw new DlAbortEx("Negative value detected: %s", sizeWithUnit.c_str());
|
|
throw new DlAbortEx("Negative value detected: %s", sizeWithUnit.c_str());
|
|
|
- } else if(v*mult < 0) {
|
|
|
|
|
|
|
+ } else if(INT64_MAX/mult < v) {
|
|
|
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
|
throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE,
|
|
|
"overflow/underflow");
|
|
"overflow/underflow");
|
|
|
}
|
|
}
|