mirror of https://github.com/aria2/aria2
2009-11-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added util::parseUIntNoThrow(). Use it in Request::parseUrl(). * src/Request.cc * src/util.cc * src/util.h * test/RequestTest.ccpull/1/head
parent
8865b9e8e6
commit
9cdf102850
|
@ -1,3 +1,11 @@
|
||||||
|
2009-11-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Added util::parseUIntNoThrow(). Use it in Request::parseUrl().
|
||||||
|
* src/Request.cc
|
||||||
|
* src/util.cc
|
||||||
|
* src/util.h
|
||||||
|
* test/RequestTest.cc
|
||||||
|
|
||||||
2009-11-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-11-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Rewritten util::uitos()
|
Rewritten util::uitos()
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "FeatureConfig.h"
|
#include "FeatureConfig.h"
|
||||||
#include "RecoverableException.h"
|
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
#include "a2functional.h"
|
#include "a2functional.h"
|
||||||
|
@ -252,14 +251,13 @@ bool Request::parseUrl(const std::string& url) {
|
||||||
// its protocol..
|
// its protocol..
|
||||||
_port = defPort;
|
_port = defPort;
|
||||||
} else {
|
} else {
|
||||||
try {
|
uint32_t tempPort;
|
||||||
unsigned int tempPort =
|
if(util::parseUIntNoThrow(tempPort, std::string(portFirst, authorityLast))){
|
||||||
util::parseUInt(std::string(portFirst, authorityLast));
|
|
||||||
if(65535 < tempPort) {
|
if(65535 < tempPort) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_port = tempPort;
|
_port = tempPort;
|
||||||
} catch(RecoverableException& e) {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
22
src/util.cc
22
src/util.cc
|
@ -395,6 +395,28 @@ uint32_t parseUInt(const std::string& s, int base)
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool parseUIntNoThrow(uint32_t& result, const std::string& s, int base)
|
||||||
|
{
|
||||||
|
std::string trimed = trim(s);
|
||||||
|
if(trimed.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// We don't allow negative number.
|
||||||
|
if(trimed[0] == '-') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
char* stop;
|
||||||
|
errno = 0;
|
||||||
|
unsigned long int v = strtoul(trimed.c_str(), &stop, base);
|
||||||
|
if(*stop != '\0') {
|
||||||
|
return false;
|
||||||
|
} else if(((v == ULONG_MAX) && (errno == ERANGE)) || (v > UINT32_MAX)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
result = v;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int64_t parseLLInt(const std::string& s, int32_t base)
|
int64_t parseLLInt(const std::string& s, int32_t base)
|
||||||
{
|
{
|
||||||
std::string trimed = trim(s);
|
std::string trimed = trim(s);
|
||||||
|
|
|
@ -180,6 +180,8 @@ int32_t parseInt(const std::string& s, int32_t base = 10);
|
||||||
|
|
||||||
uint32_t parseUInt(const std::string& s, int base = 10);
|
uint32_t parseUInt(const std::string& s, int base = 10);
|
||||||
|
|
||||||
|
bool parseUIntNoThrow(uint32_t& result, const std::string& s, int base = 10);
|
||||||
|
|
||||||
int64_t parseLLInt(const std::string& s, int32_t base = 10);
|
int64_t parseLLInt(const std::string& s, int32_t base = 10);
|
||||||
|
|
||||||
uint64_t parseULLInt(const std::string& s, int base = 10);
|
uint64_t parseULLInt(const std::string& s, int base = 10);
|
||||||
|
|
Loading…
Reference in New Issue