From c963d75dfdeec11f82e79e727062fbf89afa2c04 Mon Sep 17 00:00:00 2001
From: David Walter Seikel
Date: Sun, 22 Apr 2012 09:19:23 +1000
Subject: Update EFL to latest beta.
---
libraries/eina/src/lib/eina_unicode.c | 55 +++++++++++++++++++++++++++++++----
1 file changed, 50 insertions(+), 5 deletions(-)
(limited to 'libraries/eina/src/lib/eina_unicode.c')
diff --git a/libraries/eina/src/lib/eina_unicode.c b/libraries/eina/src/lib/eina_unicode.c
index 342e3cb..7505906 100644
--- a/libraries/eina/src/lib/eina_unicode.c
+++ b/libraries/eina/src/lib/eina_unicode.c
@@ -15,10 +15,18 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library;
* if not, see .
-
*/
-#include
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "eina_config.h"
+#include "eina_private.h"
+#include
+
+/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
+#include "eina_safety_checks.h"
#include "eina_unicode.h"
/* FIXME: check if sizeof(wchar_t) == sizeof(Eina_Unicode) if so,
@@ -30,6 +38,9 @@ EAPI const Eina_Unicode *EINA_UNICODE_EMPTY_STRING = _EINA_UNICODE_EMPTY_STRING;
EAPI int
eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b)
{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(a, -1);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(b, -1);
+
for (; *a && *a == *b; a++, b++)
;
if (*a == *b)
@@ -45,6 +56,9 @@ eina_unicode_strcpy(Eina_Unicode *dest, const Eina_Unicode *source)
{
Eina_Unicode *ret = dest;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(dest, NULL);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(source, NULL);
+
while (*source)
*dest++ = *source++;
*dest = 0;
@@ -56,6 +70,9 @@ eina_unicode_strncpy(Eina_Unicode *dest, const Eina_Unicode *source, size_t n)
{
Eina_Unicode *ret = dest;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(dest, NULL);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(source, NULL);
+
for ( ; n && *source ; n--)
*dest++ = *source++;
for (; n; n--)
@@ -67,6 +84,9 @@ EAPI size_t
eina_unicode_strlen(const Eina_Unicode *ustr)
{
const Eina_Unicode *end;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ustr, 0);
+
for (end = ustr; *end; end++)
;
return end - ustr;
@@ -77,6 +97,9 @@ eina_unicode_strnlen(const Eina_Unicode *ustr, int n)
{
const Eina_Unicode *end;
const Eina_Unicode *last = ustr + n; /* technically not portable ;-) */
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ustr, 0);
+
for (end = ustr; end < last && *end; end++)
;
return end - ustr;
@@ -90,7 +113,9 @@ eina_unicode_strndup(const Eina_Unicode *text, size_t n)
{
Eina_Unicode *ustr;
- ustr = (Eina_Unicode *) malloc((n + 1) * sizeof(Eina_Unicode));
+ EINA_SAFETY_ON_NULL_RETURN_VAL(text, NULL);
+
+ ustr = malloc((n + 1) * sizeof(Eina_Unicode));
memcpy(ustr, text, n * sizeof(Eina_Unicode));
ustr[n] = 0;
return ustr;
@@ -101,6 +126,8 @@ eina_unicode_strdup(const Eina_Unicode *text)
{
size_t len;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(text, NULL);
+
len = eina_unicode_strlen(text);
return eina_unicode_strndup(text, len);
}
@@ -110,6 +137,9 @@ eina_unicode_strstr(const Eina_Unicode *haystack, const Eina_Unicode *needle)
{
const Eina_Unicode *i, *j;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(haystack, NULL);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(needle, NULL);
+
for (i = haystack; *i; i++)
{
haystack = i; /* set this location as the base position */
@@ -131,6 +161,8 @@ eina_unicode_escape(const Eina_Unicode *str)
Eina_Unicode *s2, *d;
const Eina_Unicode *s;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(str, NULL);
+
s2 = malloc((eina_unicode_strlen(str) * 2) + 1);
if (!s2)
return NULL;
@@ -165,6 +197,9 @@ eina_unicode_utf8_get_next(const char *buf, int *iindex)
Eina_Unicode r;
unsigned char d;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(buf, 0);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(iindex, 0);
+
/* if this char is the null terminator, exit */
if ((d = buf[ind++]) == 0) return 0;
@@ -266,8 +301,12 @@ error:
EAPI Eina_Unicode
eina_unicode_utf8_get_prev(const char *buf, int *iindex)
{
- int r;
- int ind = *iindex;
+ int r, ind;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(buf, 0);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(iindex, 0);
+
+ ind = *iindex;
/* First obtain the codepoint at iindex */
r = eina_unicode_utf8_get_next(buf, &ind);
@@ -292,6 +331,8 @@ eina_unicode_utf8_get_len(const char *buf)
/* returns the number of utf8 characters (not bytes) in the string */
int i = 0, len = 0;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(buf, 0);
+
while (eina_unicode_utf8_get_next(buf, &i))
len++;
@@ -306,6 +347,8 @@ eina_unicode_utf8_to_unicode(const char *utf, int *_len)
int ind;
Eina_Unicode *buf, *uind;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(utf, NULL);
+
len = eina_unicode_utf8_get_len(utf);
if (_len)
*_len = len;
@@ -328,6 +371,8 @@ eina_unicode_unicode_to_utf8(const Eina_Unicode *uni, int *_len)
char *ind;
int ulen, len;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(uni, NULL);
+
ulen = eina_unicode_strlen(uni);
buf = (char *) calloc(ulen + 1, EINA_UNICODE_UTF8_BYTES_PER_CHAR);
--
cgit v1.1