From 4bf3f7f51a5781079324311246e996aeb8975186 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 3 Feb 2013 10:22:32 -0800 Subject: [PATCH] - client: fix copy_element_contents() to remove assumption that the end tag is on a line by itself. (this broke things if gui_urls.xml didn't end with a CRLF). --- lib/parse.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/parse.cpp b/lib/parse.cpp index 824975a717..381358c821 100644 --- a/lib/parse.cpp +++ b/lib/parse.cpp @@ -229,14 +229,23 @@ int copy_element_contents(FILE* in, const char* end_tag, char* p, int len) { } int copy_element_contents(FILE* in, const char* end_tag, string& str) { - char buf[256]; + int c; + size_t end_tag_len = strlen(end_tag); + size_t n = 0; str = ""; - while (fgets(buf, 256, in)) { - if (strstr(buf, end_tag)) { - return 0; + while (1) { + c = fgetc(in); + if (c == EOF) break; + if (n >= end_tag_len) { + const char* p = str.c_str() + n - end_tag_len; + if (!strcmp(p, end_tag)) { + str.erase(n-end_tag_len, end_tag_len); + return 0; + } } - str += buf; + str += c; + n++; } return ERR_XML_PARSE; }