2
0
Эх сурвалжийг харах

SDL_zenitymessagebox.c: Add exit code checking.

Fixes https://github.com/libsdl-org/SDL/issues/14140
Closes https://github.com/libsdl-org/SDL/pull/14146

Co-authored-by: eafton <[email protected]>
Ozkan Sezer 1 долоо хоног өмнө
parent
commit
3723913969

+ 10 - 4
src/dialog/unix/SDL_zenitymessagebox.c

@@ -75,6 +75,7 @@ bool SDL_get_zenity_version(int *major, int *minor)
 
 bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
 {
+    int exit_code = -1;
     int zenity_major = 0, zenity_minor = 0, output_len = 0;
     int argc = 5, i;
     const char *argv[5 + 2 /* icon name */ + 2 /* title */ + 2 /* message */ + 2 * MAX_BUTTONS + 1 /* NULL */] = {
@@ -158,8 +159,12 @@ bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu
         return false;
     }
     if (buttonID) {
-        char *output = SDL_ReadProcess(process, NULL, NULL);
-        if (output) {
+        char *output = SDL_ReadProcess(process, NULL, &exit_code);
+        if (exit_code < 0 || exit_code == 255) {
+            if (output) {
+                SDL_free(output);
+            }
+        } else if (output) {
             // It likes to add a newline...
             char *tmp = SDL_strrchr(output, '\n');
             if (tmp) {
@@ -177,9 +182,10 @@ bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu
             }
             SDL_free(output);
         }
+    } else {
+        SDL_WaitProcess(process, true, &exit_code);
     }
     SDL_DestroyProcess(process);
 
-    return true;
+    return !(exit_code < 0 || exit_code == 255);
 }
-