statzone

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

commit fec850b886337eba131ce053450d2481cbfee473
parent 749f56a7881dbb08ee45b1c9851de3e57ee5c5cb
Author: Frederic Cambus <fred@statdns.com>
Date:   Tue, 16 Nov 2021 11:36:13 +0100

Switch to using getline(3) instead of fgets(3).

This allows reading lines of arbitrary length, and performance testing
using hyperfine didn't show any significant regressions.

Diffstat:
Msrc/config.hpp | 4+---
Msrc/statzone.cpp | 9++++++---
2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/config.hpp b/src/config.hpp @@ -4,7 +4,7 @@ * https://www.statdns.com * * Created: 2012-02-13 - * Last Updated: 2021-03-30 + * Last Updated: 2021-11-16 * * StatZone is released under the BSD 2-Clause license. * See LICENSE file for details. @@ -17,8 +17,6 @@ #define VERSION "StatZone 1.1.0" -#define LINE_LENGTH_MAX 65536 - struct results { uint64_t processedLines; uint64_t a; diff --git a/src/statzone.cpp b/src/statzone.cpp @@ -4,7 +4,7 @@ * https://www.statdns.com * * Created: 2012-02-13 - * Last Updated: 2021-04-03 + * Last Updated: 2021-11-16 * * StatZone is released under the BSD 2-Clause license. * See LICENSE file for details. @@ -71,7 +71,9 @@ main(int argc, char *argv[]) int opt, token_count; - char linebuffer[LINE_LENGTH_MAX]; + char *linebuffer = NULL; + size_t linesize = 0; + char *input; std::string domain, previous_domain; char *rdata, *token = nullptr, *token_lc = nullptr; @@ -129,7 +131,7 @@ main(int argc, char *argv[]) } } - while (fgets(linebuffer, LINE_LENGTH_MAX, zonefile)) { + while (getline(&linebuffer, &linesize, zonefile) != -1) { if (!*linebuffer) continue; @@ -227,6 +229,7 @@ main(int argc, char *argv[]) summary(); /* Clean up */ + free(linebuffer); fclose(zonefile); return EXIT_SUCCESS;