Commit 3947e2ce authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg
Browse files

protect against NULL. (parse_criteria) : fall back on a string if we don't


2001-06-15  Jody Goldberg <jgoldberg@home.com>

	* fn-database.c (criteria_test_*) : protect against NULL.
	(parse_criteria) : fall back on a string if we don't match.
parent 90113e73
......@@ -28,6 +28,8 @@ typedef struct {
gboolean
criteria_test_equal (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) == value_get_as_float (y))
return 1;
......@@ -43,6 +45,8 @@ criteria_test_equal (Value const *x, Value const *y)
gboolean
criteria_test_unequal (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) != value_get_as_float (y))
return 1;
......@@ -58,6 +62,8 @@ criteria_test_unequal (Value const *x, Value const *y)
gboolean
criteria_test_less (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) < value_get_as_float (y))
return 1;
......@@ -70,6 +76,8 @@ criteria_test_less (Value const *x, Value const *y)
gboolean
criteria_test_greater (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) > value_get_as_float (y))
return 1;
......@@ -82,6 +90,8 @@ criteria_test_greater (Value const *x, Value const *y)
gboolean
criteria_test_less_or_equal (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) <= value_get_as_float (y))
return 1;
......@@ -94,6 +104,8 @@ criteria_test_less_or_equal (Value const *x, Value const *y)
gboolean
criteria_test_greater_or_equal (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) >= value_get_as_float (y))
return 1;
......@@ -208,6 +220,8 @@ parse_criteria (char const *criteria, criteria_test_fun_t *fun,
}
*test_value = format_match (criteria + len, NULL, NULL);
if (*test_value == NULL)
*test_value = value_new_string (criteria + len);
}
......
2001-06-15 Jody Goldberg <jgoldberg@home.com>
* fn-database.c (criteria_test_*) : protect against NULL.
(parse_criteria) : fall back on a string if we don't match.
2001-06-07 Jody Goldberg <jgoldberg@home.com>
* fn-database.c (parse_criteria) : Use a decent parser. Good idea
......
......@@ -28,6 +28,8 @@ typedef struct {
gboolean
criteria_test_equal (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) == value_get_as_float (y))
return 1;
......@@ -43,6 +45,8 @@ criteria_test_equal (Value const *x, Value const *y)
gboolean
criteria_test_unequal (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) != value_get_as_float (y))
return 1;
......@@ -58,6 +62,8 @@ criteria_test_unequal (Value const *x, Value const *y)
gboolean
criteria_test_less (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) < value_get_as_float (y))
return 1;
......@@ -70,6 +76,8 @@ criteria_test_less (Value const *x, Value const *y)
gboolean
criteria_test_greater (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) > value_get_as_float (y))
return 1;
......@@ -82,6 +90,8 @@ criteria_test_greater (Value const *x, Value const *y)
gboolean
criteria_test_less_or_equal (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) <= value_get_as_float (y))
return 1;
......@@ -94,6 +104,8 @@ criteria_test_less_or_equal (Value const *x, Value const *y)
gboolean
criteria_test_greater_or_equal (Value const *x, Value const *y)
{
g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y != NULL, FALSE);
if (VALUE_IS_NUMBER (x) && VALUE_IS_NUMBER (y))
if (value_get_as_float (x) >= value_get_as_float (y))
return 1;
......@@ -208,6 +220,8 @@ parse_criteria (char const *criteria, criteria_test_fun_t *fun,
}
*test_value = format_match (criteria + len, NULL, NULL);
if (*test_value == NULL)
*test_value = value_new_string (criteria + len);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment