diff options
author | Victor Toso <me@victortoso.com> | 2019-11-06 11:10:38 +0100 |
---|---|---|
committer | Victor Toso <me@victortoso.com> | 2019-11-06 11:10:40 +0100 |
commit | 21551ac316f20a190fea475b084379ab8077c724 (patch) | |
tree | ce60755b6689b781692f4503cd784db0c2842b3f /plugins | |
parent | a554b9602d8dc356e96d6f14ac4deba2daba4456 (diff) | |
download | glade-21551ac316f20a190fea475b084379ab8077c724.tar.gz |
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);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/gtk+/glade-gtk-list-store.c | 5 |
1 files 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; |