SDL_SetWindowTitle() should never set a NULL pointer for the title string. Various backends reacted differently (or not at all) in the presence of a NULL pointer. This simplifies things. Fixes Bugzilla #2902.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 45e9960..1a3076e 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -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);
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 068c59e..2d301e4 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -1189,16 +1189,9 @@ Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
{
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];
}
diff --git a/src/video/directfb/SDL_DirectFB_WM.c b/src/video/directfb/SDL_DirectFB_WM.c
index b48a106..e85c8d1 100644
--- a/src/video/directfb/SDL_DirectFB_WM.c
+++ b/src/video/directfb/SDL_DirectFB_WM.c
@@ -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);
}
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 463db1e..d3aaebd 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -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);
}
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 5714829..2da45e8 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -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) {