commit 1a96c86f79d76ceab52a096a90df923cf922d0e0
parent b1d9548b03afee818362874bb4761fea904afbd6
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date: Wed, 24 Jun 2015 23:55:01 +0200
Using 'strtonum' to populate the hourly distribution array
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/logswan.c b/src/logswan.c
@@ -54,6 +54,8 @@ int hour;
struct stat logFileSize;
FILE *logFile;
+const char *errstr;
+
char *endptr;
int getoptFlag;
@@ -113,9 +115,9 @@ int main (int argc, char *argv[]) {
parseDate(&parsedDate, parsedLine.date);
if (parsedDate.hour) { /* Do not feed NULL tokens to atoi */
- hour = atoi(parsedDate.hour);
+ hour = strtonum(parsedDate.hour, 0, 23, &errstr);
- if (hour < 24) {
+ if (!errstr) {
results.hours[hour] ++;
}
}