[gcalctool] Add g_return_if_fail to all public methods
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Add g_return_if_fail to all public methods
- Date: Wed, 20 Apr 2011 01:23:30 +0000 (UTC)
commit 81e37fa5404d489618b5b8e143072c49a622e268
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Apr 20 11:23:23 2011 +1000
Add g_return_if_fail to all public methods
src/currency-manager.c | 9 +++-
src/currency.c | 6 ++
src/math-buttons.c | 5 ++
src/math-converter.c | 11 ++++
src/math-equation.c | 144 +++++++++++++++++++++++++++++++++++++++++------
src/math-variables.c | 10 +++
src/math-window.c | 10 +++-
src/unit-category.c | 16 +++++
src/unit-manager.c | 20 +++++++
src/unit.c | 17 ++++++
10 files changed, 227 insertions(+), 21 deletions(-)
---
diff --git a/src/currency-manager.c b/src/currency-manager.c
index 272b9a9..66b6c92 100644
--- a/src/currency-manager.c
+++ b/src/currency-manager.c
@@ -134,13 +134,17 @@ currency_manager_get_default(void)
GList *
currency_manager_get_currencies(CurrencyManager *manager)
{
- return manager->priv->currencies;
+ g_return_val_if_fail(manager != NULL, NULL);
+ return manager->priv->currencies;
}
Currency *
currency_manager_get_currency(CurrencyManager *manager, const gchar *name)
{
+ g_return_val_if_fail(manager != NULL, NULL);
+ g_return_val_if_fail(name != NULL, NULL);
+
GList *link;
for (link = manager->priv->currencies; link; link = link->next) {
Currency *c = link->data;
@@ -566,6 +570,9 @@ currency_manager_get_value(CurrencyManager *manager, const gchar *currency)
gchar *path;
Currency *c;
+ g_return_val_if_fail(manager != NULL, NULL);
+ g_return_val_if_fail(currency != NULL, NULL);
+
/* Update rates if necessary */
path = get_imf_rate_filepath();
if (!downloading_imf_rates && file_needs_update(path, 60 * 60 * 24 * 7)) {
diff --git a/src/currency.c b/src/currency.c
index 859082d..ea81761 100644
--- a/src/currency.c
+++ b/src/currency.c
@@ -44,6 +44,7 @@ currency_new(const gchar *name,
const gchar *
currency_get_name(Currency *currency)
{
+ g_return_val_if_fail (currency != NULL, NULL);
return currency->priv->name;
}
@@ -51,6 +52,7 @@ currency_get_name(Currency *currency)
const gchar *
currency_get_display_name(Currency *currency)
{
+ g_return_val_if_fail (currency != NULL, NULL);
return currency->priv->display_name;
}
@@ -58,6 +60,7 @@ currency_get_display_name(Currency *currency)
const gchar *
currency_get_symbol(Currency *currency)
{
+ g_return_val_if_fail (currency != NULL, NULL);
return currency->priv->symbol;
}
@@ -65,6 +68,8 @@ currency_get_symbol(Currency *currency)
void
currency_set_value(Currency *currency, MPNumber *value)
{
+ g_return_if_fail (currency != NULL);
+ g_return_if_fail (value != NULL);
mp_set_from_mp (value, ¤cy->priv->value);
}
@@ -72,6 +77,7 @@ currency_set_value(Currency *currency, MPNumber *value)
const MPNumber *
currency_get_value(Currency *currency)
{
+ g_return_val_if_fail (currency != NULL, NULL);
return ¤cy->priv->value;
}
diff --git a/src/math-buttons.c b/src/math-buttons.c
index d09b6db..86f7c1e 100644
--- a/src/math-buttons.c
+++ b/src/math-buttons.c
@@ -749,6 +749,8 @@ void
math_buttons_set_mode(MathButtons *buttons, ButtonMode mode)
{
ButtonMode old_mode;
+
+ g_return_if_fail(buttons != NULL);
if (buttons->priv->mode == mode)
return;
@@ -791,6 +793,8 @@ math_buttons_get_mode(MathButtons *buttons)
void
math_buttons_set_programming_base(MathButtons *buttons, gint base)
{
+ g_return_if_fail(buttons != NULL);
+
if (base == buttons->priv->programming_base)
return;
@@ -805,6 +809,7 @@ math_buttons_set_programming_base(MathButtons *buttons, gint base)
gint
math_buttons_get_programming_base(MathButtons *buttons)
{
+ g_return_val_if_fail(buttons != NULL, 10);
return buttons->priv->programming_base;
}
diff --git a/src/math-converter.c b/src/math-converter.c
index 4eb2cbc..46e3601 100644
--- a/src/math-converter.c
+++ b/src/math-converter.c
@@ -152,6 +152,8 @@ update_from_model(MathConverter *converter)
void
math_converter_set_category(MathConverter *converter, const gchar *category)
{
+ g_return_if_fail (converter != NULL);
+
if (category == NULL && converter->priv->category == NULL)
return;
if (category != NULL && converter->priv->category != NULL && strcmp(category, converter->priv->category) == 0)
@@ -167,6 +169,7 @@ math_converter_set_category(MathConverter *converter, const gchar *category)
const gchar *
math_converter_get_category(MathConverter *converter)
{
+ g_return_val_if_fail (converter != NULL, NULL);
return converter->priv->category;
}
@@ -220,6 +223,10 @@ math_converter_set_conversion(MathConverter *converter, /*const gchar *category,
Unit *ua;
Unit *ub;
+ g_return_if_fail (converter != NULL);
+ g_return_if_fail (unit_a != NULL);
+ g_return_if_fail (unit_b != NULL);
+
ua = unit_manager_get_unit_by_name(unit_manager_get_default(), unit_a);
ub = unit_manager_get_unit_by_name(unit_manager_get_default(), unit_b);
if (!ua || !ub)
@@ -248,6 +255,10 @@ math_converter_get_conversion(MathConverter *converter, Unit **from_unit, Unit *
{
GtkTreeIter from_iter, to_iter;
+ g_return_if_fail (converter != NULL);
+ g_return_if_fail (from_unit != NULL);
+ g_return_if_fail (to_unit != NULL);
+
gtk_combo_box_get_active_iter(GTK_COMBO_BOX(converter->priv->from_combo), &from_iter);
gtk_combo_box_get_active_iter(GTK_COMBO_BOX(converter->priv->to_combo), &to_iter);
diff --git a/src/math-equation.c b/src/math-equation.c
index a7ffaca..f0c0975 100644
--- a/src/math-equation.c
+++ b/src/math-equation.c
@@ -282,7 +282,7 @@ reformat_separators(MathEquation *equation)
static void
-reformat_display(MathEquation *equation, gint old_base)
+reformat_display(MathEquation *equation)
{
/* Change ans */
reformat_ans(equation);
@@ -415,6 +415,8 @@ math_equation_copy(MathEquation *equation)
{
GtkTextIter start, end;
gchar *text;
+
+ g_return_if_fail(equation != NULL);
if (!gtk_text_buffer_get_selection_bounds(GTK_TEXT_BUFFER(equation), &start, &end))
gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(equation), &start, &end);
@@ -437,6 +439,7 @@ on_paste(GtkClipboard *clipboard, const gchar *text, gpointer data)
void
math_equation_paste(MathEquation *equation)
{
+ g_return_if_fail(equation != NULL);
gtk_clipboard_request_text(gtk_clipboard_get(GDK_NONE), on_paste, equation);
}
@@ -446,7 +449,9 @@ math_equation_undo(MathEquation *equation)
{
GList *link;
MathEquationState *state;
-
+
+ g_return_if_fail(equation != NULL);
+
if (!equation->priv->undo_stack) {
math_equation_set_status(equation,
/* Error shown when trying to undo with no undo history */
@@ -472,6 +477,8 @@ math_equation_redo(MathEquation *equation)
GList *link;
MathEquationState *state;
+ g_return_if_fail(equation != NULL);
+
if (!equation->priv->redo_stack) {
math_equation_set_status(equation,
/* Error shown when trying to redo with no redo history */
@@ -494,6 +501,9 @@ math_equation_redo(MathEquation *equation)
gunichar
math_equation_get_digit_text(MathEquation *equation, guint digit)
{
+ g_return_val_if_fail(equation != NULL, '?');
+ g_return_val_if_fail(digit < 16, '?');
+
return equation->priv->digits[digit];
}
@@ -501,11 +511,12 @@ math_equation_get_digit_text(MathEquation *equation, guint digit)
void
math_equation_set_accuracy(MathEquation *equation, gint accuracy)
{
- gint old_accuracy = mp_serializer_get_accuracy(equation->priv->serializer);
- if (old_accuracy == accuracy)
+ g_return_if_fail(equation != NULL);
+
+ if (mp_serializer_get_accuracy(equation->priv->serializer) == accuracy)
return;
mp_serializer_set_accuracy(equation->priv->serializer, accuracy);
- reformat_display(equation, mp_serializer_get_base(equation->priv->serializer));
+ reformat_display(equation);
g_object_notify(G_OBJECT(equation), "accuracy");
}
@@ -513,6 +524,8 @@ math_equation_set_accuracy(MathEquation *equation, gint accuracy)
gint
math_equation_get_accuracy(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, 0);
+
return mp_serializer_get_accuracy(equation->priv->serializer);
}
@@ -520,11 +533,13 @@ math_equation_get_accuracy(MathEquation *equation)
void
math_equation_set_show_thousands_separators(MathEquation *equation, gboolean visible)
{
- gboolean old_visible = mp_serializer_get_show_thousands_separators(equation->priv->serializer);
- if (old_visible == visible)
+ g_return_if_fail(equation != NULL);
+
+ if (mp_serializer_get_show_thousands_separators(equation->priv->serializer) == visible)
return;
+
mp_serializer_set_show_thousands_separators(equation->priv->serializer, visible);
- reformat_display(equation, mp_serializer_get_base(equation->priv->serializer));
+ reformat_display(equation);
g_object_notify(G_OBJECT(equation), "show-thousands-separators");
}
@@ -532,6 +547,7 @@ math_equation_set_show_thousands_separators(MathEquation *equation, gboolean vis
gboolean
math_equation_get_show_thousands_separators(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, FALSE);
return mp_serializer_get_show_thousands_separators(equation->priv->serializer);
}
@@ -539,11 +555,13 @@ math_equation_get_show_thousands_separators(MathEquation *equation)
void
math_equation_set_show_trailing_zeroes(MathEquation *equation, gboolean visible)
{
- gboolean old_visible = mp_serializer_get_show_trailing_zeroes(equation->priv->serializer);
- if (old_visible == visible)
+ g_return_if_fail(equation != NULL);
+
+ if (mp_serializer_get_show_trailing_zeroes(equation->priv->serializer) == visible)
return;
+
mp_serializer_set_show_trailing_zeroes(equation->priv->serializer, visible);
- reformat_display(equation, mp_serializer_get_base(equation->priv->serializer));
+ reformat_display(equation);
g_object_notify(G_OBJECT(equation), "show-trailing-zeroes");
}
@@ -551,6 +569,7 @@ math_equation_set_show_trailing_zeroes(MathEquation *equation, gboolean visible)
gboolean
math_equation_get_show_trailing_zeroes(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, FALSE);
return mp_serializer_get_show_trailing_zeroes(equation->priv->serializer);
}
@@ -558,12 +577,13 @@ math_equation_get_show_trailing_zeroes(MathEquation *equation)
void
math_equation_set_number_format(MathEquation *equation, MpDisplayFormat format)
{
- MpDisplayFormat old_format = mp_serializer_get_number_format(equation->priv->serializer);
- if (old_format == format)
+ g_return_if_fail(equation != NULL);
+
+ if (mp_serializer_get_number_format(equation->priv->serializer) == format)
return;
mp_serializer_set_number_format(equation->priv->serializer, format);
- reformat_display(equation, mp_serializer_get_base(equation->priv->serializer));
+ reformat_display(equation);
g_object_notify(G_OBJECT(equation), "number-format");
}
@@ -571,6 +591,7 @@ math_equation_set_number_format(MathEquation *equation, MpDisplayFormat format)
MpDisplayFormat
math_equation_get_number_format(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, MP_DISPLAY_FORMAT_AUTOMATIC);
return mp_serializer_get_number_format(equation->priv->serializer);
}
@@ -578,13 +599,13 @@ math_equation_get_number_format(MathEquation *equation)
void
math_equation_set_base(MathEquation *equation, gint base)
{
- gint old_base = mp_serializer_get_base(equation->priv->serializer);
+ g_return_if_fail(equation != NULL);
- if (old_base == base)
+ if (mp_serializer_get_base(equation->priv->serializer) == base)
return;
mp_serializer_set_base(equation->priv->serializer, base);
- reformat_display(equation, old_base);
+ reformat_display(equation);
g_object_notify(G_OBJECT(equation), "base");
}
@@ -592,6 +613,7 @@ math_equation_set_base(MathEquation *equation, gint base)
gint
math_equation_get_base(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, 10);
return mp_serializer_get_base(equation->priv->serializer);
}
@@ -599,8 +621,11 @@ math_equation_get_base(MathEquation *equation)
void
math_equation_set_word_size(MathEquation *equation, gint word_size)
{
+ g_return_if_fail(equation != NULL);
+
if (equation->priv->word_size == word_size)
return;
+
equation->priv->word_size = word_size;
g_object_notify(G_OBJECT(equation), "word-size");
}
@@ -609,6 +634,7 @@ math_equation_set_word_size(MathEquation *equation, gint word_size)
gint
math_equation_get_word_size(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, 64);
return equation->priv->word_size;
}
@@ -616,8 +642,11 @@ math_equation_get_word_size(MathEquation *equation)
void
math_equation_set_angle_units(MathEquation *equation, MPAngleUnit angle_units)
{
+ g_return_if_fail(equation != NULL);
+
if (equation->priv->angle_units == angle_units)
return;
+
equation->priv->angle_units = angle_units;
g_object_notify(G_OBJECT(equation), "angle-units");
}
@@ -626,6 +655,7 @@ math_equation_set_angle_units(MathEquation *equation, MPAngleUnit angle_units)
MPAngleUnit
math_equation_get_angle_units(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, MP_DEGREES);
return equation->priv->angle_units;
}
@@ -633,6 +663,9 @@ math_equation_get_angle_units(MathEquation *equation)
void
math_equation_set_source_currency(MathEquation *equation, const gchar *currency)
{
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(currency != NULL);
+
if (strcmp(equation->priv->source_currency, currency) == 0)
return;
g_free(equation->priv->source_currency);
@@ -644,6 +677,7 @@ math_equation_set_source_currency(MathEquation *equation, const gchar *currency)
const gchar *
math_equation_get_source_currency(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, NULL);
return equation->priv->source_currency;
}
@@ -651,6 +685,9 @@ math_equation_get_source_currency(MathEquation *equation)
void
math_equation_set_target_currency(MathEquation *equation, const gchar *currency)
{
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(currency != NULL);
+
if (strcmp(equation->priv->target_currency, currency) == 0)
return;
g_free(equation->priv->target_currency);
@@ -662,6 +699,7 @@ math_equation_set_target_currency(MathEquation *equation, const gchar *currency)
const gchar *
math_equation_get_target_currency(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, NULL);
return equation->priv->target_currency;
}
@@ -669,8 +707,12 @@ math_equation_get_target_currency(MathEquation *equation)
void
math_equation_set_source_units(MathEquation *equation, const gchar *units)
{
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(units != NULL);
+
if (strcmp(equation->priv->source_units, units) == 0)
return;
+
g_free(equation->priv->source_units);
equation->priv->source_units = g_strdup(units);
g_object_notify(G_OBJECT(equation), "source-units");
@@ -679,6 +721,7 @@ math_equation_set_source_units(MathEquation *equation, const gchar *units)
const gchar *
math_equation_get_source_units(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, NULL);
return equation->priv->source_units;
}
@@ -686,8 +729,12 @@ math_equation_get_source_units(MathEquation *equation)
void
math_equation_set_target_units(MathEquation *equation, const gchar *units)
{
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(units != NULL);
+
if (strcmp(equation->priv->target_units, units) == 0)
return;
+
g_free(equation->priv->target_units);
equation->priv->target_units = g_strdup(units);
g_object_notify(G_OBJECT(equation), "target-units");
@@ -697,6 +744,7 @@ math_equation_set_target_units(MathEquation *equation, const gchar *units)
const gchar *
math_equation_get_target_units(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, NULL);
return equation->priv->target_units;
}
@@ -704,6 +752,9 @@ math_equation_get_target_units(MathEquation *equation)
void
math_equation_set_status(MathEquation *equation, const gchar *status)
{
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(status != NULL);
+
if (strcmp(equation->priv->state.status, status) == 0)
return;
@@ -716,6 +767,7 @@ math_equation_set_status(MathEquation *equation, const gchar *status)
const gchar *
math_equation_get_status(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, NULL);
return equation->priv->state.status;
}
@@ -723,6 +775,7 @@ math_equation_get_status(MathEquation *equation)
gboolean
math_equation_is_empty(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, FALSE);
return gtk_text_buffer_get_char_count(GTK_TEXT_BUFFER(equation)) == 0;
}
@@ -732,6 +785,8 @@ math_equation_is_result(MathEquation *equation)
{
char *text;
gboolean result;
+
+ g_return_val_if_fail(equation != NULL, FALSE);
text = math_equation_get_equation(equation);
result = strcmp(text, "ans") == 0;
@@ -746,6 +801,8 @@ math_equation_get_display(MathEquation *equation)
{
GtkTextIter start, end;
+ g_return_val_if_fail(equation != NULL, NULL);
+
gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(equation), &start, &end);
return gtk_text_buffer_get_text(GTK_TEXT_BUFFER(equation), &start, &end, FALSE);
}
@@ -760,6 +817,8 @@ math_equation_get_equation(MathEquation *equation)
const gchar *read_iter;
gboolean last_is_digit = FALSE;
+ g_return_val_if_fail(equation != NULL, NULL);
+
text = math_equation_get_display(equation);
eq_text = g_string_sized_new(strlen(text));
@@ -809,6 +868,9 @@ math_equation_get_number(MathEquation *equation, MPNumber *z)
gchar *text;
gboolean result;
+ g_return_val_if_fail(equation != NULL, FALSE);
+ g_return_val_if_fail(z != NULL, FALSE);
+
text = math_equation_get_equation(equation);
result = !mp_serializer_from_string(equation->priv->serializer, text, z);
g_free(text);
@@ -820,6 +882,7 @@ math_equation_get_number(MathEquation *equation, MPNumber *z)
MpSerializer *
math_equation_get_serializer(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, NULL);
return equation->priv->serializer;
}
@@ -827,6 +890,8 @@ math_equation_get_serializer(MathEquation *equation)
void
math_equation_set_number_mode(MathEquation *equation, NumberMode mode)
{
+ g_return_if_fail(equation != NULL);
+
if (equation->priv->number_mode == mode)
return;
@@ -840,6 +905,7 @@ math_equation_set_number_mode(MathEquation *equation, NumberMode mode)
NumberMode
math_equation_get_number_mode(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, NORMAL);
return equation->priv->number_mode;
}
@@ -847,6 +913,7 @@ math_equation_get_number_mode(MathEquation *equation)
gboolean
math_equation_in_solve(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, FALSE);
return equation->priv->in_solve;
}
@@ -854,6 +921,7 @@ math_equation_in_solve(MathEquation *equation)
const MPNumber *
math_equation_get_answer(MathEquation *equation)
{
+ g_return_val_if_fail(equation != NULL, FALSE);
return &equation->priv->state.ans;
}
@@ -862,6 +930,9 @@ void
math_equation_store(MathEquation *equation, const gchar *name)
{
MPNumber t;
+
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(name != NULL);
if (!math_equation_get_number(equation, &t))
math_equation_set_status(equation, _("No sane value to store"));
@@ -873,14 +944,17 @@ math_equation_store(MathEquation *equation, const gchar *name)
void
math_equation_recall(MathEquation *equation, const gchar *name)
{
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(name != NULL);
math_equation_insert(equation, name);
}
void
math_equation_set(MathEquation *equation, const gchar *text)
-
{
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(text != NULL);
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(equation), text, -1);
clear_ans(equation, FALSE);
}
@@ -892,6 +966,9 @@ math_equation_set_number(MathEquation *equation, const MPNumber *x)
char *text;
GtkTextIter start, end;
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(x != NULL);
+
/* Show the number in the user chosen format */
text = mp_serializer_to_string(equation->priv->serializer, x);
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(equation), text, -1);
@@ -910,6 +987,9 @@ math_equation_set_number(MathEquation *equation, const MPNumber *x)
void
math_equation_insert(MathEquation *equation, const gchar *text)
{
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(text != NULL);
+
/* Replace ** with ^ (not on all keyboards) */
if (!gtk_text_buffer_get_has_selection(GTK_TEXT_BUFFER(equation)) &&
strcmp(text, "Ã?") == 0 && equation->priv->state.entered_multiply) {
@@ -944,6 +1024,9 @@ math_equation_insert_digit(MathEquation *equation, guint digit)
static const char *subscript_digits[] = {"â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??", NULL};
static const char *superscript_digits[] = {"�", "¹", "²", "³", "�", "�", "�", "�", "�", "�", NULL};
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(digit < 16);
+
if (equation->priv->number_mode == NORMAL || digit >= 10) {
gchar buffer[7];
gint len;
@@ -963,6 +1046,9 @@ math_equation_insert_numeric_point(MathEquation *equation)
{
gchar buffer[7];
gint len;
+
+ g_return_if_fail(equation != NULL);
+
len = g_unichar_to_utf8(mp_serializer_get_radix(equation->priv->serializer), buffer);
buffer[len] = '\0';
math_equation_insert(equation, buffer);
@@ -973,6 +1059,10 @@ void
math_equation_insert_number(MathEquation *equation, const MPNumber *x)
{
char *text;
+
+ g_return_if_fail(equation != NULL);
+ g_return_if_fail(x != NULL);
+
text = mp_serializer_to_string(equation->priv->serializer, x);
math_equation_insert(equation, text);
g_free(text);
@@ -982,6 +1072,7 @@ math_equation_insert_number(MathEquation *equation, const MPNumber *x)
void
math_equation_insert_exponent(MathEquation *equation)
{
+ g_return_if_fail(equation != NULL);
math_equation_insert(equation, "Ã?10");
math_equation_set_number_mode(equation, SUPERSCRIPT);
}
@@ -990,6 +1081,7 @@ math_equation_insert_exponent(MathEquation *equation)
void
math_equation_insert_subtract(MathEquation *equation)
{
+ g_return_if_fail(equation != NULL);
if (equation->priv->number_mode == SUPERSCRIPT && equation->priv->can_super_minus) {
math_equation_insert(equation, "â?»");
equation->priv->can_super_minus = FALSE;
@@ -1209,6 +1301,8 @@ math_equation_solve(MathEquation *equation)
{
GError *error = NULL;
+ g_return_if_fail(equation != NULL);
+
// FIXME: should replace calculation or give error message
if (equation->priv->in_solve)
return;
@@ -1279,6 +1373,8 @@ math_equation_factorize(MathEquation *equation)
MPNumber x;
GError *error = NULL;
+ g_return_if_fail(equation != NULL);
+
// FIXME: should replace calculation or give error message
if (equation->priv->in_solve)
return;
@@ -1305,7 +1401,9 @@ void
math_equation_delete(MathEquation *equation)
{
gint cursor;
- GtkTextIter start, end;
+ GtkTextIter start, end;
+
+ g_return_if_fail(equation != NULL);
g_object_get(G_OBJECT(equation), "cursor-position", &cursor, NULL);
if (cursor >= gtk_text_buffer_get_char_count(GTK_TEXT_BUFFER(equation)))
@@ -1320,6 +1418,8 @@ math_equation_delete(MathEquation *equation)
void
math_equation_backspace(MathEquation *equation)
{
+ g_return_if_fail(equation != NULL);
+
/* Can't delete empty display */
if (math_equation_is_empty(equation))
return;
@@ -1337,6 +1437,8 @@ math_equation_backspace(MathEquation *equation)
void
math_equation_clear(MathEquation *equation)
{
+ g_return_if_fail(equation != NULL);
+
math_equation_set_number_mode(equation, NORMAL);
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(equation), "", -1);
clear_ans(equation, FALSE);
@@ -1348,6 +1450,8 @@ math_equation_shift(MathEquation *equation, gint count)
{
MPNumber z;
+ g_return_if_fail(equation != NULL);
+
if (!math_equation_get_number(equation, &z)) {
math_equation_set_status(equation,
/* This message is displayed in the status bar when a bit
@@ -1368,6 +1472,8 @@ math_equation_toggle_bit(MathEquation *equation, guint bit)
guint64 bits;
gboolean result;
+ g_return_if_fail(equation != NULL);
+
result = math_equation_get_number(equation, &x);
if (result) {
MPNumber max;
diff --git a/src/math-variables.c b/src/math-variables.c
index 4ed9bb1..c8fcd24 100644
--- a/src/math-variables.c
+++ b/src/math-variables.c
@@ -108,6 +108,8 @@ math_variables_get_names(MathVariables *variables)
gint i = 0;
gchar **names;
+ g_return_val_if_fail(variables != NULL, NULL);
+
names = g_malloc0(sizeof(gchar *) * (g_hash_table_size(variables->priv->registers) + 1));
g_hash_table_iter_init(&iter, variables->priv->registers);
@@ -128,6 +130,10 @@ math_variables_set(MathVariables *variables, const char *name, const MPNumber *v
{
MPNumber *t;
+ g_return_if_fail(variables != NULL);
+ g_return_if_fail(name != NULL);
+ g_return_if_fail(value != NULL);
+
t = g_malloc(sizeof(MPNumber));
mp_set_from_mp(value, t);
g_hash_table_insert(variables->priv->registers, g_strdup(name), t);
@@ -138,6 +144,8 @@ math_variables_set(MathVariables *variables, const char *name, const MPNumber *v
MPNumber *
math_variables_get(MathVariables *variables, const char *name)
{
+ g_return_val_if_fail(variables != NULL, NULL);
+ g_return_val_if_fail(name != NULL, NULL);
return g_hash_table_lookup(variables->priv->registers, name);
}
@@ -145,6 +153,8 @@ math_variables_get(MathVariables *variables, const char *name)
void
math_variables_delete(MathVariables *variables, const char *name)
{
+ g_return_if_fail(variables != NULL);
+ g_return_if_fail(name != NULL);
g_hash_table_remove(variables->priv->registers, name);
registers_save(variables);
}
diff --git a/src/math-window.c b/src/math-window.c
index 07984df..59a427f 100644
--- a/src/math-window.c
+++ b/src/math-window.c
@@ -52,13 +52,15 @@ math_window_new(MathEquation *equation)
GtkWidget *
math_window_get_menu_bar(MathWindow *window)
{
- return window->priv->menu_bar;
+ g_return_val_if_fail(window != NULL, NULL);
+ return window->priv->menu_bar;
}
MathEquation *
math_window_get_equation(MathWindow *window)
{
+ g_return_val_if_fail(window != NULL, NULL);
return window->priv->equation;
}
@@ -66,6 +68,7 @@ math_window_get_equation(MathWindow *window)
MathDisplay *
math_window_get_display(MathWindow *window)
{
+ g_return_val_if_fail(window != NULL, NULL);
return window->priv->display;
}
@@ -73,6 +76,7 @@ math_window_get_display(MathWindow *window)
MathButtons *
math_window_get_buttons(MathWindow *window)
{
+ g_return_val_if_fail(window != NULL, NULL);
return window->priv->buttons;
}
@@ -82,6 +86,10 @@ math_window_critical_error(MathWindow *window, const gchar *title, const gchar *
{
GtkWidget *dialog;
+ g_return_if_fail(window != NULL);
+ g_return_if_fail(title != NULL);
+ g_return_if_fail(contents != NULL);
+
dialog = gtk_message_dialog_new(NULL, 0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_NONE,
diff --git a/src/unit-category.c b/src/unit-category.c
index 503b0ab..56a90e2 100644
--- a/src/unit-category.c
+++ b/src/unit-category.c
@@ -36,6 +36,7 @@ unit_category_new(const gchar *name, const gchar *display_name)
const gchar *
unit_category_get_name(UnitCategory *category)
{
+ g_return_val_if_fail (category != NULL, NULL);
return category->priv->name;
}
@@ -43,6 +44,7 @@ unit_category_get_name(UnitCategory *category)
const gchar *
unit_category_get_display_name(UnitCategory *category)
{
+ g_return_val_if_fail (category != NULL, NULL);
return category->priv->display_name;
}
@@ -50,6 +52,8 @@ unit_category_get_display_name(UnitCategory *category)
void
unit_category_add_unit(UnitCategory *category, Unit *unit)
{
+ g_return_if_fail (category != NULL);
+ g_return_if_fail (unit != NULL);
category->priv->units = g_list_append(category->priv->units, g_object_ref(unit));
}
@@ -59,6 +63,9 @@ unit_category_get_unit_by_name(UnitCategory *category, const gchar *name)
{
GList *iter;
+ g_return_val_if_fail (category != NULL, NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+
for (iter = category->priv->units; iter; iter = iter->next)
{
Unit *unit = iter->data;
@@ -75,6 +82,9 @@ unit_category_get_unit_by_symbol(UnitCategory *category, const gchar *symbol)
{
GList *iter;
+ g_return_val_if_fail (category != NULL, NULL);
+ g_return_val_if_fail (symbol != NULL, NULL);
+
for (iter = category->priv->units; iter; iter = iter->next) {
Unit *unit = iter->data;
if (unit_matches_symbol(unit, symbol))
@@ -88,6 +98,7 @@ unit_category_get_unit_by_symbol(UnitCategory *category, const gchar *symbol)
const GList *
unit_category_get_units(UnitCategory *category)
{
+ g_return_val_if_fail (category != NULL, NULL);
return category->priv->units;
}
@@ -97,6 +108,11 @@ unit_category_convert(UnitCategory *category, const MPNumber *x, Unit *x_units,
{
MPNumber t;
+ g_return_val_if_fail (category != NULL, FALSE);
+ g_return_val_if_fail (x_units != NULL, FALSE);
+ g_return_val_if_fail (z_units != NULL, FALSE);
+ g_return_val_if_fail (z != NULL, FALSE);
+
if (!unit_convert_from(x_units, x, &t))
return FALSE;
if (!unit_convert_to(z_units, &t, z))
diff --git a/src/unit-manager.c b/src/unit-manager.c
index c046418..a1a9dc1 100644
--- a/src/unit-manager.c
+++ b/src/unit-manager.c
@@ -151,7 +151,11 @@ unit_manager_add_category(UnitManager *manager, const gchar *name, const gchar *
{
UnitCategory *category;
+ g_return_val_if_fail(manager != NULL, NULL);
+ g_return_val_if_fail(name != NULL, NULL);
+ g_return_val_if_fail(display_name != NULL, NULL);
g_return_val_if_fail(unit_manager_get_category(manager, name) == NULL, NULL);
+
category = unit_category_new(name, display_name);
manager->priv->categories = g_list_append(manager->priv->categories, category);
@@ -162,6 +166,7 @@ unit_manager_add_category(UnitManager *manager, const gchar *name, const gchar *
const GList *
unit_manager_get_categories(UnitManager *manager)
{
+ g_return_val_if_fail(manager != NULL, NULL);
return manager->priv->categories;
}
@@ -170,6 +175,9 @@ UnitCategory *
unit_manager_get_category(UnitManager *manager, const gchar *category)
{
GList *iter;
+
+ g_return_val_if_fail(manager != NULL, NULL);
+ g_return_val_if_fail(category != NULL, NULL);
for (iter = manager->priv->categories; iter; iter = iter->next) {
UnitCategory *c = iter->data;
@@ -187,6 +195,9 @@ unit_manager_get_unit_by_name(UnitManager *manager, const gchar *name)
GList *iter;
Unit *u;
+ g_return_val_if_fail(manager != NULL, NULL);
+ g_return_val_if_fail(name != NULL, NULL);
+
for (iter = manager->priv->categories; iter; iter = iter->next) {
UnitCategory *c = iter->data;
u = unit_category_get_unit_by_name(c, name);
@@ -204,6 +215,9 @@ unit_manager_get_unit_by_symbol(UnitManager *manager, const gchar *symbol)
GList *iter;
Unit *u;
+ g_return_val_if_fail(manager != NULL, NULL);
+ g_return_val_if_fail(symbol != NULL, NULL);
+
for (iter = manager->priv->categories; iter; iter = iter->next) {
UnitCategory *c = iter->data;
u = unit_category_get_unit_by_symbol(c, symbol);
@@ -220,6 +234,12 @@ unit_manager_convert_by_symbol(UnitManager *manager, const MPNumber *x, const ch
{
GList *iter;
+ g_return_val_if_fail(manager != NULL, FALSE);
+ g_return_val_if_fail(x != NULL, FALSE);
+ g_return_val_if_fail(x_symbol != NULL, FALSE);
+ g_return_val_if_fail(z_symbol != NULL, FALSE);
+ g_return_val_if_fail(z != NULL, FALSE);
+
for (iter = manager->priv->categories; iter; iter = iter->next) {
UnitCategory *c = iter->data;
Unit *x_units, *z_units;
diff --git a/src/unit.c b/src/unit.c
index 723fd3a..2658883 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -59,6 +59,7 @@ unit_new(const gchar *name,
const gchar *
unit_get_name(Unit *unit)
{
+ g_return_val_if_fail (unit != NULL, NULL);
return unit->priv->name;
}
@@ -66,6 +67,7 @@ unit_get_name(Unit *unit)
const gchar *
unit_get_display_name(Unit *unit)
{
+ g_return_val_if_fail (unit != NULL, NULL);
return unit->priv->display_name;
}
@@ -75,6 +77,9 @@ unit_matches_symbol(Unit *unit, const gchar *symbol)
{
GList *iter;
+ g_return_val_if_fail (unit != NULL, FALSE);
+ g_return_val_if_fail (symbol != NULL, FALSE);
+
for (iter = unit->priv->symbols; iter; iter = iter->next) {
gchar *s = iter->data;
if (strcmp(s, symbol) == 0)
@@ -88,6 +93,7 @@ unit_matches_symbol(Unit *unit, const gchar *symbol)
const GList *
unit_get_symbols(Unit *unit)
{
+ g_return_val_if_fail (unit != NULL, NULL);
return unit->priv->symbols;
}
@@ -133,6 +139,10 @@ solve_function(const gchar *function, const MPNumber *x, MPNumber *z)
gboolean
unit_convert_from(Unit *unit, const MPNumber *x, MPNumber *z)
{
+ g_return_val_if_fail(unit != NULL, FALSE);
+ g_return_val_if_fail(x != NULL, FALSE);
+ g_return_val_if_fail(x != NULL, FALSE);
+
if (unit->priv->from_function)
return solve_function(unit->priv->from_function, x, z);
else {
@@ -151,6 +161,10 @@ unit_convert_from(Unit *unit, const MPNumber *x, MPNumber *z)
gboolean
unit_convert_to(Unit *unit, const MPNumber *x, MPNumber *z)
{
+ g_return_val_if_fail(unit != NULL, FALSE);
+ g_return_val_if_fail(x != NULL, FALSE);
+ g_return_val_if_fail(x != NULL, FALSE);
+
if (unit->priv->from_function)
return solve_function(unit->priv->to_function, x, z);
else {
@@ -171,6 +185,9 @@ unit_format(Unit *unit, MPNumber *x)
{
gchar *number_text, *text;
+ g_return_val_if_fail(unit != NULL, FALSE);
+ g_return_val_if_fail(x != NULL, FALSE);
+
number_text = mp_serializer_to_string(unit->priv->serializer, x);
text = g_strdup_printf(unit->priv->format, number_text);
g_free(number_text);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]