浏览代码

Merge topic 'utf8-decode-empty'

0bd6009a0c cm_utf8: Fail on empty input range

Acked-by: Kitware Robot <[email protected]>
Merge-request: !6885
Brad King 3 年之前
父节点
当前提交
e9500bd770
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      Source/cm_utf8.c

+ 5 - 0
Source/cm_utf8.c

@@ -42,6 +42,11 @@ static unsigned int const cm_utf8_min[7] = {
 const char* cm_utf8_decode_character(const char* first, const char* last,
 const char* cm_utf8_decode_character(const char* first, const char* last,
                                      unsigned int* pc)
                                      unsigned int* pc)
 {
 {
+  /* We need at least one byte.  */
+  if (first == last) {
+    return 0;
+  }
+
   /* Count leading ones in the first byte.  */
   /* Count leading ones in the first byte.  */
   unsigned char c = (unsigned char)*first++;
   unsigned char c = (unsigned char)*first++;
   unsigned char const ones = cm_utf8_ones[c];
   unsigned char const ones = cm_utf8_ones[c];