From 0c5eff88f17524526b315349be59c317ec131274 Mon Sep 17 00:00:00 2001 From: raster Date: Sat, 19 Feb 2011 15:39:19 +0000 Subject: [PATCH] From: Hyoyoung Chang Subject: [E-devel] [patch] elm_label - bugfix at string manipulation ear Elementary developers. It's a elm_label bugfix. It has two small improvements. 1. Current code can be reference null ptr. - replocater = curlocater + key_len + 1; - while ((*replocater != '=') && (replocater)) ^^^ - replocater++; It should be *replocater, not replocater 2. there are two while loop to find a separate character in string. I changed it from loop to strchr. git-svn-id: https://svn.enlightenment.org/svn/e/trunk/elementary@57161 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/elm_label.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/lib/elm_label.c b/src/lib/elm_label.c index 5cac1cd..c8a9fe1 100644 --- a/src/lib/elm_label.c +++ b/src/lib/elm_label.c @@ -263,27 +263,35 @@ _strbuf_key_value_replace(Eina_Strbuf *srcbuf, const char *key, const char *valu if ((starttag) && (endtag) && (tagtxtlen > key_len)) { + char *eqchar = NULL; repbuf = eina_strbuf_new(); diffbuf = eina_strbuf_new(); eina_strbuf_append_n(repbuf, starttag, tagtxtlen); srcstring = eina_strbuf_string_get(repbuf); curlocater = strstr(srcstring, key); - if (curlocater) + // key=value + // ^ : move to here + eqchar = curlocater + key_len; + if ((curlocater) && (eqchar)) { - replocater = curlocater + key_len + 1; - while ((*replocater != '=') && (replocater)) - replocater++; - - while ((*replocater) && - (*replocater != ' ') && - (*replocater != '>')) - replocater++; - - if ((replocater - curlocater) > (key_len + 1)) + // some case at useless many whitespaces (key =value) + // find the separator(=) position + eqchar = strchr(curlocater + key_len, '='); + if (eqchar) { - replocater--; - eina_strbuf_append_n(diffbuf, curlocater, - replocater-curlocater); + // key=value + // ^ : move to here + replocater = eqchar + 1; + while ((*replocater) && + (*replocater != ' ') && + (*replocater != '>')) + replocater++; + + if ((replocater - curlocater) > key_len) + eina_strbuf_append_n(diffbuf, curlocater, + replocater-curlocater); + else + insertflag = 1; } else insertflag = 1; -- 2.7.4