Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SDL_SetWindowTitle() should never set a NULL pointer for the title st…
…ring.

Various backends reacted differently (or not at all) in the presence of a
NULL pointer. This simplifies things.

Fixes Bugzilla #2902.
  • Loading branch information
icculus committed Apr 8, 2015
1 parent 1339ce7 commit 6e53bc9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 43 deletions.
7 changes: 2 additions & 5 deletions src/video/SDL_video.c
Expand Up @@ -1502,11 +1502,8 @@ SDL_SetWindowTitle(SDL_Window * window, const char *title)
return;
}
SDL_free(window->title);
if (title && *title) {
window->title = SDL_strdup(title);
} else {
window->title = NULL;
}

window->title = SDL_strdup(title ? title : "");

if (_this->SetWindowTitle) {
_this->SetWindowTitle(_this, window);
Expand Down
9 changes: 1 addition & 8 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -1189,16 +1189,9 @@ - (void)resetCursorRects
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
NSString *string;

if(window->title) {
string = [[NSString alloc] initWithUTF8String:window->title];
} else {
string = [[NSString alloc] init];
}
NSString *string = [[NSString alloc] initWithUTF8String:window->title];
[nswindow setTitle:string];
[string release];

[pool release];
}

Expand Down
2 changes: 1 addition & 1 deletion src/video/directfb/SDL_DirectFB_WM.c
Expand Up @@ -161,7 +161,7 @@ DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window)
y, w - 2 * d);

/* Caption */
if (window->title) {
if (*window->title) {
s->SetColor(s, COLOR_EXPAND(t->font_color));
DrawCraption(_this, s, (x - w) / 2, t->top_size + d, window->title);
}
Expand Down
10 changes: 2 additions & 8 deletions src/video/windows/SDL_windowswindow.c
Expand Up @@ -371,14 +371,8 @@ void
WIN_SetWindowTitle(_THIS, SDL_Window * window)
{
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
LPTSTR title;

if (window->title) {
title = WIN_UTF8ToString(window->title);
} else {
title = NULL;
}
SetWindowText(hwnd, title ? title : TEXT(""));
LPTSTR title = WIN_UTF8ToString(window->title);
SetWindowText(hwnd, title);
SDL_free(title);
}

Expand Down
42 changes: 21 additions & 21 deletions src/video/x11/SDL_x11window.c
Expand Up @@ -658,39 +658,39 @@ X11_SetWindowTitle(_THIS, SDL_Window * window)
Display *display = data->videodata->display;
XTextProperty titleprop, iconprop;
Status status;
const char *title = window->title;
const char *title = window->title ? window->title : "";
const char *icon = NULL;
char *title_locale = NULL;

#ifdef X_HAVE_UTF8_STRING
Atom _NET_WM_NAME = data->videodata->_NET_WM_NAME;
Atom _NET_WM_ICON_NAME = data->videodata->_NET_WM_ICON_NAME;
#endif

if (title != NULL) {
char *title_locale = SDL_iconv_utf8_locale(title);
if (!title_locale) {
SDL_OutOfMemory();
return;
}
status = X11_XStringListToTextProperty(&title_locale, 1, &titleprop);
SDL_free(title_locale);
if (status) {
X11_XSetTextProperty(display, data->xwindow, &titleprop, XA_WM_NAME);
X11_XFree(titleprop.value);
}
title_locale = SDL_iconv_utf8_locale(title);
if (!title_locale) {
SDL_OutOfMemory();
return;
}

status = X11_XStringListToTextProperty(&title_locale, 1, &titleprop);
SDL_free(title_locale);
if (status) {
X11_XSetTextProperty(display, data->xwindow, &titleprop, XA_WM_NAME);
X11_XFree(titleprop.value);
}
#ifdef X_HAVE_UTF8_STRING
if (SDL_X11_HAVE_UTF8) {
status =
X11_Xutf8TextListToTextProperty(display, (char **) &title, 1,
if (SDL_X11_HAVE_UTF8) {
status = X11_Xutf8TextListToTextProperty(display, (char **) &title, 1,
XUTF8StringStyle, &titleprop);
if (status == Success) {
X11_XSetTextProperty(display, data->xwindow, &titleprop,
if (status == Success) {
X11_XSetTextProperty(display, data->xwindow, &titleprop,
_NET_WM_NAME);
X11_XFree(titleprop.value);
}
X11_XFree(titleprop.value);
}
#endif
}
#endif

if (icon != NULL) {
char *icon_locale = SDL_iconv_utf8_locale(icon);
if (!icon_locale) {
Expand Down

0 comments on commit 6e53bc9

Please sign in to comment.