diff mbox series

fwts_log: make line_number to a uint32_t type

Message ID 20170906093906.30475-1-colin.king@canonical.com
State Accepted
Headers show
Series fwts_log: make line_number to a uint32_t type | expand

Commit Message

Colin Ian King Sept. 6, 2017, 9:39 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

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

Signed-off-by: Colin Ian King <colin.king@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(-)

Comments

Alex Hung Sept. 7, 2017, 1:46 a.m. UTC | #1
On 2017-09-06 02:39 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Line numbers are never negative, so make line_number a uint32_t type
> 
> Signed-off-by: Colin Ian King <colin.king@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);
>   
> 
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu Sept. 21, 2017, 8 a.m. UTC | #2
On 09/06/2017 05:39 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Line numbers are never negative, so make line_number a uint32_t type
> 
> Signed-off-by: Colin Ian King <colin.king@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);
>   
> 

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

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);