eina: fix for escapable charachters not getting escaped if it comes after '\t' or... 85/136685/2
authorPrasoon Singh <prasoon.16@samsung.com>
Tue, 9 May 2017 17:37:12 +0000 (10:37 -0700)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Mon, 3 Jul 2017 04:45:12 +0000 (04:45 +0000)
Summary:
Escaping is not happening whenever any escapable characters is coming after
'\t' or '\n'. It will also fix invalid read of 1 byte which happens for string where
last charachter is '\t' or '\n' like "eina\t".

Test Plan:
Take a string like "eina\t ". Observe space which is followed by tab is not getting
escaped.

Signed-off-by: Prasoon Singh <prasoon.16@samsung.com>
Reviewers: shilpasingh, rajeshps, govi, cedric

Reviewed By: shilpasingh

Subscribers: cedric, jpeg

Differential Revision: https://phab.enlightenment.org/D4847

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Change-Id: Ie2cd495024390b3fdb5dba81a660680d6b2fa9d1

AUTHORS
src/lib/eina/eina_str.c
src/tests/eina/eina_test_str.c

diff --git a/AUTHORS b/AUTHORS
index eab2011..781468b 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -53,6 +53,8 @@ ChunEon Park (Hermet) <hermet@hermet.pe.kr>
 Rajeev Ranjan (Rajeev) <rajeev.r@samsung.com> <rajeev.jnnce@gmail.com>
 Subodh Kumar <s7158.kumar@samsung.com>
 Michelle Legrand <legrand.michelle@outlook.com>
+Shilpa Singh <shilpa.singh@samsung.com> <shilpasingh.o@gmail.com>
+Prasoon Singh <prasoonsingh16@gmail.com>
 
 Eet
 ---
index c3d9c4c..bdf1417 100644 (file)
@@ -630,24 +630,27 @@ eina_str_escape(const char *str)
            {
              *d = '\\';
              d++;
+             *d = *s;
              break;
            }
          case '\n':
            {
              *d = '\\'; d++;
-             *d = 'n'; d++;
-             s++;
+             *d = 'n';
              break;
            }
          case '\t':
            {
              *d = '\\'; d++;
-             *d = 't'; d++;
-             s++;
+             *d = 't';
+             break;
+           }
+         default:
+           {
+             *d = *s;
              break;
            }
         }
-        *d = *s;
      }
    *d = 0;
    return s2;
index 8233dd8..d4ef920 100644 (file)
    free(str);
    free(ret);
 
+   str = malloc(sizeof(char) * 4);
+   strcpy(str, "a\t ");
+   ret = eina_str_escape(str);
+   fail_if(!eina_streq(ret, "a\\t\\ "));
+   free(str);
+   free(ret);
+
    eina_shutdown();
 }
 END_TEST