[gnumeric] xml: improve robustness.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xml: improve robustness.
- Date: Wed, 4 Aug 2010 15:12:28 +0000 (UTC)
commit 12a6744f4c17df967769c9a635b444704ce04964
Author: Morten Welinder <terra gnome org>
Date: Wed Aug 4 11:11:08 2010 -0400
xml: improve robustness.
ChangeLog | 12 ++++++++++++
NEWS | 3 +++
src/cell.c | 9 +++++++--
src/mstyle.c | 16 ++++++++--------
src/xml-sax-read.c | 28 +++++++++++++++++++---------
5 files changed, 49 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5e76f83..0455ae7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-08-04 Morten Welinder <terra gnome org>
+
+ * src/cell.c (gnm_cell_set_array_formula): Improve preconditions.
+ (gnm_cell_cleanout): Add precondition.
+
+ * src/mstyle.c (gnm_style_set_font_italic,
+ gnm_style_set_font_bold, gnm_style_set_font_strike,
+ gnm_style_set_wrap_text, gnm_style_set_shrink_to_fit,
+ gnm_style_set_contents_locked, gnm_style_set_contents_hidden):
+ Normalize gboolean.
+ (gnm_style_set_font_strike): Fix argument type.
+
2010-08-04 Jean Brefort <jean brefort normalesup org>
* src/dependent.c (gnm_cell_eval_content): force columns span recalculation
diff --git a/NEWS b/NEWS
index 389d578..8188610 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,9 @@ Jean:
* Force column span recalculation when switching between number and
error. [#625994]
+Morten:
+ * Survive malformed xml files.
+
--------------------------------------------------------------------------
Gnumeric 1.10.8
diff --git a/src/cell.c b/src/cell.c
index 049d497..1590f04 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -49,6 +49,8 @@
void
gnm_cell_cleanout (GnmCell *cell)
{
+ g_return_if_fail (cell != NULL);
+
/* A cell can have either an expression or entered text */
if (gnm_cell_has_expr (cell)) {
/* Clipboard cells, e.g., are not attached to a sheet. */
@@ -288,11 +290,14 @@ gnm_cell_set_array_formula (Sheet *sheet,
GnmCell *corner;
GnmExprTop const *wrapper;
- g_return_if_fail (num_cols > 0);
- g_return_if_fail (num_rows > 0);
+ g_return_if_fail (sheet != NULL);
g_return_if_fail (texpr != NULL);
+ g_return_if_fail (0 <= col_a);
g_return_if_fail (col_a <= col_b);
+ g_return_if_fail (col_b < gnm_sheet_get_max_cols (sheet));
+ g_return_if_fail (0 <= row_a);
g_return_if_fail (row_a <= row_b);
+ g_return_if_fail (row_b < gnm_sheet_get_max_rows (sheet));
corner = sheet_cell_fetch (sheet, col_a, row_a);
g_return_if_fail (corner != NULL);
diff --git a/src/mstyle.c b/src/mstyle.c
index 3b34584..4f26076 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -1189,7 +1189,7 @@ gnm_style_set_font_bold (GnmStyle *style, gboolean bold)
elem_changed (style, MSTYLE_FONT_BOLD);
elem_set (style, MSTYLE_FONT_BOLD);
- style->font_detail.bold = bold;
+ style->font_detail.bold = !!bold;
gnm_style_clear_font (style);
gnm_style_clear_pango (style);
}
@@ -1210,7 +1210,7 @@ gnm_style_set_font_italic (GnmStyle *style, gboolean italic)
elem_changed (style, MSTYLE_FONT_ITALIC);
elem_set (style, MSTYLE_FONT_ITALIC);
- style->font_detail.italic = italic;
+ style->font_detail.italic = !!italic;
gnm_style_clear_font (style);
gnm_style_clear_pango (style);
}
@@ -1244,13 +1244,13 @@ gnm_style_get_font_uline (GnmStyle const *style)
}
void
-gnm_style_set_font_strike (GnmStyle *style, gboolean const strikethrough)
+gnm_style_set_font_strike (GnmStyle *style, gboolean strikethrough)
{
g_return_if_fail (style != NULL);
elem_changed (style, MSTYLE_FONT_STRIKETHROUGH);
elem_set (style, MSTYLE_FONT_STRIKETHROUGH);
- style->font_detail.strikethrough = strikethrough;
+ style->font_detail.strikethrough = !!strikethrough;
gnm_style_clear_pango (style);
}
@@ -1445,7 +1445,7 @@ gnm_style_set_wrap_text (GnmStyle *style, gboolean f)
elem_changed (style, MSTYLE_WRAP_TEXT);
elem_set (style, MSTYLE_WRAP_TEXT);
- style->wrap_text = f;
+ style->wrap_text = !!f;
}
gboolean
@@ -1482,7 +1482,7 @@ gnm_style_set_shrink_to_fit (GnmStyle *style, gboolean f)
elem_changed (style, MSTYLE_SHRINK_TO_FIT);
elem_set (style, MSTYLE_SHRINK_TO_FIT);
- style->shrink_to_fit = f;
+ style->shrink_to_fit = !!f;
}
gboolean
@@ -1501,7 +1501,7 @@ gnm_style_set_contents_locked (GnmStyle *style, gboolean f)
elem_changed (style, MSTYLE_CONTENTS_LOCKED);
elem_set (style, MSTYLE_CONTENTS_LOCKED);
- style->contents_locked = f;
+ style->contents_locked = !!f;
}
gboolean
@@ -1520,7 +1520,7 @@ gnm_style_set_contents_hidden (GnmStyle *style, gboolean f)
elem_changed (style, MSTYLE_CONTENTS_HIDDEN);
elem_set (style, MSTYLE_CONTENTS_HIDDEN);
- style->contents_hidden = f;
+ style->contents_hidden = !!f;
}
gboolean
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index c2b8389..97cc071 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -1162,10 +1162,11 @@ static void
xml_sax_selection (GsfXMLIn *xin, xmlChar const **attrs)
{
XMLSaxParseState *state = (XMLSaxParseState *)xin->user_state;
+ Sheet *sheet = state->sheet;
int col = -1, row = -1;
- sv_selection_reset (sheet_get_view (state->sheet, state->wb_view));
+ sv_selection_reset (sheet_get_view (sheet, state->wb_view));
for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
if (gnm_xml_attr_int (attrs, "CursorCol", &col)) ;
@@ -1173,10 +1174,16 @@ xml_sax_selection (GsfXMLIn *xin, xmlChar const **attrs)
else
unknown_attr (xin, attrs);
- g_return_if_fail (col >= 0);
- g_return_if_fail (row >= 0);
- g_return_if_fail (state->cell.col < 0);
- g_return_if_fail (state->cell.row < 0);
+ XML_CHECK (state->cell.col < 0);
+ XML_CHECK (state->cell.row < 0);
+
+ /* Default in case of error. */
+ state->cell.col = 0;
+ state->cell.row = 0;
+
+ XML_CHECK (col >= 0 && col < gnm_sheet_get_max_cols (sheet));
+ XML_CHECK (row >= 0 && row < gnm_sheet_get_max_rows (sheet));
+
state->cell.col = col;
state->cell.row = row;
}
@@ -1431,16 +1438,19 @@ xml_sax_style_font (GsfXMLIn *xin, xmlChar const **attrs)
g_return_if_fail (state->style != NULL);
for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
- if (gnm_xml_attr_double (attrs, "Unit", &size_pts))
- gnm_style_set_font_size (state->style, size_pts);
- else if (gnm_xml_attr_int (attrs, "Bold", &val))
+ if (gnm_xml_attr_double (attrs, "Unit", &size_pts)) {
+ if (!(size_pts >= 1.0))
+ xml_sax_barf (G_STRFUNC, "size_pts >= 1");
+ else
+ gnm_style_set_font_size (state->style, size_pts);
+ } else if (gnm_xml_attr_int (attrs, "Bold", &val))
gnm_style_set_font_bold (state->style, val);
else if (gnm_xml_attr_int (attrs, "Italic", &val))
gnm_style_set_font_italic (state->style, val);
else if (gnm_xml_attr_int (attrs, "Underline", &val))
gnm_style_set_font_uline (state->style, (GnmUnderline)val);
else if (gnm_xml_attr_int (attrs, "StrikeThrough", &val))
- gnm_style_set_font_strike (state->style, val ? TRUE : FALSE);
+ gnm_style_set_font_strike (state->style, val);
else if (gnm_xml_attr_int (attrs, "Script", &val)) {
if (val == 0)
gnm_style_set_font_script (state->style, GO_FONT_SCRIPT_STANDARD);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]