From: Hyoyoung Chang <hyoyoung.chang@samsung.com>
authorraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 19 Feb 2011 15:39:19 +0000 (15:39 +0000)
committerraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 19 Feb 2011 15:39:19 +0000 (15:39 +0000)
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: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@57161 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/elm_label.c

index 5cac1cd..c8a9fe1 100644 (file)
@@ -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;