From eda3af554666ecd16bb135c446f0a68ce608e128 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 8 May 2006 16:48:47 +0000 Subject: [PATCH] Add some tests for invalid floating point numbers. 2006-05-08 Matthias Clasen * tests/keyfile-test.c (test_number): Add some tests for invalid floating point numbers. --- ChangeLog | 6 ++++++ ChangeLog.pre-2-12 | 6 ++++++ glib/gkeyfile.c | 2 +- tests/keyfile-test.c | 18 +++++++++++++++++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea1088e6b..3f89f436e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2006-05-08 Matthias Clasen + * tests/keyfile-test.c (test_number): Add some tests for + invalid floating point numbers. + + * glib/gkeyfile.c (g_key_file_parse_value_as_double): Return + an error for the empty string. (#339105, Morten Welinder) + * glib/gscanner.c (g_scanner_config_template): Make const, noticed by Kjartan Maraas. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index ea1088e6b..3f89f436e 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,5 +1,11 @@ 2006-05-08 Matthias Clasen + * tests/keyfile-test.c (test_number): Add some tests for + invalid floating point numbers. + + * glib/gkeyfile.c (g_key_file_parse_value_as_double): Return + an error for the empty string. (#339105, Morten Welinder) + * glib/gscanner.c (g_scanner_config_template): Make const, noticed by Kjartan Maraas. diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c index 4c60b95d5..b14da798c 100644 --- a/glib/gkeyfile.c +++ b/glib/gkeyfile.c @@ -3471,7 +3471,7 @@ g_key_file_parse_value_as_double (GKeyFile *key_file, double_value = g_ascii_strtod (value, &end_of_valid_d); - if (*end_of_valid_d != '\0') + if (*end_of_valid_d != '\0' || end_of_valid_d == value) g_set_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE, _("Value '%s' cannot be interpreted as a float number."), value); diff --git a/tests/keyfile-test.c b/tests/keyfile-test.c index df51d14f2..fc704bb24 100644 --- a/tests/keyfile-test.c +++ b/tests/keyfile-test.c @@ -697,7 +697,11 @@ test_number (void) "key1=0xffff\n" "key2=0.5\n" "key3=1e37\n" - "key4=ten\n"; + "key4=ten\n" + "key5=\n" + "key6=1.0.0\n" + "key7=2x2\n" + "key8=abc\n"; keyfile = load_data (data, 0); @@ -723,6 +727,18 @@ test_number (void) g_key_file_get_integer (keyfile, "invalid", "key4", &error); check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE); + g_key_file_get_double (keyfile, "invalid", "key5", &error); + check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE); + + g_key_file_get_double (keyfile, "invalid", "key6", &error); + check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE); + + g_key_file_get_double (keyfile, "invalid", "key7", &error); + check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE); + + g_key_file_get_double (keyfile, "invalid", "key8", &error); + check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE); + g_key_file_free (keyfile); } -- 2.34.1