[gtk+] Use g_ascii_strto[u]ll instead of strto[u]l
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Use g_ascii_strto[u]ll instead of strto[u]l
- Date: Mon, 25 Oct 2010 16:22:54 +0000 (UTC)
commit d3f1745493867d37f7c7cbe48002ce076c9db5f7
Author: =Christian Persch <chpe gnome org>
Date: Mon Oct 25 12:22:20 2010 -0400
Use g_ascii_strto[u]ll instead of strto[u]l
We don't want GtkBuilder input to be locale-dependent.
Bug #632503
gtk/gtkbuilder.c | 26 +++++++++++++++-----------
gtk/gtkcelllayout.c | 4 ++--
gtk/gtkdialog.c | 2 +-
gtk/gtktextbufferserialize.c | 36 ++++++++++++++++++++++++------------
gtk/gtkwindow.c | 5 +++--
5 files changed, 45 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index 06ab410..7ed026c 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -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
{
diff --git a/gtk/gtkcelllayout.c b/gtk/gtkcelllayout.c
index 86e8e39..8388b5f 100644
--- a/gtk/gtkcelllayout.c
+++ b/gtk/gtkcelllayout.c
@@ -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,
diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c
index 86e28e3..cf95927 100644
--- a/gtk/gtkdialog.c
+++ b/gtk/gtkdialog.c
@@ -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);
diff --git a/gtk/gtktextbufferserialize.c b/gtk/gtktextbufferserialize.c
index 04f684b..16a36d3 100644
--- a/gtk/gtktextbufferserialize.c
+++ b/gtk/gtktextbufferserialize.c
@@ -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,
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index fb63d1c..216054c 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]