Browse Source

Measure length of log timestamp more consistently

June 1 week ago
parent
commit
3d9906b00f
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
1 changed files with 4 additions and 4 deletions
  1. 4
    4
      log.c

+ 4
- 4
log.c View File

@@ -91,7 +91,7 @@ static FILE *logFile(struct Tag tag, const struct tm *time) {
91 91
 	return log->file;
92 92
 }
93 93
 
94
-enum { StampSize = sizeof("YYYY-MM-DDThh:mm:ss+hhmm") };
94
+enum { StampLen = sizeof("YYYY-MM-DDThh:mm:ss+hhmm") - 1 };
95 95
 
96 96
 void logFmt(struct Tag tag, const time_t *ts, const char *format, ...) {
97 97
 	if (logRoot < 0) return;
@@ -107,8 +107,8 @@ void logFmt(struct Tag tag, const time_t *ts, const char *format, ...) {
107 107
 
108 108
 	FILE *file = logFile(tag, time);
109 109
 
110
-	char stamp[StampSize];
111
-	strftime(stamp, StampSize, "%FT%T%z", time);
110
+	char stamp[StampLen + 1];
111
+	strftime(stamp, sizeof(stamp), "%FT%T%z", time);
112 112
 	fprintf(file, "[%s] ", stamp);
113 113
 	if (ferror(file)) err(EX_IOERR, "%s", tag.name);
114 114
 
@@ -136,7 +136,7 @@ void logReplay(struct Tag tag) {
136 136
 	char *line;
137 137
 	while (NULL != (line = fgetln(file, &len))) {
138 138
 		line[len - 1] = '\0';
139
-		if (len > 2 + StampSize) line = &line[2 + StampSize];
139
+		if (len > 1 + StampLen + 2) line = &line[1 + StampLen + 2];
140 140
 		uiFmt(tag, UICold, "\3%d%s", IRCGray, line);
141 141
 	}
142 142
 	if (ferror(file)) err(EX_IOERR, "%s", tag.name);

Loading…
Cancel
Save