summaryrefslogtreecommitdiff
path: root/enc
diff options
context:
space:
mode:
Diffstat (limited to 'enc')
-rw-r--r--enc/utf_32be.c18
-rw-r--r--enc/utf_32le.c18
2 files changed, 30 insertions, 6 deletions
diff --git a/enc/utf_32be.c b/enc/utf_32be.c
index 995c9d8ed5..17841e52a4 100644
--- a/enc/utf_32be.c
+++ b/enc/utf_32be.c
@@ -30,11 +30,23 @@
#include "regenc.h"
#include "iso_8859.h"
+static OnigCodePoint utf32be_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc);
static int
-utf32be_mbc_enc_len(const UChar* p ARG_UNUSED, const OnigUChar* e ARG_UNUSED,
- OnigEncoding enc ARG_UNUSED)
+utf32be_mbc_enc_len(const UChar* p ARG_UNUSED, const OnigUChar* e,
+ OnigEncoding enc)
{
- return 4;
+ if (e < p) {
+ return ONIGENC_CONSTRUCT_MBCLEN_INVALID();
+ }
+ else if (e-p < 4) {
+ return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(4-(int)(e-p));
+ }
+ else {
+ OnigCodePoint c = utf32be_mbc_to_code(p, e, enc);
+ if (!UNICODE_VALID_CODEPOINT_P(c))
+ return ONIGENC_CONSTRUCT_MBCLEN_INVALID();
+ return ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(4);
+ }
}
static int
diff --git a/enc/utf_32le.c b/enc/utf_32le.c
index e255f0e246..18b798f102 100644
--- a/enc/utf_32le.c
+++ b/enc/utf_32le.c
@@ -30,11 +30,23 @@
#include "regenc.h"
#include "iso_8859.h"
+static OnigCodePoint utf32le_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc);
static int
-utf32le_mbc_enc_len(const UChar* p ARG_UNUSED, const OnigUChar* e ARG_UNUSED,
- OnigEncoding enc ARG_UNUSED)
+utf32le_mbc_enc_len(const UChar* p ARG_UNUSED, const OnigUChar* e,
+ OnigEncoding enc)
{
- return 4;
+ if (e < p) {
+ return ONIGENC_CONSTRUCT_MBCLEN_INVALID();
+ }
+ else if (e-p < 4) {
+ return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(4-(int)(e-p));
+ }
+ else {
+ OnigCodePoint c = utf32le_mbc_to_code(p, e, enc);
+ if (!UNICODE_VALID_CODEPOINT_P(c))
+ return ONIGENC_CONSTRUCT_MBCLEN_INVALID();
+ return ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(4);
+ }
}
static int