xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] tools: fix several "format-truncation" warnings with GCC 7
@ 2017-06-12 17:51 Zhongze Liu
  2017-06-13 10:07 ` Wei Liu
  2017-06-13 10:19 ` Ian Jackson
  0 siblings, 2 replies; 5+ messages in thread
From: Zhongze Liu @ 2017-06-12 17:51 UTC (permalink / raw)
  To: xen-devel; +Cc: Wei Liu, Ian Jackson, Zhongze Liu, David Scott

GCC 7.1.1 complains that several buffers passed to snprintf() in xenpmd
and tools/ocmal/xc are too small to hold the largest possible resulting string.

enlarge the size of these buffers to fix the warnings.

Signed-off-by: Zhongze Liu <blackskygg@gmail.com>
---
CC: David Scott <dave@recoil.org>
CC: Ian Jackson <ian.jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>

Changed since v1:
  * Changed the word "error" to "warning" in title and description
  * Enlarge the buffer instead of replacing snprintf() with asprintf()
---
 tools/ocaml/libs/xc/xenctrl_stubs.c | 2 +-
 tools/xenpmd/xenpmd.c               | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c
index 5e455519d4..f1b28db53a 100644
--- a/tools/ocaml/libs/xc/xenctrl_stubs.c
+++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -54,7 +54,7 @@
 
 static void Noreturn failwith_xc(xc_interface *xch)
 {
-	char error_str[256];
+	char error_str[1028];
 	if (xch) {
 		const xc_error *error = xc_get_last_error(xch);
 		if (error->code == XC_ERROR_NONE)
diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c
index b3a31062aa..df96f2683f 100644
--- a/tools/xenpmd/xenpmd.c
+++ b/tools/xenpmd/xenpmd.c
@@ -100,7 +100,7 @@ FILE *get_next_battery_file(DIR *battery_dir,
 {
     FILE *file = 0;
     struct dirent *dir_entries;
-    char file_name[32];
+    char file_name[512];
     
     do 
     {
@@ -110,10 +110,10 @@ FILE *get_next_battery_file(DIR *battery_dir,
         if ( strlen(dir_entries->d_name) < 4 )
             continue;
         if ( battery_info_type == BIF ) 
-            snprintf(file_name, 32, BATTERY_INFO_FILE_PATH,
+	    snprintf(file_name, sizeof(file_name), BATTERY_INFO_FILE_PATH,
                      dir_entries->d_name);
         else 
-            snprintf(file_name, 32, BATTERY_STATE_FILE_PATH,
+            snprintf(file_name, sizeof(file_name), BATTERY_STATE_FILE_PATH,
                      dir_entries->d_name);
         file = fopen(file_name, "r");
     } while ( !file );
-- 
2.13.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tools: fix several "format-truncation" warnings with GCC 7
  2017-06-12 17:51 [PATCH v2] tools: fix several "format-truncation" warnings with GCC 7 Zhongze Liu
@ 2017-06-13 10:07 ` Wei Liu
  2017-06-13 10:19 ` Ian Jackson
  1 sibling, 0 replies; 5+ messages in thread
From: Wei Liu @ 2017-06-13 10:07 UTC (permalink / raw)
  To: Zhongze Liu; +Cc: xen-devel, Ian Jackson, Wei Liu, David Scott

On Tue, Jun 13, 2017 at 01:51:17AM +0800, Zhongze Liu wrote:
> GCC 7.1.1 complains that several buffers passed to snprintf() in xenpmd
> and tools/ocmal/xc are too small to hold the largest possible resulting string.
> 
> enlarge the size of these buffers to fix the warnings.
> 
> Signed-off-by: Zhongze Liu <blackskygg@gmail.com>

Acked-by: Wei Liu <wei.liu2@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tools: fix several "format-truncation" warnings with GCC 7
  2017-06-12 17:51 [PATCH v2] tools: fix several "format-truncation" warnings with GCC 7 Zhongze Liu
  2017-06-13 10:07 ` Wei Liu
@ 2017-06-13 10:19 ` Ian Jackson
  2017-06-13 10:52   ` Wei Liu
  1 sibling, 1 reply; 5+ messages in thread
From: Ian Jackson @ 2017-06-13 10:19 UTC (permalink / raw)
  To: Zhongze Liu; +Cc: xen-devel, Wei Liu, David Scott

Zhongze Liu writes ("[PATCH v2] tools: fix several "format-truncation" warnings with GCC 7"):
> GCC 7.1.1 complains that several buffers passed to snprintf() in
> xenpmd and tools/ocmal/xc are too small to hold the largest possible
> resulting string.
> 
> enlarge the size of these buffers to fix the warnings.

This is probably a reasonable approach.  But, I can't see where you
got the new maximum sizes.  Forgive me if I missed a mail, but I think
at least the commit message should explain how each of the new sizes
is calculated.

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tools: fix several "format-truncation" warnings with GCC 7
  2017-06-13 10:19 ` Ian Jackson
@ 2017-06-13 10:52   ` Wei Liu
  2017-06-13 16:03     ` Zhongze Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Wei Liu @ 2017-06-13 10:52 UTC (permalink / raw)
  To: Ian Jackson; +Cc: xen-devel, Wei Liu, Zhongze Liu, David Scott

On Tue, Jun 13, 2017 at 11:19:58AM +0100, Ian Jackson wrote:
> Zhongze Liu writes ("[PATCH v2] tools: fix several "format-truncation" warnings with GCC 7"):
> > GCC 7.1.1 complains that several buffers passed to snprintf() in
> > xenpmd and tools/ocmal/xc are too small to hold the largest possible
> > resulting string.
> > 
> > enlarge the size of these buffers to fix the warnings.
> 
> This is probably a reasonable approach.  But, I can't see where you
> got the new maximum sizes.  Forgive me if I missed a mail, but I think
> at least the commit message should explain how each of the new sizes
> is calculated.

Zhongze, please summarise what we discussed on IRC, especially the part
we figured out the various buffer sizes, in the commit message.

Ideally you should include the exact error messages in the commit
message, too.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tools: fix several "format-truncation" warnings with GCC 7
  2017-06-13 10:52   ` Wei Liu
@ 2017-06-13 16:03     ` Zhongze Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Zhongze Liu @ 2017-06-13 16:03 UTC (permalink / raw)
  To: Wei Liu, Ian Jackson; +Cc: xen-devel, David Scott

Hi Wei & Ian,

2017-06-13 18:52 GMT+08:00 Wei Liu <wei.liu2@citrix.com>:
> On Tue, Jun 13, 2017 at 11:19:58AM +0100, Ian Jackson wrote:
>> Zhongze Liu writes ("[PATCH v2] tools: fix several "format-truncation" warnings with GCC 7"):
>> > GCC 7.1.1 complains that several buffers passed to snprintf() in
>> > xenpmd and tools/ocmal/xc are too small to hold the largest possible
>> > resulting string.
>> >
>> > enlarge the size of these buffers to fix the warnings.
>>
>> This is probably a reasonable approach.  But, I can't see where you
>> got the new maximum sizes.  Forgive me if I missed a mail, but I think
>> at least the commit message should explain how each of the new sizes
>> is calculated.

OK, I'll add that.

>
> Zhongze, please summarise what we discussed on IRC, especially the part
> we figured out the various buffer sizes, in the commit message.
>
> Ideally you should include the exact error messages in the commit
> message, too.

Will do.

Cheers,

Zhongze Liu

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-13 16:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-12 17:51 [PATCH v2] tools: fix several "format-truncation" warnings with GCC 7 Zhongze Liu
2017-06-13 10:07 ` Wei Liu
2017-06-13 10:19 ` Ian Jackson
2017-06-13 10:52   ` Wei Liu
2017-06-13 16:03     ` Zhongze Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).