statzone

DNS zone file analyzer targeted at TLD zones
Log | Files | Refs | README | LICENSE

commit d61d53142e02c81eccd9a2513dbe35c01cb35351
parent 58a6f8c07d006ae126bebbc67d15a08cf7e3161c
Author: Frederic Cambus <fred@statdns.com>
Date:   Mon,  8 Feb 2021 15:16:02 +0100

Refactor the domain comparison checks, allows removing strdup("") call.

Diffstat:
Msrc/statzone.c | 7+++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/statzone.c b/src/statzone.c @@ -79,7 +79,7 @@ main(int argc, char *argv[]) int opt, token_count; char lineBuffer[LINE_LENGTH_MAX]; - char *intput, *domain, *previous_domain; + char *intput, *domain, *previous_domain = NULL; char *rdata, *token = NULL, *token_lc = NULL; if (pledge("stdio rpath", NULL) == -1) { @@ -143,8 +143,6 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - previous_domain = strdup(""); - while (fgets(lineBuffer, LINE_LENGTH_MAX, zonefile)) { if (!*lineBuffer) continue; @@ -204,7 +202,8 @@ main(int argc, char *argv[]) if (!strcmp(token_lc, "ns")) { results.ns++; - if (strlen(previous_domain) != strlen(domain) || + if (previous_domain == NULL || + strlen(previous_domain) != strlen(domain) || strncmp(domain, previous_domain, strlen(domain))) { results.domains++; free(previous_domain);