X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/87b8d3d415be5a53eaf18318d6ac83758784fcdf..ab4553c3321e7d41330252da08d42a4c3b558110:/src/vikgotoxmltool.c diff --git a/src/vikgotoxmltool.c b/src/vikgotoxmltool.c index 64178c19..2b0f6d51 100644 --- a/src/vikgotoxmltool.c +++ b/src/vikgotoxmltool.c @@ -18,7 +18,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Created by Quy Tonthat */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -27,7 +26,7 @@ #include #include #ifdef HAVE_MATH_H -#include "math.h" +#include #endif #include #include @@ -398,8 +397,8 @@ static gboolean _goto_xml_tool_parse_file_for_latlon(VikGotoTool *self, gchar *filename, struct LatLon *ll) { GMarkupParser xml_parser; - GMarkupParseContext *xml_context; - GError *error; + GMarkupParseContext *xml_context = NULL; + GError *error = NULL; VikGotoXmlToolPrivate *priv = GOTO_XML_TOOL_GET_PRIVATE (self); g_return_val_if_fail(priv != NULL, FALSE); @@ -436,16 +435,28 @@ _goto_xml_tool_parse_file_for_latlon(VikGotoTool *self, gchar *filename, struct gchar buff[BUFSIZ]; size_t nb; - while ((nb = fread (buff, sizeof(gchar), BUFSIZ, file)) > 0) + while (xml_context && + (nb = fread (buff, sizeof(gchar), BUFSIZ, file)) > 0) { if (!g_markup_parse_context_parse(xml_context, buff, nb, &error)) - fprintf(stderr, "%s: parsing error.\n", __FUNCTION__); + { + fprintf(stderr, "%s: parsing error: %s.\n", + __FUNCTION__, error->message); + g_markup_parse_context_free(xml_context); + xml_context = NULL; + } + g_clear_error (&error); } /* cleanup */ - if (!g_markup_parse_context_end_parse(xml_context, &error)) - fprintf(stderr, "%s: errors occurred reading file.\n", __FUNCTION__); + if (xml_context && + !g_markup_parse_context_end_parse(xml_context, &error)) + fprintf(stderr, "%s: errors occurred while reading file: %s.\n", + __FUNCTION__, error->message); + g_clear_error (&error); - g_markup_parse_context_free(xml_context); + if (xml_context) + g_markup_parse_context_free(xml_context); + xml_context = NULL; fclose (file); if (ll != NULL)