Use g_ascii_strto[u]ll instead of strto[u]l

We don't want GtkBuilder input to be locale-dependent.

Bug #632503
This commit is contained in:
=Christian Persch 2010-10-25 12:22:20 -04:00 committed by Matthias Clasen
parent 377e7179b8
commit d3f1745493
5 changed files with 45 additions and 28 deletions

View File

@ -239,7 +239,7 @@
#include "config.h"
#include <errno.h> /* errno */
#include <stdlib.h> /* strtol, strtoul */
#include <stdlib.h>
#include <string.h> /* strlen */
#include "gtkbuilder.h"
@ -1451,9 +1451,9 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
case G_TYPE_LONG:
{
long l;
gchar *endptr;
gchar *endptr = NULL;
errno = 0;
l = strtol (string, &endptr, 0);
l = g_ascii_strtoll (string, &endptr, 0);
if (errno || endptr == string)
{
g_set_error (error,
@ -1474,9 +1474,9 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
case G_TYPE_ULONG:
{
gulong ul;
gchar *endptr;
gchar *endptr = NULL;
errno = 0;
ul = strtoul (string, &endptr, 0);
ul = g_ascii_strtoull (string, &endptr, 0);
if (errno || endptr == string)
{
g_set_error (error,
@ -1520,7 +1520,7 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
case G_TYPE_DOUBLE:
{
gdouble d;
gchar *endptr;
gchar *endptr = NULL;
errno = 0;
d = g_ascii_strtod (string, &endptr);
if (errno || endptr == string)
@ -1676,8 +1676,10 @@ _gtk_builder_enum_from_string (GType type,
ret = TRUE;
value = strtoul (string, &endptr, 0);
if (endptr != string) /* parsed a number */
endptr = NULL;
errno = 0;
value = g_ascii_strtoull (string, &endptr, 0);
if (errno == 0 && endptr != string) /* parsed a number */
*enum_value = value;
else
{
@ -1723,9 +1725,11 @@ _gtk_builder_flags_from_string (GType type,
g_return_val_if_fail (string != 0, FALSE);
ret = TRUE;
value = strtoul (string, &endptr, 0);
if (endptr != string) /* parsed a number */
endptr = NULL;
errno = 0;
value = g_ascii_strtoull (string, &endptr, 0);
if (errno == 0 && endptr != string) /* parsed a number */
*flags_value = value;
else
{

View File

@ -335,9 +335,9 @@ attributes_text_element (GMarkupParseContext *context,
if (!parser_data->attr_name)
return;
errno = 0;
string = g_strndup (text, text_len);
l = strtol (string, &endptr, 0);
errno = 0;
l = g_ascii_strtoll (string, &endptr, 0);
if (errno || endptr == string)
{
g_set_error (error,

View File

@ -1357,7 +1357,7 @@ gtk_dialog_buildable_custom_finished (GtkBuildable *buildable,
}
ad = get_response_data (GTK_WIDGET (object), TRUE);
ad->response_id = atoi (item->response_id);
ad->response_id = g_ascii_strtoll (item->response_id, NULL, 10);
if (GTK_IS_BUTTON (object))
signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);

View File

@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "gdk-pixbuf/gdk-pixdata.h"
#include "gtktextbufferserialize.h"
@ -113,9 +114,10 @@ deserialize_value (const gchar *str,
gchar *tmp;
int v;
v = strtol (str, &tmp, 10);
errno = 0;
v = g_ascii_strtoll (str, &tmp, 10);
if (tmp == NULL || tmp == str)
if (errno || tmp == NULL || tmp == str)
return FALSE;
g_value_set_int (value, v);
@ -143,26 +145,32 @@ deserialize_value (const gchar *str,
gchar *tmp;
old = str;
color.red = strtol (old, &tmp, 16);
tmp = NULL;
errno = 0;
color.red = g_ascii_strtoll (old, &tmp, 16);
if (tmp == NULL || tmp == old)
if (errno || tmp == old)
return FALSE;
old = tmp;
if (*old++ != ':')
return FALSE;
color.green = strtol (old, &tmp, 16);
if (tmp == NULL || tmp == old)
tmp = NULL;
errno = 0;
color.green = g_ascii_strtoll (old, &tmp, 16);
if (errno || tmp == old)
return FALSE;
old = tmp;
if (*old++ != ':')
return FALSE;
color.blue = strtol (old, &tmp, 16);
tmp = NULL;
errno = 0;
color.blue = g_ascii_strtoll (old, &tmp, 16);
if (tmp == NULL || tmp == old || *tmp != '\0')
if (errno || tmp == old || *tmp != '\0')
return FALSE;
g_value_set_boxed (value, &color);
@ -836,9 +844,11 @@ check_id_or_name (GMarkupParseContext *context,
has_id = TRUE;
/* Try parsing the integer */
*id = strtol (attribute_values[i], &tmp, 10);
tmp = NULL;
errno = 0;
*id = g_ascii_strtoll (attribute_values[i], &tmp, 10);
if (tmp == NULL || tmp == attribute_values[i])
if (errno || tmp == attribute_values[i])
{
set_error (error, context,
G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
@ -1291,9 +1301,11 @@ parse_tag_element (GMarkupParseContext *context,
}
}
prio = strtol (priority, &tmp, 10);
tmp = NULL;
errno = 0;
prio = g_ascii_strtoll (priority, &tmp, 10);
if (tmp == NULL || tmp == priority)
if (errno || tmp == priority)
{
set_error (error, context,
G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,

View File

@ -531,9 +531,10 @@ extract_time_from_startup_id (const gchar* startup_id)
/* Skip past the "_TIME" part */
timestr += 5;
end = NULL;
errno = 0;
timestamp = strtoul (timestr, &end, 0);
if (end != timestr && errno == 0)
timestamp = g_ascii_strtoull (timestr, &end, 0);
if (errno == 0 && end != timestr)
retval = timestamp;
}