summaryrefslogtreecommitdiff
path: root/utf8.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2019-04-05 16:21:51 -0600
committerKarl Williamson <khw@cpan.org>2019-04-05 17:14:11 -0600
commit45671da298df5eb367286a19e0b03796307902c9 (patch)
tree20ecb5c05880393718de5d8d7a7f920cdc3cb7d7 /utf8.h
parent9d5c52dfb15d17a41d63829964fdda6657054a13 (diff)
downloadperl-45671da298df5eb367286a19e0b03796307902c9.tar.gz
PATCH: [perl #133896] Assertion failure
This was due to UTF8_SAFE_SKIP(s, e) not allowing s to be as large as e, and there are legitimate cases where it can be. This commit hardens the macro so that it never reads above e-1, returning 0 if it otherwise would be required to. The assertion is changed to 's <= e'.
Diffstat (limited to 'utf8.h')
-rw-r--r--utf8.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/utf8.h b/utf8.h
index 7773007e49..d0b8742d5a 100644
--- a/utf8.h
+++ b/utf8.h
@@ -501,13 +501,16 @@ only) byte is pointed to by C<s>.
/*
=for apidoc Am|STRLEN|UTF8_SAFE_SKIP|char* s|char* e
-returns the number of bytes in the UTF-8 encoded character whose first (perhaps
-only) byte is pointed to by C<s>. But never returns beyond C<e>.
+returns 0 if S<C<s E<gt>= e>>; otherwise returns the number of bytes in the
+UTF-8 encoded character whose first byte is pointed to by C<s>. But it never
+returns beyond C<e>. On DEBUGGING builds, it asserts that S<C<s E<lt>= e>>.
=cut
*/
-#define UTF8_SAFE_SKIP(s, e) (__ASSERT_((e) > (s)) \
- MIN(((e) - (s)), UTF8_SKIP(s)))
+#define UTF8_SAFE_SKIP(s, e) (__ASSERT_((e) >= (s)) \
+ ((e) - (s)) <= 0 \
+ ? 0 \
+ : MIN(((e) - (s)), UTF8_SKIP(s)))
/* Most code that says 'UNI_' really means the native value for code points up
* through 255 */