fix calculated size

This commit is contained in:
rakslice 2020-11-19 15:54:10 -08:00
parent 5163e17f14
commit 6d74ff5600

View File

@ -72,14 +72,12 @@ int prepare_host_domain_suffixes(char * buf) {
if (buf) buf[pos] = '.'; if (buf) buf[pos] = '.';
pos++; pos++;
} }
if (buf) {
const char * str_pos = str; const char * str_pos = str;
while (*str_pos != '\0') { while (*str_pos != '\0') {
buf[pos] = tolower(*str_pos); if (buf) buf[pos] = tolower(*str_pos);
++pos; ++pos;
++str_pos; ++str_pos;
} }
};
// domain to be checked will be FQDN so suffix must have a trailing dot // domain to be checked will be FQDN so suffix must have a trailing dot
if (str[strlen(str) - 1] != '.') { if (str[strlen(str) - 1] != '.') {
if (buf) buf[pos] = '.'; if (buf) buf[pos] = '.';
@ -102,7 +100,8 @@ void load_host_domains() {
const int size = prepare_host_domain_suffixes(NULL); const int size = prepare_host_domain_suffixes(NULL);
char * buf = malloc(size); char * buf = malloc(size);
if (buf) { if (buf) {
prepare_host_domain_suffixes(buf); const int second_size = prepare_host_domain_suffixes(buf);
assert(size == second_size);
host_resolved_domain_suffixes = (const char **) buf; host_resolved_domain_suffixes = (const char **) buf;
} }
} }