GMutex (linux): detect and report some errors
[platform/upstream/glib.git] / glib / goption.c
index 31bbf16..6438281 100644 (file)
 #include <errno.h>
 
 #if defined __OpenBSD__
-#include <sys/types.h>
 #include <unistd.h>
-#include <sys/param.h>
 #include <sys/sysctl.h>
 #endif
 
@@ -1190,8 +1188,8 @@ parse_arg (GOptionContext *context,
     {
     case G_OPTION_ARG_NONE:
       {
-        change = get_change (context, G_OPTION_ARG_NONE,
-                             entry->arg_data);
+        (void) get_change (context, G_OPTION_ARG_NONE,
+                           entry->arg_data);
 
         *(gboolean *)entry->arg_data = !(entry->flags & G_OPTION_FLAG_REVERSE);
         break;
@@ -1763,13 +1761,16 @@ platform_get_argv0 (void)
   g_free (cmdline);
   return base_arg0;
 #elif defined __OpenBSD__
-  char **cmdline = NULL;
+  char **cmdline;
   char *base_arg0;
-  gsize len = PATH_MAX;
+  gsize len;
 
   int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
 
-  cmdline = (char **) realloc (cmdline, len);
+  if (sysctl (mib, G_N_ELEMENTS (mib), NULL, &len, NULL, 0) == -1)
+      return NULL;
+
+  cmdline = g_malloc0 (len);
 
   if (sysctl (mib, G_N_ELEMENTS (mib), cmdline, &len, NULL, 0) == -1)
     {
@@ -2037,6 +2038,7 @@ g_option_context_parse (GOptionContext   *context,
                       if (new_arg)
                         new_arg[arg_index] = '\0';
                       add_pending_null (context, &((*argv)[i]), new_arg);
+                      i = new_i;
                     }
                   else if (parsed)
                     {