diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2013-10-25 15:44:52 +0100 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2013-10-25 15:44:52 +0100 |
commit | 2962faed63f4d4520ff34045859420b96b67d5ae (patch) | |
tree | 9647d960fe83e67b532b5d4c3fea423f273eea33 /gtk/scaffolding.c | |
parent | 1cf0125f2dc49363f6fd94e8462bbdcbbd5e8669 (diff) | |
download | netsurf-2962faed63f4d4520ff34045859420b96b67d5ae.tar.gz netsurf-2962faed63f4d4520ff34045859420b96b67d5ae.tar.bz2 |
fix gtk title setting to cope with null titles coverity 1109897
Diffstat (limited to 'gtk/scaffolding.c')
-rw-r--r-- | gtk/scaffolding.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c index 80b6dea4c..3d86975cc 100644 --- a/gtk/scaffolding.c +++ b/gtk/scaffolding.c @@ -2162,25 +2162,45 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel) return g; } +/** set the title in the window + * + * @param gw The gui window to set title on + * @param title The title to set (may be NULL) + */ void gui_window_set_title(struct gui_window *gw, const char *title) { - static char suffix[] = " - NetSurf"; - char nt[strlen(title) + strlen(suffix) + 1]; struct gtk_scaffolding *gs = nsgtk_get_scaffold(gw); + int title_len; + char *newtitle; - nsgtk_tab_set_title(gw, title); - - if (gs->top_level == gw) { - if (title == NULL || title[0] == '\0') { + if ((title == NULL) || (title[0] == '\0')) { + if (gs->top_level != gw) { gtk_window_set_title(gs->window, "NetSurf"); - } else { - strcpy(nt, title); - strcat(nt, suffix); - gtk_window_set_title(gs->window, nt); } + return; + } + + nsgtk_tab_set_title(gw, title); + + if (gs->top_level != gw) { + /* not top level window so do not set window title */ + return; + } + + title_len = strlen(title) + SLEN(" - NetSurf") + 1; + newtitle = malloc(title_len); + if (newtitle == NULL) { + return; } + + snprintf(newtitle, title_len, "%s - NetSurf", title); + + gtk_window_set_title(gs->window, newtitle); + + free(newtitle); } + void gui_window_set_url(struct gui_window *_g, const char *url) { struct gtk_scaffolding *g = nsgtk_get_scaffold(_g); |