]> git.scottworley.com Git - tl-append/commitdiff
test: Dynamic buffer size
authorScott Worley <scottworley@scottworley.com>
Thu, 31 Aug 2023 18:08:25 +0000 (11:08 -0700)
committerScott Worley <scottworley@scottworley.com>
Fri, 1 Sep 2023 07:44:10 +0000 (00:44 -0700)
tl-append-test.c

index 6761b02b335cc10f98fe26a264f791c715935a3f..22589da464db8ba2f6cf362c921903750b3818bd 100644 (file)
@@ -37,18 +37,20 @@ static void write_to_tl_append(const char *content) {
 }
 
 static void verify_log_contents(const char *contents) {
-  char buf[10];
+  size_t len = strlen(contents);
+  char *buf = (char *)malloc(len + 2);
 
   FILE *f = fopen("tl.log", "r");
   if (f == NULL)
     die_err("Error opening log file");
-  buf[fread(buf, 1, sizeof(buf), f)] = '\0';
+  buf[fread(buf, 1, len + 1, f)] = '\0';
   if (ferror(f))
     die("Error reading log file");
-  if (strncmp(contents, buf, sizeof(buf)) != 0)
+  if (strncmp(contents, buf, len + 1) != 0)
     die("Wrong contents in log file");
   if (fclose(f) != 0)
     die_err("Error closing log file");
+  free(buf);
 }
 
 static void write_and_read_line() {