Commit e18ca715 authored by Lev Walkin's avatar Lev Walkin

fixed indexing bug; also rearranging and made more comments

parent 263b0280
...@@ -32,13 +32,20 @@ asn_TYPE_descriptor_t asn_DEF_UTF8String = { ...@@ -32,13 +32,20 @@ asn_TYPE_descriptor_t asn_DEF_UTF8String = {
0 /* No specifics */ 0 /* No specifics */
}; };
static int _UTF8String_h1[16] = { /*
1, 1, 1, 1, 1, 1, 1, 1, /* 0x0 ... 0x7 */ * This is the table of length expectations.
0, 0, 0, 0, 2, 2, 3, -1 * The second half of this table is only applicable to the long sequentes.
}; */
static int _UTF8String_h2[16] = { static int UTF8String_ht[2][16] = {
4, 4, 4, 4, 4, 4, 4, 4, /* 0xF0 .. 0xF7 */ { /* 0x0 ... 0x7 */
5, 5, 5, 5, 6, 6, -1, -1 /* 0000..0111 */
1, 1, 1, 1, 1, 1, 1, 1,
/* 1000..1011(0), 1100..1101(2), 1110(3), 1111(-1) */
0, 0, 0, 0, 2, 2, 3, -1 },
{ /* 0xF0 .. 0xF7 */
/* 11110000..11110111 */
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 6, 6, -1, -1 }
}; };
int int
...@@ -63,7 +70,7 @@ UTF8String_length(const UTF8String_t *st, const char *opt_type_name, ...@@ -63,7 +70,7 @@ UTF8String_length(const UTF8String_t *st, const char *opt_type_name,
for(want = 0; buf < end; buf++) { for(want = 0; buf < end; buf++) {
uint8_t ch = *buf; uint8_t ch = *buf;
int w = _UTF8String_h1[ch >> 4]; int w = UTF8String_ht[0][ch >> 4];
if(want) { /* Continuation expected */ if(want) { /* Continuation expected */
if(w) { if(w) {
_ASN_ERRLOG(app_errlog, app_key, _ASN_ERRLOG(app_errlog, app_key,
...@@ -78,11 +85,11 @@ UTF8String_length(const UTF8String_t *st, const char *opt_type_name, ...@@ -78,11 +85,11 @@ UTF8String_length(const UTF8String_t *st, const char *opt_type_name,
} else { } else {
switch(w) { switch(w) {
case -1: /* Long UTF-8 */ case -1: /* Long UTF-8 */
w = _UTF8String_h2[ch & 0xF0]; w = UTF8String_ht[1][ch & 0x0F];
if(w != -1) if(w != -1)
break; break;
/* Fall through */ /* Fall through */
case 0: case 0: /* But we should want something! */
_ASN_ERRLOG(app_errlog, app_key, _ASN_ERRLOG(app_errlog, app_key,
"%s: UTF-8 expectation" "%s: UTF-8 expectation"
"failed at byte %d (%s:%d)", "failed at byte %d (%s:%d)",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment