[PATCH] fwts_log: make line_number to a uint32_t type

Colin King colin.king at canonical.com
Wed Sep 6 09:39:06 UTC 2017


From: Colin Ian King <colin.king at canonical.com>

Line numbers are never negative, so make line_number a uint32_t type

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/include/fwts_log.h       | 2 +-
 src/lib/src/fwts_log_plaintext.c | 3 ++-
 src/lib/src/fwts_log_xml.c       | 3 ++-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/lib/include/fwts_log.h b/src/lib/include/fwts_log.h
index da8cb42b..3d4ecf9a 100644
--- a/src/lib/include/fwts_log.h
+++ b/src/lib/include/fwts_log.h
@@ -97,7 +97,7 @@ typedef struct log_t {
  */
 typedef struct {
 	FILE *fp;				/* file descriptor for log */
-	int line_number;			/* keeps track of the line numbering */
+	uint32_t line_number;			/* keeps track of the line numbering */
 	fwts_log *log;				/* parent log struct */
 	fwts_log_type type;			/* log type */
 	fwts_log_filename_type filename_type;	/* log filename type */
diff --git a/src/lib/src/fwts_log_plaintext.c b/src/lib/src/fwts_log_plaintext.c
index a4fbcec4..0cde841f 100644
--- a/src/lib/src/fwts_log_plaintext.c
+++ b/src/lib/src/fwts_log_plaintext.c
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdint.h>
 #include <string.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
@@ -52,7 +53,7 @@ static int fwts_log_header_plaintext(
 			ptr++;
 			if (!strncmp(ptr, "line", 4)) {
 				n += snprintf(buffer + n, len - n,
-					"%5.5d", log_file->line_number);
+					"%5.5" PRIu32, log_file->line_number);
 				ptr += 4;
 			}
 			if (!strncmp(ptr, "date", 4)) {
diff --git a/src/lib/src/fwts_log_xml.c b/src/lib/src/fwts_log_xml.c
index 273f0500..2954bb24 100644
--- a/src/lib/src/fwts_log_xml.c
+++ b/src/lib/src/fwts_log_xml.c
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdint.h>
 #include <string.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
@@ -67,7 +68,7 @@ static int fwts_log_print_xml(
 
 	fprintf(log_file->fp, "%*s<logentry>\n", xml_stack_index * XML_INDENT, "");
 
-	fprintf(log_file->fp, "%*s<line_num>%d</line_num>\n",
+	fprintf(log_file->fp, "%*s<line_num>%" PRIu32 "</line_num>\n",
 		(xml_stack_index + 1) * XML_INDENT,
 		"", log_file->line_number);
 
-- 
2.14.1




More information about the fwts-devel mailing list