Remove a temporary raw allocation.
This commit is contained in:
+5
-7
@@ -146,7 +146,7 @@ static std::string Hsts_parse_attr(const char **header_str)
|
|||||||
/**
|
/**
|
||||||
* Get the value in *header_str.
|
* Get the value in *header_str.
|
||||||
*/
|
*/
|
||||||
static char *Hsts_parse_value(const char **header_str)
|
static std::string Hsts_parse_value(const char **header_str)
|
||||||
{
|
{
|
||||||
uint_t len;
|
uint_t len;
|
||||||
const char *str;
|
const char *str;
|
||||||
@@ -167,7 +167,7 @@ static char *Hsts_parse_value(const char **header_str)
|
|||||||
str = *header_str;
|
str = *header_str;
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
return dStrndup(str, len);
|
return std::string{ str, str + len };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -199,22 +199,20 @@ void a_Hsts_set(const char *header, const DilloUrl *url)
|
|||||||
/* Iterate until there is nothing left of the string */
|
/* Iterate until there is nothing left of the string */
|
||||||
while (*header) {
|
while (*header) {
|
||||||
std::string attr;
|
std::string attr;
|
||||||
char *value;
|
|
||||||
|
|
||||||
/* Get attribute */
|
/* Get attribute */
|
||||||
attr = Hsts_parse_attr(&header);
|
attr = Hsts_parse_attr(&header);
|
||||||
|
|
||||||
/* Get the value for the attribute and store it */
|
/* Get the value for the attribute and store it */
|
||||||
if (dStrAsciiCasecmp(attr.c_str(), "max-age") == 0) {
|
if (dStrAsciiCasecmp(attr.c_str(), "max-age") == 0) {
|
||||||
value = Hsts_parse_value(&header);
|
auto value = Hsts_parse_value(&header);
|
||||||
if (isdigit(*value)) {
|
if (isdigit(*value.c_str())) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
max_age = strtol(value, NULL, 10);
|
max_age = strtol(value.c_str(), NULL, 10);
|
||||||
if (errno == ERANGE)
|
if (errno == ERANGE)
|
||||||
max_age = INT_MAX;
|
max_age = INT_MAX;
|
||||||
max_age_valid = TRUE;
|
max_age_valid = TRUE;
|
||||||
}
|
}
|
||||||
dFree(value);
|
|
||||||
} else if (dStrAsciiCasecmp(attr.c_str(), "includeSubDomains") == 0) {
|
} else if (dStrAsciiCasecmp(attr.c_str(), "includeSubDomains") == 0) {
|
||||||
subdomains = TRUE;
|
subdomains = TRUE;
|
||||||
Hsts_eat_value(&header);
|
Hsts_eat_value(&header);
|
||||||
|
|||||||
Reference in New Issue
Block a user