summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@heap.zone>2019-04-22 18:53:51 +0200
committerJonathan Schleifer <js@heap.zone>2019-04-22 18:53:51 +0200
commit6808023a1cf99f4853814d3c1206b8ab421578c9 (patch)
tree00862a330a239f59ae4430d238f1390870a13280
parentd2154da632c795439138ab5e2fe2f32c532410e2 (diff)
OFString_UTF8: Improved range checks
-rw-r--r--src/OFMutableString_UTF8.m2
-rw-r--r--src/OFString.m2
-rw-r--r--src/OFString_UTF8.m2
-rw-r--r--src/macros.h4
4 files changed, 5 insertions, 5 deletions
diff --git a/src/OFMutableString_UTF8.m b/src/OFMutableString_UTF8.m
index 2e4957fb..d09b5f91 100644
--- a/src/OFMutableString_UTF8.m
+++ b/src/OFMutableString_UTF8.m
@@ -207,7 +207,7 @@
idx = of_string_utf8_get_position(_s->cString, idx,
_s->cStringLength);
- if (idx > _s->cStringLength)
+ if (idx >= _s->cStringLength)
@throw [OFOutOfRangeException exception];
/* Shortcut if old and new character both are ASCII */
diff --git a/src/OFString.m b/src/OFString.m
index 9d487496..5bcc8a01 100644
--- a/src/OFString.m
+++ b/src/OFString.m
@@ -265,7 +265,7 @@ of_string_utf8_encode(of_unichar_t character, char *buffer)
ssize_t
of_string_utf8_decode(const char *buffer_, size_t length, of_unichar_t *ret)
{
- const uint8_t *buffer = (const uint8_t *)buffer_;
+ const unsigned char *buffer = (const unsigned char *)buffer_;
if (!(*buffer & 0x80)) {
*ret = buffer[0];
diff --git a/src/OFString_UTF8.m b/src/OFString_UTF8.m
index 371a39b9..654c03e5 100644
--- a/src/OFString_UTF8.m
+++ b/src/OFString_UTF8.m
@@ -167,7 +167,7 @@ of_string_utf8_get_position(const char *string, size_t idx, size_t length)
for (size_t i = 0; i <= idx; i++)
if OF_UNLIKELY ((string[i] & 0xC0) == 0x80)
if (++idx > length)
- return OF_NOT_FOUND;
+ @throw [OFInvalidFormatException exception];
return idx;
}
diff --git a/src/macros.h b/src/macros.h
index 2aa0f885..f86781ad 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -93,8 +93,8 @@
# define OF_WEAK_REF(sym) __attribute__((__weakref__(sym)))
#else
# define OF_INLINE inline
-# define OF_LIKELY(cond) cond
-# define OF_UNLIKELY(cond) cond
+# define OF_LIKELY(cond) (cond)
+# define OF_UNLIKELY(cond) (cond)
# define OF_CONST_FUNC
# define OF_NO_RETURN_FUNC
# define OF_WEAK_REF(sym)