From 3db329a61368ba90c1422e2b0e6197a103130287 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 20 Jan 2005 17:16:47 +0000 Subject: [PATCH] Don't interpret leading zeros as octal. The specification requires %f 2005-01-20 Matthias Clasen * glib/gkeyfile.c (g_key_file_parse_value_as_integer): Don't interpret leading zeros as octal. The specification requires %f parsing, and %f doesn't allow octal. * tests/keyfile-test.c: Add some more tests. --- ChangeLog | 4 ++++ ChangeLog.pre-2-10 | 4 ++++ ChangeLog.pre-2-12 | 4 ++++ ChangeLog.pre-2-8 | 4 ++++ glib/gkeyfile.c | 2 +- tests/keyfile-test.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 82 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5fbe34b..cab6839 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2005-01-20 Matthias Clasen + * glib/gkeyfile.c (g_key_file_parse_value_as_integer): Don't + interpret leading zeros as octal. The specification requires + %f parsing, and %f doesn't allow octal. + * tests/keyfile-test.c: Add some more tests. * glib/gkeyfile.c (g_key_file_get_keys): Return keys in diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 5fbe34b..cab6839 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,9 @@ 2005-01-20 Matthias Clasen + * glib/gkeyfile.c (g_key_file_parse_value_as_integer): Don't + interpret leading zeros as octal. The specification requires + %f parsing, and %f doesn't allow octal. + * tests/keyfile-test.c: Add some more tests. * glib/gkeyfile.c (g_key_file_get_keys): Return keys in diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 5fbe34b..cab6839 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,5 +1,9 @@ 2005-01-20 Matthias Clasen + * glib/gkeyfile.c (g_key_file_parse_value_as_integer): Don't + interpret leading zeros as octal. The specification requires + %f parsing, and %f doesn't allow octal. + * tests/keyfile-test.c: Add some more tests. * glib/gkeyfile.c (g_key_file_get_keys): Return keys in diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 5fbe34b..cab6839 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,9 @@ 2005-01-20 Matthias Clasen + * glib/gkeyfile.c (g_key_file_parse_value_as_integer): Don't + interpret leading zeros as octal. The specification requires + %f parsing, and %f doesn't allow octal. + * tests/keyfile-test.c: Add some more tests. * glib/gkeyfile.c (g_key_file_get_keys): Return keys in diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c index 85e50ef..a2e4289 100644 --- a/glib/gkeyfile.c +++ b/glib/gkeyfile.c @@ -3163,7 +3163,7 @@ g_key_file_parse_value_as_integer (GKeyFile *key_file, gchar *end_of_valid_int; gint int_value = 0; - int_value = strtol (value, &end_of_valid_int, 0); + int_value = strtol (value, &end_of_valid_int, 10); if (*end_of_valid_int != '\0') g_set_error (error, G_KEY_FILE_ERROR, diff --git a/tests/keyfile-test.c b/tests/keyfile-test.c index 1556839..c097ff3 100644 --- a/tests/keyfile-test.c +++ b/tests/keyfile-test.c @@ -109,6 +109,27 @@ check_boolean_value (GKeyFile *keyfile, } static void +check_integer_value (GKeyFile *keyfile, + const gchar *group, + const gchar *key, + gint expected) +{ + GError *error = NULL; + gint value; + + value = g_key_file_get_integer (keyfile, group, key, &error); + check_no_error (&error); + + if (value != expected) + { + g_print ("Group %s key %s: " + "expected integer value %d, actual value %d\n", + group, key, expected, value); + exit (1); + } +} + +static void check_name (const gchar *what, const gchar *value, const gchar *expected, @@ -343,7 +364,49 @@ test_boolean (void) check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE); } -int +/* check parsing of integer values */ +static void +test_integer (void) +{ + GKeyFile *keyfile; + GError *error = NULL; + + const gchar *data = + "[valid]\n" + "key1=0\n" + "key2=1\n" + "key3=-1\n" + "key4=2324431\n" + "key5=-2324431\n" + "key6=000111\n" + "[invalid]\n" + "key1=0xffff\n" + "key2=0.5\n" + "key3=1e37\n" + "key4=ten\n"; + + keyfile = load_data (data); + check_integer_value (keyfile, "valid", "key1", 0); + check_integer_value (keyfile, "valid", "key2", 1); + check_integer_value (keyfile, "valid", "key3", -1); + check_integer_value (keyfile, "valid", "key4", 2324431); + check_integer_value (keyfile, "valid", "key5", -2324431); + check_integer_value (keyfile, "valid", "key6", 111); + + g_key_file_get_integer (keyfile, "invalid", "key1", &error); + check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE); + + g_key_file_get_integer (keyfile, "invalid", "key2", &error); + check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE); + + g_key_file_get_integer (keyfile, "invalid", "key3", &error); + check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE); + + g_key_file_get_integer (keyfile, "invalid", "key4", &error); + check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE); +} + +int main (int argc, char *argv[]) { test_line_ends (); @@ -351,6 +414,7 @@ main (int argc, char *argv[]) test_listing (); test_string (); test_boolean (); + test_integer (); return 0; } -- 2.7.4