eina: always terminate the string with a '\0'.

This commit is contained in:
Cedric BAIL 2015-11-23 11:57:04 -08:00
parent b3a917563c
commit 8616e22c7e
2 changed files with 7 additions and 4 deletions

View File

@ -729,15 +729,16 @@ eina_memdup(unsigned char *mem, size_t size, Eina_Bool terminate)
} }
EAPI char * 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; char *dest;
int i = 0, j = 0, k = 0; int i = 0, j = 0, k = 0;
unsigned char inarr[3], outarr[4];
if (!src) return NULL; 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; if (!dest) return NULL;
while (len--) while (len--)
@ -774,5 +775,7 @@ eina_str_base64_encode(unsigned char const *src, unsigned int len)
} }
dest[k] = '\0';
return dest; return dest;
} }

View File

@ -393,7 +393,7 @@ EAPI char *eina_strftime(const char *format, const struct tm *tm);
* *
* @since 1.17.0 * @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" #include "eina_inline_str.x"