mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
fixed leak in short option parsing. rewrote parts of the code to be more
Tue May 2 14:18:25 2006 Tim Janik <timj@gtk.org> * glib/goption.c (g_option_context_parse): fixed leak in short option parsing. rewrote parts of the code to be more concise to enhance readability. fixed exaggerated uses of strlen.
This commit is contained in:
parent
fdb17e7e96
commit
34ee852317
@ -1,3 +1,9 @@
|
|||||||
|
Tue May 2 14:18:25 2006 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* glib/goption.c (g_option_context_parse): fixed leak in short
|
||||||
|
option parsing. rewrote parts of the code to be more concise to
|
||||||
|
enhance readability. fixed exaggerated uses of strlen.
|
||||||
|
|
||||||
2006-04-28 Behdad Esfahbod <behdad@gnome.org>
|
2006-04-28 Behdad Esfahbod <behdad@gnome.org>
|
||||||
|
|
||||||
* glib/guniprop.c: #include <stdlib.h>
|
* glib/guniprop.c: #include <stdlib.h>
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
Tue May 2 14:18:25 2006 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* glib/goption.c (g_option_context_parse): fixed leak in short
|
||||||
|
option parsing. rewrote parts of the code to be more concise to
|
||||||
|
enhance readability. fixed exaggerated uses of strlen.
|
||||||
|
|
||||||
2006-04-28 Behdad Esfahbod <behdad@gnome.org>
|
2006-04-28 Behdad Esfahbod <behdad@gnome.org>
|
||||||
|
|
||||||
* glib/guniprop.c: #include <stdlib.h>
|
* glib/guniprop.c: #include <stdlib.h>
|
||||||
|
@ -1446,36 +1446,23 @@ g_option_context_parse (GOptionContext *context,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{ /* short option */
|
||||||
/* short option */
|
gint j, new_i = i, arg_length;
|
||||||
|
|
||||||
gint new_i, j;
|
|
||||||
gboolean *nulled_out = NULL;
|
gboolean *nulled_out = NULL;
|
||||||
|
|
||||||
arg = (*argv)[i] + 1;
|
arg = (*argv)[i] + 1;
|
||||||
|
arg_length = strlen (arg);
|
||||||
new_i = i;
|
nulled_out = g_newa (gboolean, arg_length);
|
||||||
|
memset (nulled_out, 0, arg_length * sizeof (gboolean));
|
||||||
if (context->ignore_unknown)
|
for (j = 0; j < arg_length; j++)
|
||||||
nulled_out = g_new0 (gboolean, strlen (arg));
|
|
||||||
|
|
||||||
for (j = 0; j < strlen (arg); j++)
|
|
||||||
{
|
{
|
||||||
if (context->help_enabled && arg[j] == '?')
|
if (context->help_enabled && arg[j] == '?')
|
||||||
print_help (context, TRUE, NULL);
|
print_help (context, TRUE, NULL);
|
||||||
|
|
||||||
parsed = FALSE;
|
parsed = FALSE;
|
||||||
|
|
||||||
if (context->main_group &&
|
if (context->main_group &&
|
||||||
!parse_short_option (context, context->main_group,
|
!parse_short_option (context, context->main_group,
|
||||||
i, &new_i, arg[j],
|
i, &new_i, arg[j],
|
||||||
argc, argv, error, &parsed))
|
argc, argv, error, &parsed))
|
||||||
{
|
goto fail;
|
||||||
|
|
||||||
g_free (nulled_out);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!parsed)
|
if (!parsed)
|
||||||
{
|
{
|
||||||
/* Try the groups */
|
/* Try the groups */
|
||||||
@ -1483,47 +1470,38 @@ g_option_context_parse (GOptionContext *context,
|
|||||||
while (list)
|
while (list)
|
||||||
{
|
{
|
||||||
GOptionGroup *group = list->data;
|
GOptionGroup *group = list->data;
|
||||||
|
|
||||||
if (!parse_short_option (context, group, i, &new_i, arg[j],
|
if (!parse_short_option (context, group, i, &new_i, arg[j],
|
||||||
argc, argv, error, &parsed))
|
argc, argv, error, &parsed))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (parsed)
|
if (parsed)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
list = list->next;
|
list = list->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context->ignore_unknown)
|
if (context->ignore_unknown && parsed)
|
||||||
{
|
nulled_out[j] = TRUE;
|
||||||
if (parsed)
|
else if (context->ignore_unknown)
|
||||||
nulled_out[j] = TRUE;
|
continue;
|
||||||
else
|
else if (!parsed)
|
||||||
continue;
|
break;
|
||||||
}
|
/* !context->ignore_unknown && parsed */
|
||||||
|
|
||||||
if (!parsed)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context->ignore_unknown)
|
if (context->ignore_unknown)
|
||||||
{
|
{
|
||||||
gchar *new_arg = NULL;
|
gchar *new_arg = NULL;
|
||||||
gint arg_index = 0;
|
gint arg_index = 0;
|
||||||
|
for (j = 0; j < arg_length; j++)
|
||||||
for (j = 0; j < strlen (arg); j++)
|
|
||||||
{
|
{
|
||||||
if (!nulled_out[j])
|
if (!nulled_out[j])
|
||||||
{
|
{
|
||||||
if (!new_arg)
|
if (!new_arg)
|
||||||
new_arg = g_malloc (strlen (arg) + 1);
|
new_arg = g_malloc (arg_length + 1);
|
||||||
new_arg[arg_index++] = arg[j];
|
new_arg[arg_index++] = arg[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (new_arg)
|
if (new_arg)
|
||||||
new_arg[arg_index] = '\0';
|
new_arg[arg_index] = '\0';
|
||||||
|
|
||||||
add_pending_null (context, &((*argv)[i]), new_arg);
|
add_pending_null (context, &((*argv)[i]), new_arg);
|
||||||
}
|
}
|
||||||
else if (parsed)
|
else if (parsed)
|
||||||
|
Loading…
Reference in New Issue
Block a user