client/locale: properly check popen return value
authorBernhard Miklautz <bernhard.miklautz@thincast.com>
Mon, 22 Jun 2015 12:26:11 +0000 (14:26 +0200)
committerBernhard Miklautz <bernhard.miklautz@thincast.com>
Mon, 22 Jun 2015 17:23:58 +0000 (19:23 +0200)
popen returns NULL if an error occurs and not < 0.

client/X11/xf_event.c
client/X11/xf_keyboard.c
libfreerdp/locale/keyboard_sun.c
libfreerdp/locale/keyboard_x11.c

index b5b2b71..5f13d50 100644 (file)
@@ -101,7 +101,7 @@ BOOL xf_event_action_script_init(xfContext* xfc)
 
        actionScript = popen(command, "r");
 
-       if (actionScript <= 0)
+       if (!actionScript)
                return FALSE;
 
        while (fgets(buffer, sizeof(buffer), actionScript))
@@ -170,7 +170,7 @@ static BOOL xf_event_execute_action_script(xfContext* xfc, XEvent* event)
 
        actionScript = popen(command, "r");
 
-       if (actionScript < 0)
+       if (!actionScript)
                return FALSE;
 
        while (fgets(buffer, sizeof(buffer), actionScript))
index 9630556..a85186f 100644 (file)
@@ -72,7 +72,7 @@ BOOL xf_keyboard_action_script_init(xfContext* xfc)
 
        keyScript = popen(command, "r");
 
-       if (keyScript < 0)
+       if (!keyScript)
        {
                free(xfc->actionScript);
                xfc->actionScript = NULL;
@@ -414,7 +414,7 @@ int xf_keyboard_execute_action_script(xfContext* xfc, XF_MODIFIER_KEYS* mod, Key
 
        keyScript = popen(command, "r");
 
-       if (keyScript < 0)
+       if (!keyScript)
                return -1;
 
        while (fgets(buffer, sizeof(buffer), keyScript) != NULL)
index 5f8b62e..111abf7 100644 (file)
@@ -227,7 +227,7 @@ int freerdp_get_solaris_keyboard_layout_and_type(int* type, int* layout)
 
        kbd = popen("kbd -t -l", "r");
 
-       if (kbd < 0)
+       if (!kbd)
                return -1;
 
        while (fgets(buffer, sizeof(buffer), kbd) != NULL)
index 387644d..e9ca41f 100644 (file)
@@ -48,7 +48,8 @@ int freerdp_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId)
 
        /* We start by looking for _XKB_RULES_NAMES_BACKUP which appears to be used by libxklavier */
 
-        xprop = popen("xprop -root _XKB_RULES_NAMES_BACKUP", "r");
+    if (!(xprop = popen("xprop -root _XKB_RULES_NAMES_BACKUP", "r")))
+               return 0;
 
        /* Sample output for "Canadian Multilingual Standard"
         *
@@ -100,7 +101,8 @@ int freerdp_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId)
 
        /* Check _XKB_RULES_NAMES if _XKB_RULES_NAMES_BACKUP fails */
 
-       xprop = popen("xprop -root _XKB_RULES_NAMES", "r");
+       if (!(xprop = popen("xprop -root _XKB_RULES_NAMES", "r")))
+               return 0;
 
        while (fgets(buffer, sizeof(buffer), xprop) != NULL)
        {
@@ -157,6 +159,9 @@ char* freerdp_detect_keymap_from_xkb()
        /* this tells us about the current XKB configuration, if XKB is available */
        setxkbmap = popen("setxkbmap -print", "r");
 
+       if (!setxkbmap)
+               return NULL;
+
        while (fgets(buffer, sizeof(buffer), setxkbmap) != NULL)
        {
                /* the line with xkb_keycodes is what interests us */