[glade] gtk+: workaround truncation warning by being safer
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade] gtk+: workaround truncation warning by being safer
- Date: Wed, 6 Nov 2019 12:36:43 +0000 (UTC)
commit 21551ac316f20a190fea475b084379ab8077c724
Author: Victor Toso <me victortoso com>
Date: Wed Nov 6 11:10:38 2019 +0100
gtk+: workaround truncation warning by being safer
Truncation was somewhat intended as column_name can fit 255 bytes plus
the null termination. Still, there is an easy workaround which is to
ensure that buffer is null terminated and then use strcpy. Should be a
bit safer and faster than strncpy().
> ../plugins/gtk+/glade-gtk-list-store.c:492:13: warning: ‘strncpy’
> output may be truncated copying 255 bytes from a string of length
> 255 [-Wstringop-truncation]
>
> 492 | strncpy (column_name, buffer, 255);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plugins/gtk+/glade-gtk-list-store.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/plugins/gtk+/glade-gtk-list-store.c b/plugins/gtk+/glade-gtk-list-store.c
index b30b58a1..bfaad360 100644
--- a/plugins/gtk+/glade-gtk-list-store.c
+++ b/plugins/gtk+/glade-gtk-list-store.c
@@ -479,6 +479,7 @@ glade_gtk_store_read_columns (GladeWidget *widget, GladeXmlNode *node)
{
GladeColumnType *data;
gchar *type, *comment_str, buffer[256];
+ buffer[255] = '\0';
if (!glade_xml_node_verify_silent (prop, GLADE_TAG_COLUMN) &&
!glade_xml_node_is_comment (prop))
@@ -487,8 +488,8 @@ glade_gtk_store_read_columns (GladeWidget *widget, GladeXmlNode *node)
if (glade_xml_node_is_comment (prop))
{
comment_str = glade_xml_get_content (prop);
- if (sscanf (comment_str, " column-name %s", buffer) == 1)
- strncpy (column_name, buffer, 255);
+ if (sscanf (comment_str, " column-name %255s", buffer) == 1)
+ strcpy (column_name, buffer);
g_free (comment_str);
continue;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]