diff --git a/ChangeLog b/ChangeLog index ada61af4c..e15c6d824 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-12-25 Vladimir Serbinenko + + * include/grub/unicode.h (grub_unicode_compact_range): Replace end with + len and make it smaller. All users updated. + * util/import_unicode.py: Put length and not end character. + Check length. + 2011-12-25 Vladimir Serbinenko Make better Unicode-compliant and unify some UTF-8 code pathes. diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c index 6ddd91827..314a1be66 100644 --- a/grub-core/normal/charset.c +++ b/grub-core/normal/charset.c @@ -367,9 +367,9 @@ unpack_join (void) grub_errno = GRUB_ERR_NONE; return; } - for (cur = grub_unicode_compact; cur->end; cur++) - for (i = cur->start; i <= cur->end - && i < GRUB_UNICODE_MAX_CACHED_CHAR; i++) + for (cur = grub_unicode_compact; cur->len; cur++) + for (i = cur->start; i < cur->start + (unsigned) cur->len + && i < GRUB_UNICODE_MAX_CACHED_CHAR; i++) join_types[i] = cur->join_type; } @@ -387,9 +387,9 @@ unpack_bidi (void) grub_errno = GRUB_ERR_NONE; return; } - for (cur = grub_unicode_compact; cur->end; cur++) - for (i = cur->start; i <= cur->end - && i < GRUB_UNICODE_MAX_CACHED_CHAR; i++) + for (cur = grub_unicode_compact; cur->len; cur++) + for (i = cur->start; i < cur->start + (unsigned) cur->len + && i < GRUB_UNICODE_MAX_CACHED_CHAR; i++) if (cur->bidi_mirror) bidi_types[i] = cur->bidi_type | 0x80; else @@ -407,8 +407,8 @@ get_bidi_type (grub_uint32_t c) if (bidi_types && c < GRUB_UNICODE_MAX_CACHED_CHAR) return bidi_types[c] & 0x7f; - for (cur = grub_unicode_compact; cur->end; cur++) - if (cur->start <= c && c <= cur->end) + for (cur = grub_unicode_compact; cur->len; cur++) + if (cur->start <= c && c < cur->start + (unsigned) cur->len) return cur->bidi_type; return GRUB_BIDI_TYPE_L; @@ -425,8 +425,8 @@ get_join_type (grub_uint32_t c) if (join_types && c < GRUB_UNICODE_MAX_CACHED_CHAR) return join_types[c]; - for (cur = grub_unicode_compact; cur->end; cur++) - if (cur->start <= c && c <= cur->end) + for (cur = grub_unicode_compact; cur->len; cur++) + if (cur->start <= c && c < cur->start + (unsigned) cur->len) return cur->join_type; return GRUB_JOIN_TYPE_NONJOINING; @@ -443,8 +443,8 @@ is_mirrored (grub_uint32_t c) if (bidi_types && c < GRUB_UNICODE_MAX_CACHED_CHAR) return !!(bidi_types[c] & 0x80); - for (cur = grub_unicode_compact; cur->end; cur++) - if (cur->start <= c && c <= cur->end) + for (cur = grub_unicode_compact; cur->len; cur++) + if (cur->start <= c && c < cur->start + (unsigned) cur->len) return cur->bidi_mirror; return 0; @@ -461,8 +461,8 @@ grub_unicode_get_comb_type (grub_uint32_t c) unsigned i; comb_types = grub_zalloc (GRUB_UNICODE_MAX_CACHED_CHAR); if (comb_types) - for (cur = grub_unicode_compact; cur->end; cur++) - for (i = cur->start; i <= cur->end + for (cur = grub_unicode_compact; cur->len; cur++) + for (i = cur->start; i < cur->start + (unsigned) cur->len && i < GRUB_UNICODE_MAX_CACHED_CHAR; i++) comb_types[i] = cur->comb_type; else @@ -472,8 +472,8 @@ grub_unicode_get_comb_type (grub_uint32_t c) if (comb_types && c < GRUB_UNICODE_MAX_CACHED_CHAR) return comb_types[c]; - for (cur = grub_unicode_compact; cur->end; cur++) - if (cur->start <= c && c <= cur->end) + for (cur = grub_unicode_compact; cur->len; cur++) + if (cur->start <= c && c < cur->start + (unsigned) cur->len) return cur->comb_type; return GRUB_UNICODE_COMB_NONE; diff --git a/include/grub/unicode.h b/include/grub/unicode.h index 64769258a..ebdfbddbf 100644 --- a/include/grub/unicode.h +++ b/include/grub/unicode.h @@ -31,12 +31,12 @@ struct grub_unicode_bidi_pair struct grub_unicode_compact_range { - grub_uint32_t start:21; - grub_uint32_t end:21; - grub_uint8_t bidi_type:5; - grub_uint8_t comb_type; - grub_uint8_t bidi_mirror:1; - grub_uint8_t join_type:3; + unsigned start:21; + unsigned len:9; + unsigned bidi_type:5; + unsigned comb_type:8; + unsigned bidi_mirror:1; + unsigned join_type:3; } __attribute__ ((packed)); /* Old-style Arabic shaping. Used for "visual UTF-8" and diff --git a/util/import_unicode.py b/util/import_unicode.py index 8d17e7ef6..ec3db0842 100644 --- a/util/import_unicode.py +++ b/util/import_unicode.py @@ -130,9 +130,13 @@ for line in infile: if begincode != -2 and (lastbiditype != "L" or lastcombtype != 0 or \ lastmirrortype): outfile.write (("{0x%x, 0x%x, GRUB_BIDI_TYPE_%s, %d, %d, GRUB_JOIN_TYPE_%s},\n" \ - % (begincode, lastcode, lastbiditype, \ + % (begincode, lastcode - begincode + 1, \ + lastbiditype, \ lastcombtype, lastmirrortype, \ lastjoin))) + if lastcode - begincode + 1 >= 0x200: + print "Too long range" + raise begincode = curcode lastcode = curcode lastjoin = curjoin