cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=8616e22c7e6e4b7cab48d8f2206c85f43c6063c3

commit 8616e22c7e6e4b7cab48d8f2206c85f43c6063c3
Author: Cedric BAIL <ced...@osg.samsung.com>
Date:   Mon Nov 23 11:57:04 2015 -0800

    eina: always terminate the string with a '\0'.
---
 src/lib/eina/eina_str.c | 9 ++++++---
 src/lib/eina/eina_str.h | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/lib/eina/eina_str.c b/src/lib/eina/eina_str.c
index a77d145..4ff23e9 100644
--- a/src/lib/eina/eina_str.c
+++ b/src/lib/eina/eina_str.c
@@ -729,15 +729,16 @@ eina_memdup(unsigned char *mem, size_t size, Eina_Bool 
terminate)
 }
 
 EAPI char *
-eina_str_base64_encode(unsigned char const *src, unsigned int len)
+eina_str_base64_encode(const unsigned char *src, unsigned int len)
 {
+   unsigned char inarr[3], outarr[4];
    char *dest;
    int i = 0, j = 0, k = 0;
-   unsigned char inarr[3], outarr[4];
 
    if (!src) return NULL;
 
-   dest = malloc(((len + 2) / 3) * 4); // Max length of encoded string.
+   // Max length of encoded string.
+   dest = malloc(sizeof (char) * (((len + 2) / 3) * 4 + 1));
    if (!dest) return NULL;
 
    while (len--)
@@ -774,5 +775,7 @@ eina_str_base64_encode(unsigned char const *src, unsigned 
int len)
 
      }
 
+   dest[k] = '\0';
+
    return dest;
 }
diff --git a/src/lib/eina/eina_str.h b/src/lib/eina/eina_str.h
index 6347dd9..c47ddb4 100644
--- a/src/lib/eina/eina_str.h
+++ b/src/lib/eina/eina_str.h
@@ -393,7 +393,7 @@ EAPI char *eina_strftime(const char *format, const struct 
tm *tm);
  *
  * @since 1.17.0
  */
-EAPI char *eina_str_base64_encode(unsigned char const *src, unsigned int len);
+EAPI char *eina_str_base64_encode(const unsigned char *src, unsigned int len);
 
 #include "eina_inline_str.x"
 

-- 


Reply via email to