diff options
author | is <none@none> | 2008-07-02 17:06:30 -0700 |
---|---|---|
committer | is <none@none> | 2008-07-02 17:06:30 -0700 |
commit | 85bb5f1d642e430b889478fb1200b511338085d7 (patch) | |
tree | 87b1fcd9ec47321a1fdb020c5aa607698e1bd13d /usr/src | |
parent | 2321aa36382ca9bc1d3f0437d553acc4e342c81b (diff) | |
download | illumos-joyent-85bb5f1d642e430b889478fb1200b511338085d7.tar.gz |
6622765 geniconvtbl.so cannot parse certain mapping operations resulting EILSEQ from iconv(3C)
6634992 Unicode text prep functions have 'errno' argument -- bad for readability at user-land
6660526 Combining acute accent character (U+0301) cannot be deleted by backspace
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/geniconvtbl/geniconvtbl.c | 397 | ||||
-rw-r--r-- | usr/src/common/unicode/u8_textprep.c | 88 | ||||
-rw-r--r-- | usr/src/uts/common/io/ldterm.c | 443 |
3 files changed, 405 insertions, 523 deletions
diff --git a/usr/src/cmd/geniconvtbl/geniconvtbl.c b/usr/src/cmd/geniconvtbl/geniconvtbl.c index aad552bd30..d0f9d3cdc9 100644 --- a/usr/src/cmd/geniconvtbl/geniconvtbl.c +++ b/usr/src/cmd/geniconvtbl/geniconvtbl.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 1999, 2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -228,7 +227,7 @@ _icv_open(const char *itm) return ((void *)(-1)); } (void) memset(ist->regs, 0, - (sizeof (itm_num_t)) * hdr->reg_num); + (sizeof (itm_num_t)) * hdr->reg_num); } @@ -238,11 +237,8 @@ _icv_open(const char *itm) size_t ileft = 0; unsigned char *op = NULL; size_t oleft = 0; - (void) eval_op_tbl(ist, - ist->itm_hdr->op_init_tbl, - &ip, - &ileft, - &op, &oleft); + (void) eval_op_tbl(ist, ist->itm_hdr->op_init_tbl, &ip, + &ileft, &op, &oleft); } else { op_init_default(ist); } @@ -304,11 +300,10 @@ _icv_iconv( retval = 0; TRACE_MESSAGE('i', ("_icv_iconv(inbuf=%p inbytesleft=%ld " - "outbuf=%p outbytesleft=%ld)\n", - (NULL == inbuf) ? 0 : *inbuf, - (NULL == inbytesleft) ? 0 : *inbytesleft, - (NULL == outbuf) ? 0 : *outbuf, - (NULL == outbytesleft) ? 0 : *outbytesleft)); + "outbuf=%p outbytesleft=%ld)\n", (NULL == inbuf) ? 0 : *inbuf, + (NULL == inbytesleft) ? 0 : *inbytesleft, + (NULL == outbuf) ? 0 : *outbuf, + (NULL == outbytesleft) ? 0 : *outbytesleft)); /* * If (NULL == inbuf || NULL == *inbuf) then this conversion is @@ -317,10 +312,8 @@ _icv_iconv( if ((NULL == inbuf) || (NULL == *inbuf)) { if (0 != hdr->op_reset_tbl.itm_ptr) { ist->direc = ADDR(hdr->direc_init_tbl); - retval = eval_op_tbl(ist, - hdr->op_reset_tbl, - inbuf, inbytesleft, - outbuf, outbytesleft); + retval = eval_op_tbl(ist, hdr->op_reset_tbl, inbuf, + inbytesleft, outbuf, outbytesleft); if ((size_t)(-1) == retval) { return (retval); } @@ -342,9 +335,8 @@ _icv_iconv( map = (char *)(map_hdr + 1); if (1 == map_hdr->default_error) { - retval = map_i_f(ist->direc, - inbuf, inbytesleft, - outbuf, outbytesleft, 0); + retval = map_i_f(ist->direc, inbuf, inbytesleft, + outbuf, outbytesleft, 0); return (retval); } @@ -358,7 +350,7 @@ _icv_iconv( UPDATE_ARGS(); errno = E2BIG; TRACE_MESSAGE('e', ("_icv_iconv: error=%d\n", - errno)); + errno)); return ((size_t)-1); } *(op++) = *(map + *(ip++)); @@ -369,24 +361,20 @@ _icv_iconv( UPDATE_ARGS(); return (0); } else if (ITM_TBL_MAP_INDEX_FIXED == ist->direc->type) { - retval = map_i_f(ist->direc, - inbuf, inbytesleft, - outbuf, outbytesleft, 0); + retval = map_i_f(ist->direc, inbuf, inbytesleft, + outbuf, outbytesleft, 0); return (retval); } else if (ITM_TBL_MAP_HASH == ist->direc->type) { - retval = map_h_l(ist->direc, - inbuf, inbytesleft, - outbuf, outbytesleft, 0); + retval = map_h_l(ist->direc, inbuf, inbytesleft, + outbuf, outbytesleft, 0); return (retval); } else if (ITM_TBL_MAP_DENSE_ENC == ist->direc->type) { - retval = map_d_e_l(ist->direc, - inbuf, inbytesleft, - outbuf, outbytesleft, 0); + retval = map_d_e_l(ist->direc, inbuf, inbytesleft, + outbuf, outbytesleft, 0); return (retval); } else if (ITM_TBL_MAP_LOOKUP == ist->direc->type) { - retval = map_l_f(ist->direc, - inbuf, inbytesleft, - outbuf, outbytesleft, 0); + retval = map_l_f(ist->direc, inbuf, inbytesleft, + outbuf, outbytesleft, 0); return (retval); } @@ -411,8 +399,7 @@ retry_cond_eval: if (0 == ist->default_action.itm_ptr) { errno = EILSEQ; TRACE_MESSAGE('e', - ("_icv_iconv:error=%d\n", - errno)); + ("_icv_iconv:error=%d\n", errno)); return ((size_t)(-1)); } @@ -421,13 +408,12 @@ retry_cond_eval: action = ist->default_action; type = ((itm_tbl_hdr_t *)(ADDR(action)))->type; TRACE_MESSAGE('E', - ("escape seq (default action=%6p, type=%ld) " - "excuting\n", action.itm_ptr, type)); + ("escape seq (default action=%6p, " + "type=%ld) executing\n", + action.itm_ptr, type)); } else if (0 != direc->condition.itm_ptr) { retval = eval_cond_tbl(ist, direc->condition, - inbuf, inbytesleft, - *outbytesleft, - direc); + inbuf, inbytesleft, *outbytesleft, direc); if ((size_t)(0) == retval) { continue; } else if ((size_t)(-1) == retval) { @@ -443,13 +429,12 @@ retry_cond_eval: } TRACE_MESSAGE('a', - ("inbytesleft=%ld; type=%ld:action=%p\n", - *inbytesleft, type, action.itm_ptr)); + ("inbytesleft=%ld; type=%ld:action=%p\n", + *inbytesleft, type, action.itm_ptr)); switch (ITM_TBL_MASK & type) { case ITM_TBL_OP: retval = eval_op_tbl(ist, action, - inbuf, inbytesleft, - outbuf, outbytesleft); + inbuf, inbytesleft, outbuf, outbytesleft); if ((size_t)(-1) == retval) { return (retval); } @@ -461,33 +446,29 @@ retry_cond_eval: switch (type) { case ITM_TBL_MAP_INDEX_FIXED_1_1: case ITM_TBL_MAP_INDEX_FIXED: - retval = map_i_f( - ADDR(action), - inbuf, inbytesleft, - outbuf, outbytesleft, - 1); + retval = map_i_f(ADDR(action), + inbuf, inbytesleft, + outbuf, outbytesleft, 1); break; case ITM_TBL_MAP_HASH: retval = map_h_l(ADDR(action), - inbuf, inbytesleft, - outbuf, outbytesleft, 1); + inbuf, inbytesleft, + outbuf, outbytesleft, 1); break; case ITM_TBL_MAP_DENSE_ENC: retval = map_d_e_l(ADDR(action), - inbuf, inbytesleft, - outbuf, outbytesleft, 1); + inbuf, inbytesleft, + outbuf, outbytesleft, 1); break; case ITM_TBL_MAP_LOOKUP: - retval = map_l_f( - ADDR(action), - inbuf, inbytesleft, - outbuf, outbytesleft, - 1); + retval = map_l_f(ADDR(action), + inbuf, inbytesleft, + outbuf, outbytesleft, 1); break; default: errno = ELIBBAD; TRACE_MESSAGE('e', - ("_icv_iconv:error=%d\n", errno)); + ("_icv_iconv:error=%d\n", errno)); return ((size_t)(-1)); } @@ -498,7 +479,7 @@ retry_cond_eval: default: /* never */ errno = ELIBBAD; TRACE_MESSAGE('e', - ("_icv_iconv:error=%d\n", errno)); + ("_icv_iconv:error=%d\n", errno)); return ((size_t)(-1)); } break; @@ -545,7 +526,7 @@ map_i_f( } if (((j < map_hdr->start.itm_ptr) || - (map_hdr->end.itm_ptr < j)) && + (map_hdr->end.itm_ptr < j)) && (0 < map_hdr->default_error)) { errno = EILSEQ; (*inbuf) = (void*) ((*inbuf) - map_hdr->source_len); @@ -563,11 +544,10 @@ map_i_f( } if ((j < map_hdr->start.itm_ptr) || - (map_hdr->end.itm_ptr < j)) { + (map_hdr->end.itm_ptr < j)) { if (0 == map_hdr->default_error) { p = (((unsigned char *)(map_hdr + 1)) + - (map_hdr->result_len * - (tbl_hdr->number))); + (map_hdr->result_len * (tbl_hdr->number))); for (i = 0; i < map_hdr->result_len; i++) { PUT(*(p + i)); } @@ -580,27 +560,26 @@ map_i_f( } else { char *map_error; map_error = (((char *)(map_hdr + 1)) + - (map_hdr->result_len * - (tbl_hdr->number)) + - (j - map_hdr->start.itm_ptr)); + (map_hdr->result_len * (tbl_hdr->number)) + + (j - map_hdr->start.itm_ptr)); if (0 == map_hdr->default_error) { map_error = (void *) - (map_error + map_hdr->result_len); + (map_error + map_hdr->result_len); } if (((1 == map_hdr->default_error) || (0 < map_hdr->error_num)) && (0 != *(map_error))) { errno = EILSEQ; (*inbuf) = (void *) - ((*inbuf) - map_hdr->source_len); + ((*inbuf) - map_hdr->source_len); (*inbytesleft) += map_hdr->source_len; TRACE_MESSAGE('e', - ("map_i_f:error=%d\n", errno)); + ("map_i_f:error=%d\n", errno)); return ((size_t)(-1)); } p = (((unsigned char *)(map_hdr + 1)) + - (map_hdr->result_len * - (j - map_hdr->start.itm_ptr))); + (map_hdr->result_len * + (j - map_hdr->start.itm_ptr))); for (i = 0; i < map_hdr->result_len; i++) { PUT(*(p + i)); } @@ -674,18 +653,18 @@ map_l_f( p = *inbuf; } else if (0 == map_hdr->default_error) { p = map + (pair_size * tbl_hdr->number) + - map_hdr->source_len + 1; + map_hdr->source_len + 1; } else if (0 < map_hdr->default_error) { errno = EILSEQ; TRACE_MESSAGE('e', ("map_l_f:error=%d\n", - errno)); + errno)); return ((size_t)(-1)); } } else { if (0 != (*p)) { errno = EILSEQ; TRACE_MESSAGE('e', ("map_l_f:error=%d\n", - errno)); + errno)); return ((size_t)(-1)); } p++; @@ -754,8 +733,8 @@ map_h_l( result = 1; q = *inbuf; - hash_value = hash((const char *)(q), - source_len, map_hdr->hash_tbl_num); + hash_value = hash((const char *)(q), source_len, + map_hdr->hash_tbl_num); p = map_hash + (pair_size * hash_value); if (1 == *(map_error + hash_value)) { for (i = 0, result = 0; i < source_len; i++) { @@ -765,12 +744,10 @@ map_h_l( } } TRACE_MESSAGE('G', - ("(h=%d): find pair without conflict\n", - hash_value)); + ("(h=%d): find pair without conflict\n", + hash_value)); } else if (0 == *(map_error + hash_value)) { - TRACE_MESSAGE('G', - ("(h=%d): No Pair\n", - hash_value)); + TRACE_MESSAGE('G', ("(h=%d): No Pair\n", hash_value)); result = -3; } else /* if (0 < *(map_error + hash_value)) */ { for (i = 0, result = 0; i < source_len; i++) { @@ -801,11 +778,10 @@ map_h_l( } else if (0 < result) { low = mid + 1; } else { /* 0 == result */ - TRACE_MESSAGE('G', - ("(h=%d): " - "find data on out ot " - "hashtable with CONFLICT\n", - hash_value)); + TRACE_MESSAGE('G', ("(h=%d): " + "find data on out of " + "hashtable with CONFLICT\n", + hash_value)); break; } } @@ -817,21 +793,18 @@ map_h_l( } else if (0 == map_hdr->default_error) { p = map_of + map_hdr->hash_of_size; } else if (0 < map_hdr->default_error) { - TRACE_MESSAGE('G', - ("(h=%d): NO PAIR\n", - hash_value)); + TRACE_MESSAGE('G', ("(h=%d): NO PAIR\n", + hash_value)); errno = EILSEQ; TRACE_MESSAGE('e', - ("map_h_l:error=%d\n", errno)); + ("map_h_l:error=%d\n", errno)); return ((size_t)(-1)); } } else { if (0 != (*p)) { errno = EILSEQ; - TRACE_MESSAGE('G', - (" : error pair\n")); - TRACE_MESSAGE('e', ("map_l_f:error\n", - errno)); + TRACE_MESSAGE('G', (" : error pair\n")); + TRACE_MESSAGE('e', ("map_l_f:error\n", errno)); return ((size_t)(-1)); } p++; @@ -877,8 +850,8 @@ map_d_e_l( TRACE_MESSAGE('i', ("map_d_e_l\n")); map_hdr = (itm_map_dense_enc_hdr_t *)(tbl_hdr + 1); - map_ptr = ((unsigned char *)(map_hdr + 1) + - map_hdr->source_len + map_hdr->source_len); + map_ptr = ((unsigned char *)(map_hdr + 1) + map_hdr->source_len + + map_hdr->source_len); map_error = (map_ptr + (tbl_hdr->number * map_hdr->result_len)); if (0 == map_hdr->default_error) { map_error = (void *)(map_error + map_hdr->result_len); @@ -894,7 +867,7 @@ map_d_e_l( } j = hash_dense_encoding(*inbuf, map_hdr->source_len, - byte_seq_min, byte_seq_max); + byte_seq_min, byte_seq_max); if (((j < 0) || (tbl_hdr->number < j)) && (0 < map_hdr->default_error)) { @@ -911,8 +884,8 @@ map_d_e_l( if ((j < 0) || (tbl_hdr->number < j)) { if (0 == map_hdr->default_error) { - p = (map_ptr + - (tbl_hdr->number * map_hdr->result_len)); + p = (map_ptr + (tbl_hdr->number * + map_hdr->result_len)); for (i = 0; i < map_hdr->result_len; i++) { PUT(*(p + i)); } @@ -928,7 +901,7 @@ map_d_e_l( if (0 != *(map_error + j)) { errno = EILSEQ; TRACE_MESSAGE('e', - ("map_d_e_l:error=%d\n", errno)); + ("map_d_e_l:error=%d\n", errno)); return ((size_t)(-1)); } } @@ -986,8 +959,8 @@ eval_cond_tbl( rtsh = (itm_range_hdr_t *)(rth + 1); if (ileft < rtsh->len) { errno = EINVAL; - TRACE_MESSAGE('e', - ("eval_cond_tbl:error=%d\n", errno)); + TRACE_MESSAGE('e', ("eval_cond_tbl:error=%d\n", + errno)); retval = ((size_t)(-1)); goto eval_cond_return; } @@ -1010,8 +983,8 @@ eval_cond_tbl( } if (0 == retval) { TRACE_MESSAGE('b', - ("out of between (%p) len= rtsh=%ld\n", - *ip, rtsh->len)); + ("out of between (%p) len= rtsh=%ld\n", + *ip, rtsh->len)); goto eval_cond_return; } break; /* continue */ @@ -1027,11 +1000,10 @@ eval_cond_tbl( if (NULL == ist->default_action.itm_ptr) { ist->default_action = direc->action; TRACE_MESSAGE('E', - ("escape seq (default action=%6p, " - "type=%ld) set\n", - direc->action.itm_ptr, - ((itm_tbl_hdr_t *)(ADDR(direc->action))) - ->type)); + ("escape seq (default action=%6p, " + "type=%ld) set\n", + direc->action.itm_ptr, ((itm_tbl_hdr_t *) + (ADDR(direc->action)))->type)); } retval = 0; if (*inbytesleft < eh->len_min) { @@ -1045,14 +1017,14 @@ eval_cond_tbl( } if (0 == memcmp(*inbuf, DADDR(d), d->size)) { TRACE_MESSAGE('E', - ("escape seq: discard=%ld chars\n", - d->size)); - TRACE_MESSAGE('E', ( - "escape seq (default action=%6p, " - "type=%ld) set\n", - direc->action.itm_ptr, - ((itm_tbl_hdr_t *) - (ADDR(direc->action)))->type)); + ("escape seq: discard=%ld chars\n", + d->size)); + TRACE_MESSAGE('E', + ("escape seq (default " + "action=%6p, type=%ld) set\n", + direc->action.itm_ptr, + ((itm_tbl_hdr_t *) + (ADDR(direc->action)))->type)); ist->default_action = direc->action; DISCARD(d->size); retval = 2; @@ -1065,7 +1037,7 @@ eval_cond_tbl( break; /* continue */ case ITM_COND_EXPR: retval = eval_expr(ist, cond->operand.place, - *inbytesleft, ip, outbytesleft); + *inbytesleft, ip, outbytesleft); if (0 == retval) { goto eval_cond_return; } else { @@ -1074,7 +1046,7 @@ eval_cond_tbl( break; /* continue */ default: TRACE_MESSAGE('e', ("eval_cond_tbl:illegal cond=%d\n", - cond->type)); + cond->type)); retval = (size_t)-1; goto eval_cond_return; } @@ -1121,9 +1093,8 @@ eval_op_tbl( for (i = 0; i < op_hdr->number; i++, operation++, op_place += (sizeof (itm_op_t))) { TRACE_MESSAGE('O', ("eval_op_tbl: %ld %p\n", i, op_place)); - retval = eval_op(ist, op_place, - inbuf, inbytesleft, - outbuf, outbytesleft); + retval = eval_op(ist, op_place, inbuf, inbytesleft, + outbuf, outbytesleft); if (((long)(retval)) < 0) { #if defined(OP_DEPTH_MAX) ist->op_depth -= 1; @@ -1169,10 +1140,12 @@ eval_op( itm_size_t z; unsigned char *p; itm_expr_t *expr0; + itm_tbl_hdr_t *h; + itm_type_t t; #define EVAL_EXPR(n) \ (expr0 = ADDR(operation->data.operand[(n)]), \ - (itm_num_t)((expr0->type == ITM_EXPR_INT) ? \ + (itm_num_t)((expr0->type == ITM_EXPR_INT) ? \ expr0->data.itm_exnum : \ ((expr0->type == ITM_EXPR_REG) ? \ REG(expr0->data.itm_exnum) : \ @@ -1191,12 +1164,12 @@ eval_op( switch (operation->type) { case ITM_OP_EXPR: num = eval_expr(ist, operation->data.operand[0], - *inbytesleft, *inbuf, *outbytesleft); + *inbytesleft, *inbuf, *outbytesleft); TRACE_MESSAGE('o', ("ITM_OP_EXPR: %ld\n", retval)); break; case ITM_OP_ERROR: num = eval_expr(ist, operation->data.operand[0], - *inbytesleft, *inbuf, *outbytesleft); + *inbytesleft, *inbuf, *outbytesleft); errno = (int)num; TRACE_MESSAGE('o', ("ITM_OP_ERROR: %ld\n", num)); retval = (size_t)(-1); @@ -1214,7 +1187,7 @@ eval_op( return ((size_t)(-1)); } c = eval_expr(ist, operation->data.operand[0], - *inbytesleft, *inbuf, *outbytesleft); + *inbytesleft, *inbuf, *outbytesleft); PUT((uchar_t)c); retval = *inbytesleft; TRACE_MESSAGE('o', ("ITM_OP_OUT: %ld %ld\n", c, *inbytesleft)); @@ -1264,9 +1237,9 @@ eval_op( return ((size_t)(-1)); } z = (((0 <= expr->data.itm_exnum) && - (expr->data.itm_exnum < *inbytesleft)) ? - (*((unsigned char *)(*inbuf + expr->data.itm_exnum))) : - (((-1) == expr->data.itm_exnum) ? *inbytesleft : 0)); + (expr->data.itm_exnum < *inbytesleft)) ? + (*((unsigned char *)(*inbuf + expr->data.itm_exnum))) : + (((-1) == expr->data.itm_exnum) ? *inbytesleft : 0)); PUT((uchar_t)z); break; case ITM_OP_DISCARD: @@ -1274,12 +1247,11 @@ eval_op( num = EVAL_EXPR(0); #else /* !defined(EVAL_EXPR) */ num = eval_expr(ist, operation->data.operand[0], - *inbytesleft, *inbuf, *outbytesleft); + *inbytesleft, *inbuf, *outbytesleft); #endif /* defined(EVAL_EXPR) */ TRACE_MESSAGE('o', ("ITM_OP_DISCARD: %ld\n", num)); #if defined(DISCARD) - DISCARD((num <= *inbytesleft) ? ((ulong_t)num) : - *inbytesleft); + DISCARD((num <= *inbytesleft) ? ((ulong_t)num) : *inbytesleft); #else /* defined(DISCARD) */ for (num = ((num <= *inbytesleft) ? num : *inbytesleft); 0 < num; --num) { @@ -1301,54 +1273,82 @@ eval_op( break; case ITM_OP_IF: c = eval_expr(ist, operation->data.operand[0], - *inbytesleft, *inbuf, *outbytesleft); + *inbytesleft, *inbuf, *outbytesleft); TRACE_MESSAGE('o', ("ITM_OP_IF: %ld\n", c)); if (c) { - retval = eval_op_tbl(ist, - operation->data.operand[1], - inbuf, inbytesleft, - outbuf, outbytesleft); + retval = eval_op_tbl(ist, operation->data.operand[1], + inbuf, inbytesleft, outbuf, outbytesleft); } break; case ITM_OP_IF_ELSE: c = eval_expr(ist, operation->data.operand[0], - *inbytesleft, *inbuf, *outbytesleft); + *inbytesleft, *inbuf, *outbytesleft); TRACE_MESSAGE('o', ("ITM_OP_IF_ELSE: %ld\n", c)); if (c) { - retval = eval_op_tbl(ist, - operation->data.operand[1], - inbuf, inbytesleft, - outbuf, outbytesleft); + retval = eval_op_tbl(ist, operation->data.operand[1], + inbuf, inbytesleft, outbuf, outbytesleft); } else { - retval = eval_op_tbl(ist, - operation->data.operand[2], - inbuf, inbytesleft, - outbuf, outbytesleft); + retval = eval_op_tbl(ist, operation->data.operand[2], + inbuf, inbytesleft, outbuf, outbytesleft); } break; case ITM_OP_DIRECTION: TRACE_MESSAGE('o', ("ITM_OP_DIRECTION: %p\n", - operation->data.operand[0].itm_ptr)); + operation->data.operand[0].itm_ptr)); ist->direc = ADDR(operation->data.operand[0]); return ((size_t)(-2)); case ITM_OP_MAP: TRACE_MESSAGE('o', ("ITM_OP_MAP: %p\n", - operation->data.operand[0].itm_ptr)); + operation->data.operand[0].itm_ptr)); i = 0; if (0 != operation->data.operand[1].itm_ptr) { #if defined(EVAL_EXPR) i = EVAL_EXPR(1); #else /* !defined(EVAL_EXPR) */ i = eval_expr(ist, operation->data.operand[1], - *inbytesleft, *inbuf, *outbytesleft); + *inbytesleft, *inbuf, *outbytesleft); #endif /* defined(EVAL_EXPR) */ (*inbytesleft) -= i; (*inbuf) += i; } - retval = map_i_f(ADDR(operation->data.operand[0]), - inbuf, inbytesleft, - outbuf, outbytesleft, 1); + /* + * Based on what is the maptype, we call the corresponding + * mapping function. + */ + h = ADDR(operation->data.operand[0]); + t = h->type; + switch (t) { + case ITM_TBL_MAP_INDEX_FIXED: + case ITM_TBL_MAP_INDEX_FIXED_1_1: + retval = map_i_f(h, inbuf, inbytesleft, + outbuf, outbytesleft, 1); + break; + case ITM_TBL_MAP_HASH: + retval = map_h_l(h, inbuf, inbytesleft, + outbuf, outbytesleft, 1); + break; + case ITM_TBL_MAP_DENSE_ENC: + retval = map_d_e_l(h, inbuf, inbytesleft, + outbuf, outbytesleft, 1); + break; + case ITM_TBL_MAP_LOOKUP: + retval = map_l_f(h, inbuf, inbytesleft, + outbuf, outbytesleft, 1); + break; + default: + /* + * This should not be possible, but in case we + * have an incorrect maptype, don't fall back to + * map_i_f(). Instead, because it is an error, return + * an error. See CR 6622765. + */ + errno = EBADF; + TRACE_MESSAGE('e', ("eval_op:error=%d\n", errno)); + retval = (size_t)-1; + break; + } + if ((size_t)(-1) == retval) { (*outbytesleft) += i; (*outbuf) -= i; @@ -1356,21 +1356,17 @@ eval_op( break; case ITM_OP_OPERATION: TRACE_MESSAGE('o', ("ITM_OP_OPERATION: %p\n", - operation->data.operand[0].itm_ptr)); - retval = eval_op_tbl(ist, - operation->data.operand[0], - inbuf, inbytesleft, - outbuf, outbytesleft); + operation->data.operand[0].itm_ptr)); + retval = eval_op_tbl(ist, operation->data.operand[0], + inbuf, inbytesleft, outbuf, outbytesleft); break; case ITM_OP_INIT: TRACE_MESSAGE('o', ("ITM_OP_INIT: %p\n", - ist->itm_hdr->op_init_tbl)); + ist->itm_hdr->op_init_tbl)); if (0 != ist->itm_hdr->op_init_tbl.itm_ptr) { - retval = eval_op_tbl(ist, - ist->itm_hdr->op_init_tbl, - inbuf, inbytesleft, - outbuf, outbytesleft); + retval = eval_op_tbl(ist, ist->itm_hdr->op_init_tbl, + inbuf, inbytesleft, outbuf, outbytesleft); } else { op_init_default(ist); retval = (size_t)-2; @@ -1378,12 +1374,10 @@ eval_op( break; case ITM_OP_RESET: TRACE_MESSAGE('o', ("ITM_OP_RESET: %p\n", - ist->itm_hdr->op_reset_tbl)); + ist->itm_hdr->op_reset_tbl)); if (0 != ist->itm_hdr->op_reset_tbl.itm_ptr) { - retval = eval_op_tbl(ist, - ist->itm_hdr->op_reset_tbl, - inbuf, inbytesleft, - outbuf, outbytesleft); + retval = eval_op_tbl(ist, ist->itm_hdr->op_reset_tbl, + inbuf, inbytesleft, outbuf, outbytesleft); } else { op_reset_default(ist); retval = (size_t)-2; @@ -1396,25 +1390,25 @@ eval_op( TRACE_MESSAGE('o', ("ITM_OP_RETURN\n")); return (RETVALRET); case ITM_OP_PRINTCHR: - c = eval_expr(ist, operation->data.operand[0], - *inbytesleft, *inbuf, *outbytesleft); + c = eval_expr(ist, operation->data.operand[0], *inbytesleft, + *inbuf, *outbytesleft); (void) fputc((uchar_t)c, stderr); - TRACE_MESSAGE('o', - ("ITM_OP_PRINTCHR: %ld %ld\n", c, *inbytesleft)); + TRACE_MESSAGE('o', ("ITM_OP_PRINTCHR: %ld %ld\n", + c, *inbytesleft)); break; case ITM_OP_PRINTHD: - c = eval_expr(ist, operation->data.operand[0], - *inbytesleft, *inbuf, *outbytesleft); + c = eval_expr(ist, operation->data.operand[0], *inbytesleft, + *inbuf, *outbytesleft); (void) fprintf(stderr, "%lx", c); - TRACE_MESSAGE('o', - ("ITM_OP_PRINTHD: %ld %ld\n", c, *inbytesleft)); + TRACE_MESSAGE('o', ("ITM_OP_PRINTHD: %ld %ld\n", + c, *inbytesleft)); break; case ITM_OP_PRINTINT: - c = eval_expr(ist, operation->data.operand[0], - *inbytesleft, *inbuf, *outbytesleft); + c = eval_expr(ist, operation->data.operand[0], *inbytesleft, + *inbuf, *outbytesleft); (void) fprintf(stderr, "%ld", c); - TRACE_MESSAGE('o', - ("ITM_OP_PRINTINT: %ld %ld\n", c, *inbytesleft)); + TRACE_MESSAGE('o', ("ITM_OP_PRINTINT: %ld %ld\n", + c, *inbytesleft)); break; default: /* never */ errno = ELIBBAD; @@ -1448,28 +1442,28 @@ eval_expr( itm_num_t num01; #define EVAL_EXPR_E(n) (eval_expr(ist, expr->data.operand[(n)], \ - inbytesleft, inbuf, outbytesleft)) + inbytesleft, inbuf, outbytesleft)) #define EVAL_EXPR_D(n) ((itm_num_t)(expr->data.operand[(n)].itm_ptr)) #define EVAL_EXPR_R(n) (REG((itm_num_t)(expr->data.operand[(n)].itm_ptr))) #define EVAL_EXPR_INVD(n) \ ((num0 ## n) = ((itm_num_t)(expr->data.operand[(n)].itm_ptr)), \ - ((num0 ## n) < 0) ? \ - (((-1) == (num0 ## n)) ? inbytesleft : 0) : \ - (((num0 ## n) < inbytesleft) ? \ - (*(unsigned char *)(inbuf + (num0 ## n))) : 0)) + ((num0 ## n) < 0) ? \ + (((-1) == (num0 ## n)) ? inbytesleft : 0) : \ + (((num0 ## n) < inbytesleft) ? \ + (*(unsigned char *)(inbuf + (num0 ## n))) : 0)) #define EVAL_EXPR(n) \ (expr0 = ADDR(expr->data.operand[(n)]), \ - (itm_num_t)((expr0->type == ITM_EXPR_INT) ? \ - expr0->data.itm_exnum : \ - ((expr0->type == ITM_EXPR_REG) ? \ - REG(expr0->data.itm_exnum) : \ - ((expr0->type == ITM_EXPR_IN_VECTOR_D) ? \ - ((expr0->data.itm_exnum < 0) ? \ - (((-1) == expr0->data.itm_exnum) ? inbytesleft : 0) : \ - ((expr0->data.itm_exnum < inbytesleft) ? \ - (*(uchar_t *)(inbuf + expr0->data.itm_exnum)) : 0)) : \ - eval_expr(ist, expr->data.operand[(n)], \ - inbytesleft, inbuf, outbytesleft))))) + (itm_num_t)((expr0->type == ITM_EXPR_INT) ? \ + expr0->data.itm_exnum : \ + ((expr0->type == ITM_EXPR_REG) ? \ + REG(expr0->data.itm_exnum) : \ + ((expr0->type == ITM_EXPR_IN_VECTOR_D) ? \ + ((expr0->data.itm_exnum < 0) ? \ + (((-1) == expr0->data.itm_exnum) ? inbytesleft : 0) : \ + ((expr0->data.itm_exnum < inbytesleft) ? \ + (*(uchar_t *)(inbuf + expr0->data.itm_exnum)) : 0)) : \ + eval_expr(ist, expr->data.operand[(n)], \ + inbytesleft, inbuf, outbytesleft))))) #define EVAL_OP_BIN_PROTO(op, name, name0, name1) \ case ITM_EXPR_##name##_##name0##_##name1: \ @@ -1697,7 +1691,7 @@ eval_expr( num = EVAL_EXPR(1); if (expr->data.operand[0].itm_ptr < ist->itm_hdr->reg_num) { return (*(ist->regs + expr->data.operand[0].itm_ptr) - = num); + = num); } else { return (0); } @@ -1819,8 +1813,7 @@ itm_ref_inc(const char *itm) (hdr->version[2] != ITM_VER_2) || (hdr->version[3] != ITM_VER_3) || (((size_t)(hdr->itm_size.itm_ptr)) != st.st_size)) { - itm_ref_free(-1, ref, ref->name, - ref->hdr, ref->len); + itm_ref_free(-1, ref, ref->name, ref->hdr, ref->len); errno = ELIBBAD; TRACE_MESSAGE('e', ("itm_ref_inc:error=%d\n", errno)); return (NULL); @@ -1860,7 +1853,7 @@ regs_init(icv_state_t *ist) { if (0 < ist->itm_hdr->reg_num) { (void) memset(ist->regs, 0, - (sizeof (itm_num_t)) * ist->itm_hdr->reg_num); + (sizeof (itm_num_t)) * ist->itm_hdr->reg_num); } } diff --git a/usr/src/common/unicode/u8_textprep.c b/usr/src/common/unicode/u8_textprep.c index 37a01b83b1..8faf1a97e4 100644 --- a/usr/src/common/unicode/u8_textprep.c +++ b/usr/src/common/unicode/u8_textprep.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -334,7 +334,7 @@ const uint8_t u8_valid_max_2nd_byte[0x100] = { * specific to UTF-8 and Unicode. */ int -u8_validate(char *u8str, size_t n, char **list, int flag, int *errno) +u8_validate(char *u8str, size_t n, char **list, int flag, int *errnum) { uchar_t *ib; uchar_t *ibtail; @@ -371,13 +371,13 @@ u8_validate(char *u8str, size_t n, char **list, int flag, int *errno) */ sz = u8_number_of_bytes[*ib]; if (sz == U8_ILLEGAL_CHAR) { - *errno = EILSEQ; + *errnum = EILSEQ; return (-1); } if (sz == U8_OUT_OF_RANGE_CHAR || (validate_ucs2_range_only && sz > U8_MAX_BYTES_UCS2)) { - *errno = ERANGE; + *errnum = ERANGE; return (-1); } @@ -387,7 +387,7 @@ u8_validate(char *u8str, size_t n, char **list, int flag, int *errno) * checking higher priority then EINVAL cases. */ if ((ibtail - ib) < sz) { - *errno = EINVAL; + *errnum = EINVAL; return (-1); } @@ -407,12 +407,12 @@ u8_validate(char *u8str, size_t n, char **list, int flag, int *errno) if (second) { if (*ib < u8_valid_min_2nd_byte[f] || *ib > u8_valid_max_2nd_byte[f]) { - *errno = EILSEQ; + *errnum = EILSEQ; return (-1); } second = B_FALSE; } else if (U8_ILLEGAL_NEXT_BYTE_COMMON(*ib)) { - *errno = EILSEQ; + *errnum = EILSEQ; return (-1); } ib++; @@ -432,7 +432,7 @@ u8_validate(char *u8str, size_t n, char **list, int flag, int *errno) } if (s1 >= ib && *s2 == '\0') { - *errno = EBADF; + *errnum = EBADF; return (-1); } } @@ -566,7 +566,7 @@ do_case_conv(int uv, uchar_t *u8s, uchar_t *s, int sz, boolean_t is_it_toupper) */ static int do_case_compare(size_t uv, uchar_t *s1, uchar_t *s2, size_t n1, - size_t n2, boolean_t is_it_toupper, int *errno) + size_t n2, boolean_t is_it_toupper, int *errnum) { int f; int sz1; @@ -583,11 +583,11 @@ do_case_compare(size_t uv, uchar_t *s1, uchar_t *s2, size_t n1, * Find out what would be the byte length for this UTF-8 * character at string s1 and also find out if this is * an illegal start byte or not and if so, issue a proper - * errno and yet treat this byte as a character. + * error number and yet treat this byte as a character. */ sz1 = u8_number_of_bytes[*s1]; if (sz1 < 0) { - *errno = EILSEQ; + *errnum = EILSEQ; sz1 = 1; } @@ -612,7 +612,7 @@ do_case_compare(size_t uv, uchar_t *s1, uchar_t *s2, size_t n1, s1++; u8s1[1] = '\0'; } else if ((i1 + sz1) > n1) { - *errno = EINVAL; + *errnum = EINVAL; for (j = 0; (i1 + j) < n1; ) u8s1[j++] = *s1++; u8s1[j] = '\0'; @@ -624,7 +624,7 @@ do_case_compare(size_t uv, uchar_t *s1, uchar_t *s2, size_t n1, /* Do the same for the string s2. */ sz2 = u8_number_of_bytes[*s2]; if (sz2 < 0) { - *errno = EILSEQ; + *errnum = EILSEQ; sz2 = 1; } @@ -636,7 +636,7 @@ do_case_compare(size_t uv, uchar_t *s1, uchar_t *s2, size_t n1, s2++; u8s2[1] = '\0'; } else if ((i2 + sz2) > n2) { - *errno = EINVAL; + *errnum = EINVAL; for (j = 0; (i2 + j) < n2; ) u8s2[j++] = *s2++; u8s2[j] = '\0'; @@ -1383,7 +1383,7 @@ collect_a_seq(size_t uv, uchar_t *u8s, uchar_t **source, uchar_t *slast, boolean_t canonical_decomposition, boolean_t compatibility_decomposition, boolean_t canonical_composition, - int *errno, u8_normalization_states_t *state) + int *errnum, u8_normalization_states_t *state) { uchar_t *s; int sz; @@ -1426,7 +1426,7 @@ collect_a_seq(size_t uv, uchar_t *u8s, uchar_t **source, uchar_t *slast, sz = u8_number_of_bytes[*s]; if (sz < 0) { - *errno = EILSEQ; + *errnum = EILSEQ; u8s[0] = *s++; u8s[1] = '\0'; @@ -1446,7 +1446,7 @@ collect_a_seq(size_t uv, uchar_t *u8s, uchar_t **source, uchar_t *slast, s++; u8s[1] = '\0'; } else if ((s + sz) > slast) { - *errno = EINVAL; + *errnum = EINVAL; for (i = 0; s < slast; ) u8s[i++] = *s++; @@ -1726,7 +1726,7 @@ TURN_STREAM_SAFE: */ static int do_norm_compare(size_t uv, uchar_t *s1, uchar_t *s2, size_t n1, size_t n2, - int flag, int *errno) + int flag, int *errnum) { int result; size_t sz1; @@ -1778,7 +1778,7 @@ do_norm_compare(size_t uv, uchar_t *s1, uchar_t *s2, size_t n1, size_t n2, is_it_toupper, is_it_tolower, canonical_decomposition, compatibility_decomposition, - canonical_composition, errno, &state); + canonical_composition, errnum, &state); } if (U8_ISASCII(*s2) && ((s2 + 1) >= s2last || @@ -1798,7 +1798,7 @@ do_norm_compare(size_t uv, uchar_t *s1, uchar_t *s2, size_t n1, size_t n2, is_it_toupper, is_it_tolower, canonical_decomposition, compatibility_decomposition, - canonical_composition, errno, &state); + canonical_composition, errnum, &state); } /* @@ -1842,13 +1842,13 @@ do_norm_compare(size_t uv, uchar_t *s1, uchar_t *s2, size_t n1, size_t n2, */ int u8_strcmp(const char *s1, const char *s2, size_t n, int flag, size_t uv, - int *errno) + int *errnum) { int f; size_t n1; size_t n2; - *errno = 0; + *errnum = 0; /* * Check on the requested Unicode version, case conversion, and @@ -1856,7 +1856,7 @@ u8_strcmp(const char *s1, const char *s2, size_t n, int flag, size_t uv, */ if (uv > U8_UNICODE_LATEST) { - *errno = ERANGE; + *errnum = ERANGE; uv = U8_UNICODE_LATEST; } @@ -1869,14 +1869,14 @@ u8_strcmp(const char *s1, const char *s2, size_t n, int flag, size_t uv, flag |= U8_STRCMP_CS; } else if (f != U8_STRCMP_CS && f != U8_STRCMP_CI_UPPER && f != U8_STRCMP_CI_LOWER) { - *errno = EBADF; + *errnum = EBADF; flag = U8_STRCMP_CS; } f = flag & (U8_CANON_DECOMP | U8_COMPAT_DECOMP | U8_CANON_COMP); if (f && f != U8_STRCMP_NFD && f != U8_STRCMP_NFC && f != U8_STRCMP_NFKD && f != U8_STRCMP_NFKC) { - *errno = EBADF; + *errnum = EBADF; flag = U8_STRCMP_CS; } } @@ -1900,19 +1900,19 @@ u8_strcmp(const char *s1, const char *s2, size_t n, int flag, size_t uv, */ if (flag == U8_STRCMP_CI_UPPER) { return (do_case_compare(uv, (uchar_t *)s1, (uchar_t *)s2, - n1, n2, B_TRUE, errno)); + n1, n2, B_TRUE, errnum)); } else if (flag == U8_STRCMP_CI_LOWER) { return (do_case_compare(uv, (uchar_t *)s1, (uchar_t *)s2, - n1, n2, B_FALSE, errno)); + n1, n2, B_FALSE, errnum)); } return (do_norm_compare(uv, (uchar_t *)s1, (uchar_t *)s2, n1, n2, - flag, errno)); + flag, errnum)); } size_t u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen, - int flag, size_t unicode_version, int *errno) + int flag, size_t unicode_version, int *errnum) { int f; int sz; @@ -1934,20 +1934,20 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen, u8_normalization_states_t state; if (unicode_version > U8_UNICODE_LATEST) { - *errno = ERANGE; + *errnum = ERANGE; return ((size_t)-1); } f = flag & (U8_TEXTPREP_TOUPPER | U8_TEXTPREP_TOLOWER); if (f == (U8_TEXTPREP_TOUPPER | U8_TEXTPREP_TOLOWER)) { - *errno = EBADF; + *errnum = EBADF; return ((size_t)-1); } f = flag & (U8_CANON_DECOMP | U8_COMPAT_DECOMP | U8_CANON_COMP); if (f && f != U8_TEXTPREP_NFD && f != U8_TEXTPREP_NFC && f != U8_TEXTPREP_NFKD && f != U8_TEXTPREP_NFKC) { - *errno = EBADF; + *errnum = EBADF; return ((size_t)-1); } @@ -1955,7 +1955,7 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen, return (0); if (outarray == NULL) { - *errno = E2BIG; + *errnum = E2BIG; return ((size_t)-1); } @@ -1987,7 +1987,7 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen, if (sz < 0) { if (do_not_ignore_invalid) { - *errno = EILSEQ; + *errnum = EILSEQ; ret_val = (size_t)-1; break; } @@ -1998,7 +1998,7 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen, if (sz == 1) { if (ob >= obtail) { - *errno = E2BIG; + *errnum = E2BIG; ret_val = (size_t)-1; break; } @@ -2013,13 +2013,13 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen, ob++; } else if ((ib + sz) > ibtail) { if (do_not_ignore_invalid) { - *errno = EINVAL; + *errnum = EINVAL; ret_val = (size_t)-1; break; } if ((obtail - ob) < (ibtail - ib)) { - *errno = E2BIG; + *errnum = E2BIG; ret_val = (size_t)-1; break; } @@ -2038,7 +2038,7 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen, ib, sz, is_it_toupper); if ((obtail - ob) < i) { - *errno = E2BIG; + *errnum = E2BIG; ret_val = (size_t)-1; break; } @@ -2049,7 +2049,7 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen, *ob++ = u8s[sz]; } else { if ((obtail - ob) < sz) { - *errno = E2BIG; + *errnum = E2BIG; ret_val = (size_t)-1; break; } @@ -2082,7 +2082,7 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen, if (U8_ISASCII(*ib) && ((ib + 1) >= ibtail || ((ib + 1) < ibtail && U8_ISASCII(*(ib + 1))))) { if (ob >= obtail) { - *errno = E2BIG; + *errnum = E2BIG; ret_val = (size_t)-1; break; } @@ -2096,7 +2096,7 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen, ib++; ob++; } else { - *errno = 0; + *errnum = 0; state = U8_STATE_START; j = collect_a_seq(unicode_version, u8s, @@ -2106,15 +2106,15 @@ u8_textprep_str(char *inarray, size_t *inlen, char *outarray, size_t *outlen, canonical_decomposition, compatibility_decomposition, canonical_composition, - errno, &state); + errnum, &state); - if (*errno && do_not_ignore_invalid) { + if (*errnum && do_not_ignore_invalid) { ret_val = (size_t)-1; break; } if ((obtail - ob) < j) { - *errno = E2BIG; + *errnum = E2BIG; ret_val = (size_t)-1; break; } diff --git a/usr/src/uts/common/io/ldterm.c b/usr/src/uts/common/io/ldterm.c index 3303e45420..69af0acf27 100644 --- a/usr/src/uts/common/io/ldterm.c +++ b/usr/src/uts/common/io/ldterm.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -521,160 +520,14 @@ static const ldterm_cs_data_t default_cs_data = { }; /* - * The byte length of a UTF-8 character can be decided by looking at the - * first byte: - * - * Binary enc Code range Byte length - * - * 0xxx xxxx 0x00 ~ 0x7F 1 - * 110x xxxx 0xC0 ~ 0xDF 2 - * 1110 xxxx 0xE0 ~ 0xEF 3 - * 1111 0xxx 0xF0 ~ 0xF7 4 - * 1111 10xx 0xF8 ~ 0xFB 5 - * 1111 110x 0xFC ~ 0xFD 6 - * - * Invalid leading bytes, esp., 0x80 ~ 0xBF, 0xFE, and, 0xFF, will be treated - * as a single byte, single display column character. + * The following tables are from either u8_textprep.c or uconv.c at + * usr/src/common/unicode/. The tables are used to figure out corresponding + * UTF-8 character byte lengths and also the validity of given character bytes. */ -static const uchar_t utf8_byte_length_tbl[0x100] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - -/* C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF */ - 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - -/* D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF */ - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - -/* E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF */ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - -/* F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF */ - 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -}; - -/* - * Following is a vector of bit-masks to get used bits in the first byte of - * a UTF-8 character. Index is remaining bytes of the UTF-8 character. - */ -static const char masks_tbl[6] = { 0x00, 0x1f, 0x0f, 0x07, 0x03, 0x01 }; - -/* - * The following two vectors are to provide valid minimum and - * maximum values for the 2'nd byte of a multibyte UTF-8 character for - * better illegal sequence checking as defined in the "UTF-8 Corrigendum" of - * the Unicode 3.1 standard. The index value must be the value of - * the first byte of an UTF-8 character. - */ -static const uchar_t valid_min_2nd_byte[0x100] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - -/* C0 C1 C2 C3 C4 C5 C6 C7 */ - 0, 0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - -/* C8 C9 CA CB CC CD CE CF */ - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - -/* D0 D1 D2 D3 D4 D5 D6 D7 */ - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - -/* D8 D9 DA DB DC DD DE DF */ - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - -/* E0 E1 E2 E3 E4 E5 E6 E7 */ - 0xa0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - -/* E8 E9 EA EB EC ED EE EF */ - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - -/* F0 F1 F2 F3 F4 F5 F6 F7 */ - 0x90, 0x80, 0x80, 0x80, 0x80, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, -}; - -static const uchar_t valid_max_2nd_byte[0x100] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - -/* C0 C1 C2 C3 C4 C5 C6 C7 */ - 0, 0, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, - -/* C8 C9 CA CB CC CD CE CF */ - 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, - -/* D0 D1 D2 D3 D4 D5 D6 D7 */ - 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, - -/* D8 D9 DA DB DC DD DE DF */ - 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, - -/* E0 E1 E2 E3 E4 E5 E6 E7 */ - 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, - -/* E8 E9 EA EB EC ED EE EF */ - 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, - -/* F0 F1 F2 F3 F4 F5 F6 F7 */ - 0xbf, 0xbf, 0xbf, 0xbf, 0x8f, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, -}; +extern const int8_t u8_number_of_bytes[]; +extern const uchar_t u8_masks_tbl[]; +extern const uint8_t u8_valid_min_2nd_byte[]; +extern const uint8_t u8_valid_max_2nd_byte[]; /* * Unicode character width definition tables from uwidth.c: @@ -826,7 +679,7 @@ ldtermopen(queue_t *q, dev_t *devp, int oflag, int sflag, cred_t *crp) } tp = (ldtermstd_state_t *)kmem_zalloc(sizeof (ldtermstd_state_t), - KM_SLEEP); + KM_SLEEP); /* * Get termios defaults. These are stored as @@ -1192,7 +1045,7 @@ ldtermrput(queue_t *q, mblk_t *mp) freemsg(mp); if ((mp = allocb(3, BPRI_HI)) == NULL) { cmn_err(CE_WARN, - "ldtermrput: no blocks"); + "ldtermrput: no blocks"); return; } mp->b_datap->db_type = M_DATA; @@ -1207,7 +1060,7 @@ ldtermrput(queue_t *q, mblk_t *mp) freemsg(mp); if ((mp = allocb(1, BPRI_HI)) == NULL) { cmn_err(CE_WARN, - "ldtermrput: no blocks"); + "ldtermrput: no blocks"); return; } mp->b_datap->db_type = M_DATA; @@ -1424,7 +1277,8 @@ ldtermrput(queue_t *q, mblk_t *mp) tp->t_modes.c_iflag & IXANY)) { tp->t_state &= - ~(TS_TTSTOP|TS_OFBLOCK); + ~(TS_TTSTOP | + TS_OFBLOCK); (void) putnextctl(wrq, M_START); } @@ -1568,7 +1422,7 @@ ldtermrput(queue_t *q, mblk_t *mp) */ if (q->q_first != NULL || !bcanputnext(q, mp->b_band) || - (tp->t_state & TS_RESCAN)) + (tp->t_state & TS_RESCAN)) (void) putq(q, mp); else (void) ldtermrmsg(q, mp); @@ -1831,8 +1685,7 @@ ldtermrmsg(queue_t *q, mblk_t *mp) break; } } else - bpt = ldterm_dononcanon(bp, bpt, - ebsize, q, tp); + bpt = ldterm_dononcanon(bp, bpt, ebsize, q, tp); if (bpt == NULL) { cmn_err(CE_WARN, "ldtermrsrv: out of blocks"); @@ -1894,7 +1747,7 @@ ldterm_docanon(uchar_t c, mblk_t *bpt, size_t ebsize, queue_t *q, if ((tp->t_modes.c_lflag & IEXTEN) && c == tp->t_modes.c_cc[VLNEXT]) { if (tp->t_modes.c_lflag & ECHO) ldterm_outstring((unsigned char *)"^\b", 2, wrq, - ebsize, tp); + ebsize, tp); tp->t_state |= TS_SLNCH; goto out; } @@ -2107,20 +1960,18 @@ escaped: } else { /* is the first byte of a multi-byte, or is ASCII */ if (ISASCII(c)) { *tp->t_eucp++ = - tp->t_csmethods.ldterm_dispwidth(c, - (void *)tp, - tp->t_modes.c_lflag & ECHOCTL); + tp->t_csmethods.ldterm_dispwidth(c, + (void *)tp, tp->t_modes.c_lflag & ECHOCTL); tp->t_codeset = 0; } else { *tp->t_eucp++ = - tp->t_csmethods.ldterm_dispwidth(c, - (void *)tp, - tp->t_modes.c_lflag & ECHOCTL); + tp->t_csmethods.ldterm_dispwidth(c, + (void *)tp, tp->t_modes.c_lflag & ECHOCTL); tp->t_eucleft = - tp->t_csmethods.ldterm_memwidth(c, - (void *)tp) - 1; + tp->t_csmethods.ldterm_memwidth(c, + (void *)tp) - 1; tp->t_codeset = ldterm_codeset( - tp->t_csdata.codeset_type, c); + tp->t_csdata.codeset_type, c); } } } @@ -2278,7 +2129,7 @@ ldterm_rubout(uchar_t c, queue_t *q, size_t ebsize, ldtermstd_state_t *tp) if ((tp->t_modes.c_lflag & XCASE) && omaptab[c]) ldterm_outstring(RUBOUT1, 3, q, ebsize, - tp); + tp); ldterm_outstring(RUBOUT1, 3, q, ebsize, tp); break; @@ -2290,7 +2141,7 @@ ldterm_rubout(uchar_t c, queue_t *q, size_t ebsize, ldtermstd_state_t *tp) if ((tp->t_modes.c_lflag & ECHOCTL) && (tp->t_modes.c_lflag & IEXTEN)) ldterm_outstring(RUBOUT2, 6, q, ebsize, - tp); + tp); break; case TAB: @@ -2313,7 +2164,7 @@ ldterm_rubout(uchar_t c, queue_t *q, size_t ebsize, ldtermstd_state_t *tp) } } } else if ((tp->t_modes.c_lflag & ECHOPRT) && - (tp->t_modes.c_lflag & IEXTEN)) { + (tp->t_modes.c_lflag & IEXTEN)) { /* * "Printing rubout"; echo it between \ and /. */ @@ -2389,14 +2240,14 @@ ldterm_tabcols(ldtermstd_state_t *tp) */ u8[0] = *startp; for (i = 1; (i < LDTERM_CS_MAX_BYTE_LENGTH) && - (*(readp + i) == 0); - i++) { + (*(readp + i) == 0); i++) { startp++; if (startp >= bp->b_datap->db_lim) { if (bp->b_cont) { bp = bp->b_cont; startp = - bp->b_datap->db_base; + bp->b_datap-> + db_base; } else { *readp = 1; col++; @@ -2705,7 +2556,7 @@ ldterm_kill(queue_t *q, size_t ebsize, ldtermstd_state_t *tp) if ((*ip == 1 || *ip == 2 || *ip > UNKNOWN_WIDTH) && ISASCII(c)) { ldterm_rubout((unsigned char) c, q, - ebsize, tp); + ebsize, tp); len = 0; } else if (*ip) { if (*ip == UNKNOWN_WIDTH) { @@ -2716,7 +2567,7 @@ ldterm_kill(queue_t *q, size_t ebsize, ldtermstd_state_t *tp) u8_2[i] = u8[len-i-1]; *ip = ldterm_utf8_width( - u8_2, len); + u8_2, len); } else { *ip = 1; } @@ -2827,7 +2678,7 @@ ldterm_dononcanon(mblk_t *bp, mblk_t *bpt, size_t ebsize, queue_t *q, if (tp->t_modes.c_lflag & ECHO) ldterm_outstring( (unsigned char *)"^\b", - 2, wrq, ebsize, tp); + 2, wrq, ebsize, tp); tp->t_state |= TS_SLNCH; continue; /* and ignore it */ } @@ -2850,8 +2701,7 @@ ldterm_dononcanon(mblk_t *bp, mblk_t *bpt, size_t ebsize, queue_t *q, * set. */ if (c == '\n') - ldterm_outchar('\n', - wrq, 1, tp); + ldterm_outchar('\n', wrq, 1, tp); } } bp->b_wptr = wptr; @@ -2890,7 +2740,7 @@ ldterm_dononcanon(mblk_t *bp, mblk_t *bpt, size_t ebsize, queue_t *q, roomleft = IBSIZE; } DEBUG5(("roomleft=%d, bytes_in_bp=%d, tp->t_rd_request=%d\n", - roomleft, bytes_in_bp, tp->t_rd_request)); + roomleft, bytes_in_bp, tp->t_rd_request)); /* * if there is a read pending before this data got * here move bytes according to the minimum of room @@ -3019,8 +2869,8 @@ ldterm_echo(uchar_t c, queue_t *q, size_t ebsize, ldtermstd_state_t *tp) return (i + 1); /* echo only special control character and the Bell */ } else if ((c > 037 && c != 0177) || c == '\t' || c == '\n' || - c == '\r' || c == '\b' || c == 007 || - c == tp->t_modes.c_cc[VKILL]) { + c == '\r' || c == '\b' || c == 007 || + c == tp->t_modes.c_cc[VKILL]) { ldterm_outchar(c, q, ebsize, tp); return (i + 1); } @@ -3209,11 +3059,12 @@ ldtermwput(queue_t *q, mblk_t *mp) * eventually. */ if (*mp->b_rptr & FLUSHW) { - if ((tp->t_state & TS_ISPTSTTY) && - (*mp->b_rptr & FLUSHBAND)) - flushband(q, *(mp->b_rptr + 1), FLUSHDATA); - else - flushq(q, FLUSHDATA); + if ((tp->t_state & TS_ISPTSTTY) && + (*mp->b_rptr & FLUSHBAND)) + flushband(q, *(mp->b_rptr + 1), + FLUSHDATA); + else + flushq(q, FLUSHDATA); } putnext(q, mp); @@ -3465,7 +3316,7 @@ ldtermwmsg(queue_t *q, mblk_t *mp) short flag = mp->b_flag; residmp = ldterm_output_msg(q, mp, &omp, - tp, OBSIZE, 0); + tp, OBSIZE, 0); if ((mp = omp) == NULL) break; mp->b_band |= band; @@ -3612,14 +3463,19 @@ ldterm_output_msg(queue_t *q, mblk_t *imp, mblk_t **omp, if ((tp->t_state & TS_MEUC) && tp->t_eucign == 0 && NOTASCII(c)) { tp->t_eucign = - tp->t_csmethods.ldterm_memwidth( - c, (void *)tp); + tp->t_csmethods.ldterm_memwidth( + c, (void *)tp); tp->t_scratch_len = tp->t_eucign; if (tp->t_csdata.codeset_type != LDTERM_CS_TYPE_UTF8) { tp->t_col += -tp->t_csmethods.ldterm_dispwidth(c, (void *)tp, tp->t_modes.c_lflag & ECHOCTL); + tp-> + t_csmethods. + ldterm_dispwidth(c, + (void *)tp, + tp->t_modes.c_lflag & + ECHOCTL); } } @@ -3708,9 +3564,9 @@ tp->t_csmethods.ldterm_dispwidth(c, (void *)tp, tp->t_modes.c_lflag & ECHOCTL); bytes_to_move = bytes_left; if (tp->t_state & TS_MEUC) { bytes_moved = movtuc(bytes_to_move, - ibp->b_rptr, obp->b_wptr, - (tp->t_modes.c_oflag & OLCUC ? - elcuctab : enotrantab)); + ibp->b_rptr, obp->b_wptr, + (tp->t_modes.c_oflag & OLCUC ? + elcuctab : enotrantab)); } else { bytes_moved = movtuc(bytes_to_move, ibp->b_rptr, obp->b_wptr, @@ -3754,15 +3610,15 @@ tp->t_csmethods.ldterm_dispwidth(c, (void *)tp, tp->t_modes.c_lflag & ECHOCTL); if ((tp->t_state & TS_MEUC) && tp->t_eucign == 0 && NOTASCII(c)) { tp->t_eucign = tp->t_csmethods.ldterm_memwidth( - c, (void *)tp); + c, (void *)tp); tp->t_scratch_len = tp->t_eucign; if (tp->t_csdata.codeset_type != LDTERM_CS_TYPE_UTF8) { tp->t_col += tp->t_csmethods.ldterm_dispwidth(c, - (void *)tp, - tp->t_modes.c_lflag & ECHOCTL); + (void *)tp, + tp->t_modes.c_lflag & ECHOCTL); } } @@ -4077,7 +3933,7 @@ tp->t_csmethods.ldterm_dispwidth(c, (void *)tp, tp->t_modes.c_lflag & ECHOCTL); bp->b_datap->db_type = M_DELAY; *bp->b_wptr++ = - (uchar_t)count; + (uchar_t)count; putnext(q, bp); } } @@ -4311,17 +4167,13 @@ ldterm_do_ioctl(queue_t *q, mblk_t *mp) oldmodes = tp->t_amodes; tp->t_amodes.c_iflag = - (tp->t_amodes.c_iflag & 0xffff0000 | - cb->c_iflag); + (tp->t_amodes.c_iflag & 0xffff0000 | cb->c_iflag); tp->t_amodes.c_oflag = - (tp->t_amodes.c_oflag & 0xffff0000 | - cb->c_oflag); + (tp->t_amodes.c_oflag & 0xffff0000 | cb->c_oflag); tp->t_amodes.c_cflag = - (tp->t_amodes.c_cflag & 0xffff0000 | - cb->c_cflag); + (tp->t_amodes.c_cflag & 0xffff0000 | cb->c_cflag); tp->t_amodes.c_lflag = - (tp->t_amodes.c_lflag & 0xffff0000 | - cb->c_lflag); + (tp->t_amodes.c_lflag & 0xffff0000 | cb->c_lflag); bcopy(cb->c_cc, tp->t_modes.c_cc, NCC); /* TCGETS returns amodes, so update that too */ @@ -4543,11 +4395,14 @@ ldterm_do_ioctl(queue_t *q, mblk_t *mp) * this line! */ if (tp->t_msglen) { - tp->t_eucp = tp->t_eucp_mp->b_rptr; + tp->t_eucp = + tp->t_eucp_mp->b_rptr; for (i = tp->t_msglen; i; i--) *tp->t_eucp++ = 1; - } else - tp->t_eucp = tp->t_eucp_mp->b_rptr; + } else { + tp->t_eucp = + tp->t_eucp_mp->b_rptr; + } } /* doing multi-byte handling */ tp->t_state |= TS_MEUC; @@ -4566,19 +4421,19 @@ ldterm_do_ioctl(queue_t *q, mblk_t *mp) */ bzero(&tp->t_csdata.eucpc_data, (sizeof (ldterm_eucpc_data_t) * - LDTERM_CS_MAX_CODESETS)); + LDTERM_CS_MAX_CODESETS)); tp->t_csdata.eucpc_data[0].byte_length = - tp->eucwioc.eucw[1]; + tp->eucwioc.eucw[1]; tp->t_csdata.eucpc_data[0].screen_width = - tp->eucwioc.scrw[1]; + tp->eucwioc.scrw[1]; tp->t_csdata.eucpc_data[1].byte_length = - tp->eucwioc.eucw[2]; + tp->eucwioc.eucw[2]; tp->t_csdata.eucpc_data[1].screen_width = - tp->eucwioc.scrw[2]; + tp->eucwioc.scrw[2]; tp->t_csdata.eucpc_data[2].byte_length = - tp->eucwioc.eucw[3]; + tp->eucwioc.eucw[3]; tp->t_csdata.eucpc_data[2].screen_width = - tp->eucwioc.scrw[3]; + tp->eucwioc.scrw[3]; tp->t_csdata.version = LDTERM_DATA_VERSION; tp->t_csdata.codeset_type = LDTERM_CS_TYPE_EUC; /* @@ -4587,7 +4442,7 @@ ldterm_do_ioctl(queue_t *q, mblk_t *mp) * the maximum possible. */ tp->t_csdata.csinfo_num = - LDTERM_CS_TYPE_EUC_MAX_SUBCS; + LDTERM_CS_TYPE_EUC_MAX_SUBCS; if (tp->t_csdata.locale_name != (char *)NULL) { kmem_free(tp->t_csdata.locale_name, strlen(tp->t_csdata.locale_name) + 1); @@ -4664,10 +4519,10 @@ ldterm_do_ioctl(queue_t *q, mblk_t *mp) } if ((csdp->codeset_type == LDTERM_CS_TYPE_EUC && - csdp->csinfo_num > LDTERM_CS_TYPE_EUC_MAX_SUBCS) || + csdp->csinfo_num > LDTERM_CS_TYPE_EUC_MAX_SUBCS) || (csdp->codeset_type == LDTERM_CS_TYPE_PCCS && - (csdp->csinfo_num < LDTERM_CS_TYPE_PCCS_MIN_SUBCS || - csdp->csinfo_num > LDTERM_CS_TYPE_PCCS_MAX_SUBCS))) { + (csdp->csinfo_num < LDTERM_CS_TYPE_PCCS_MIN_SUBCS || + csdp->csinfo_num > LDTERM_CS_TYPE_PCCS_MAX_SUBCS))) { miocnak(q, mp, 0, ERANGE); return; } @@ -4750,7 +4605,7 @@ ldterm_do_ioctl(queue_t *q, mblk_t *mp) if (!(tp->t_eucp_mp = allocb(CANBSIZ, BPRI_HI))) { cmn_err(CE_WARN, - "Can't allocate eucp_mp"); + "Can't allocate eucp_mp"); miocnak(q, mp, 0, ENOSR); return; } @@ -4781,8 +4636,8 @@ ldterm_do_ioctl(queue_t *q, mblk_t *mp) tp->t_csdata.codeset_type = csdp->codeset_type; tp->t_csdata.csinfo_num = csdp->csinfo_num; bcopy(csdp->eucpc_data, tp->t_csdata.eucpc_data, - sizeof (ldterm_eucpc_data_t) * - LDTERM_CS_MAX_CODESETS); + sizeof (ldterm_eucpc_data_t) * + LDTERM_CS_MAX_CODESETS); tp->t_csmethods = cs_methods[csdp->codeset_type]; if (csdp->codeset_type == LDTERM_CS_TYPE_EUC) { @@ -4790,19 +4645,19 @@ ldterm_do_ioctl(queue_t *q, mblk_t *mp) tp->eucwioc.scrw[0] = 1; tp->eucwioc.eucw[1] = - csdp->eucpc_data[0].byte_length; + csdp->eucpc_data[0].byte_length; tp->eucwioc.scrw[1] = - csdp->eucpc_data[0].screen_width; + csdp->eucpc_data[0].screen_width; tp->eucwioc.eucw[2] = - csdp->eucpc_data[1].byte_length + 1; + csdp->eucpc_data[1].byte_length + 1; tp->eucwioc.scrw[2] = - csdp->eucpc_data[1].screen_width; + csdp->eucpc_data[1].screen_width; tp->eucwioc.eucw[3] = - csdp->eucpc_data[2].byte_length + 1; + csdp->eucpc_data[2].byte_length + 1; tp->eucwioc.scrw[3] = - csdp->eucpc_data[2].screen_width; + csdp->eucpc_data[2].screen_width; } else { /* * We are not going to use this data @@ -4844,7 +4699,7 @@ ldterm_do_ioctl(queue_t *q, mblk_t *mp) } if (locale_name_sz > 1) { tp->t_csdata.locale_name = (char *)kmem_alloc( - locale_name_sz, KM_SLEEP); + locale_name_sz, KM_SLEEP); (void) strcpy(tp->t_csdata.locale_name, csdp->locale_name); } else { @@ -4873,12 +4728,12 @@ ldterm_do_ioctl(queue_t *q, mblk_t *mp) csdp->pad = tp->t_csdata.pad; if (tp->t_csdata.locale_name) { (void) strcpy(csdp->locale_name, - tp->t_csdata.locale_name); + tp->t_csdata.locale_name); } else { csdp->locale_name[0] = '\0'; } bcopy(tp->t_csdata.eucpc_data, csdp->eucpc_data, - sizeof (ldterm_eucpc_data_t) * LDTERM_CS_MAX_CODESETS); + sizeof (ldterm_eucpc_data_t) * LDTERM_CS_MAX_CODESETS); /* * If the codeset is an EUC codeset and if it has 2nd and/or * 3rd supplementary codesets, we subtract one from each @@ -4993,7 +4848,7 @@ ldterm_ioctl_reply(queue_t *q, mblk_t *mp) * stream head eventually. */ struct termios *cb = - (struct termios *)mp->b_cont->b_rptr; + (struct termios *)mp->b_cont->b_rptr; /* * cflag has cflags sent upstream by the @@ -5015,7 +4870,7 @@ ldterm_ioctl_reply(queue_t *q, mblk_t *mp) * eventually. */ struct termio *cb = - (struct termio *)mp->b_cont->b_rptr; + (struct termio *)mp->b_cont->b_rptr; cb->c_iflag = tp->t_amodes.c_iflag; /* all except the */ cb->c_oflag = tp->t_amodes.c_oflag; /* cb->c_cflag */ @@ -5043,8 +4898,7 @@ vmin_satisfied(queue_t *q, ldtermstd_state_t *tp, int sendup) { ASSERT(q); if (tp->t_vtid != 0) { - DEBUG4(("vmin_satisfied: cancelled timer id %d\n", - tp->t_vtid)); + DEBUG4(("vmin_satisfied: cancelled timer id %d\n", tp->t_vtid)); (void) quntimeout(q, tp->t_vtid); tp->t_vtid = 0; } @@ -5088,11 +4942,11 @@ vmin_settimer(queue_t *q) if (V_MIN && V_TIME) { /* EMPTY */ DEBUG4(("vmin_settimer: timer restarted, old tid=%d\n", - tp->t_vtid)); + tp->t_vtid)); } else { /* EMPTY */ DEBUG4(("vmin_settimer: tid = %d was still active!\n", - tp->t_vtid)); + tp->t_vtid)); } (void) quntimeout(q, tp->t_vtid); tp->t_vtid = 0; @@ -5499,12 +5353,22 @@ static int __ldterm_memwidth_utf8(uchar_t c, void *p) { ldtermstd_state_t *tp = (ldtermstd_state_t *)p; + int len; - /* This is to silence the lint. */ + /* + * If the codeset type doesn't match, we treat them as + * an illegal character and return 1. + */ if (tp->t_csdata.codeset_type != LDTERM_CS_TYPE_UTF8) return (1); - return ((int)utf8_byte_length_tbl[c]); + len = u8_number_of_bytes[c]; + + /* + * If this is a start of an illegal character, we treat + * such as an 1 byte character and screen out. + */ + return ((len <= 0) ? 1 : len); } static uchar_t @@ -5517,29 +5381,29 @@ ldterm_utf8_width(uchar_t *u8, int length) if (length == 0) return ('\0'); - j = utf8_byte_length_tbl[u8[0]] - 1; + j = u8_number_of_bytes[u8[0]] - 1; /* * If the UTF-8 character is out of UTF-16 code range, or, * if it is either an ASCII character or an invalid leading byte for * a UTF-8 character, return 1. */ - if (length > 4 || j == 0) + if (length > 4 || j <= 0) return ('\1'); - intcode = u8[0] & masks_tbl[j]; + intcode = u8[0] & u8_masks_tbl[j]; for (i = 1; j > 0; j--, i++) { /* - * The following additional checking is needed to - * conform to the "UTF-8 Corrigendum" of the Unicode 3.1 - * standard. + * The following additional checking is needed to conform to + * the "UTF-8 Corrigendum" introduced at the Unicode 3.1 and + * then updated one more time at the Unicode 3.2. */ if (i == 1) { - if (u8[i] < valid_min_2nd_byte[u8[0]] || - u8[i] > valid_max_2nd_byte[u8[0]]) + if (u8[i] < u8_valid_min_2nd_byte[u8[0]] || + u8[i] > u8_valid_max_2nd_byte[u8[0]]) return ('\1'); } else if (u8[i] < (uchar_t)LDTERM_CS_TYPE_UTF8_MIN_BYTE || - u8[i] > (uchar_t)LDTERM_CS_TYPE_UTF8_MAX_BYTE) + u8[i] > (uchar_t)LDTERM_CS_TYPE_UTF8_MAX_BYTE) return ('\1'); /* @@ -5552,22 +5416,27 @@ ldterm_utf8_width(uchar_t *u8, int length) * six bits from the new byte. */ intcode = (intcode << LDTERM_CS_TYPE_UTF8_SHIFT_BITS) | - (u8[i] & LDTERM_CS_TYPE_UTF8_BIT_MASK); + (u8[i] & LDTERM_CS_TYPE_UTF8_BIT_MASK); } + i = 0; if (intcode <= LDTERM_CS_TYPE_UTF8_MAX_P00) { /* Basic Multilingual Plane. */ i = intcode / 4; j = intcode % 4; switch (j) { case 0: - return (ldterm_ucode[0][i].u0); + i = ldterm_ucode[0][i].u0; + break; case 1: - return (ldterm_ucode[0][i].u1); + i = ldterm_ucode[0][i].u1; + break; case 2: - return (ldterm_ucode[0][i].u2); + i = ldterm_ucode[0][i].u2; + break; case 3: - return (ldterm_ucode[0][i].u3); + i = ldterm_ucode[0][i].u3; + break; } } else if (intcode <= LDTERM_CS_TYPE_UTF8_MAX_P01) { /* Secondary Multilingual Plane. */ @@ -5576,35 +5445,55 @@ ldterm_utf8_width(uchar_t *u8, int length) j = intcode % 4; switch (j) { case 0: - return (ldterm_ucode[1][i].u0); + i = ldterm_ucode[1][i].u0; + break; case 1: - return (ldterm_ucode[1][i].u1); + i = ldterm_ucode[1][i].u1; + break; case 2: - return (ldterm_ucode[1][i].u2); + i = ldterm_ucode[1][i].u2; + break; case 3: - return (ldterm_ucode[1][i].u3); + i = ldterm_ucode[1][i].u3; + break; } } else if ((intcode >= LDTERM_CS_TYPE_UTF8_MIN_CJKEXTB && - intcode <= LDTERM_CS_TYPE_UTF8_MAX_CJKEXTB) || - (intcode >= LDTERM_CS_TYPE_UTF8_MIN_CJKCOMP && - intcode <= LDTERM_CS_TYPE_UTF8_MAX_CJKCOMP) || - (intcode >= LDTERM_CS_TYPE_UTF8_MIN_P15 && - intcode <= LDTERM_CS_TYPE_UTF8_MAX_P15) || - (intcode >= LDTERM_CS_TYPE_UTF8_MIN_P16 && - intcode <= LDTERM_CS_TYPE_UTF8_MAX_P16)) { + intcode <= LDTERM_CS_TYPE_UTF8_MAX_CJKEXTB) || + (intcode >= LDTERM_CS_TYPE_UTF8_MIN_CJKCOMP && + intcode <= LDTERM_CS_TYPE_UTF8_MAX_CJKCOMP) || + (intcode >= LDTERM_CS_TYPE_UTF8_MIN_P15 && + intcode <= LDTERM_CS_TYPE_UTF8_MAX_P15) || + (intcode >= LDTERM_CS_TYPE_UTF8_MIN_P16 && + intcode <= LDTERM_CS_TYPE_UTF8_MAX_P16)) { /* * Supplementary Plane for CJK Ideographs and * Private Use Planes. */ return ('\2'); } else if ((intcode >= LDTERM_CS_TYPE_UTF8_MIN_P14 && - intcode <= LDTERM_CS_TYPE_UTF8_MAX_P14) || - (intcode >= LDTERM_CS_TYPE_UTF8_MIN_VARSEL && - intcode <= LDTERM_CS_TYPE_UTF8_MAX_VARSEL)) { - /* Special Purpose Plane. */ + intcode <= LDTERM_CS_TYPE_UTF8_MAX_P14) || + (intcode >= LDTERM_CS_TYPE_UTF8_MIN_VARSEL && + intcode <= LDTERM_CS_TYPE_UTF8_MAX_VARSEL)) { + /* + * Some Special Purpose Plane characters: + * These are like control characters and not printable. + */ return ('\0'); } - /* Anything else including invalid characters, we return 1. */ - return ('\1'); + /* + * We return the display width of 1 for all character code points + * that we didn't catch from the above logic and also for combining + * and conjoining characters with width value of zero. + * + * In particular, the reason why we are returning 1 for combining + * and conjoining characters is because the GUI-based terminal + * emulators are not yet capable of properly handling such characters + * and in most of the cases, they just treat such characters as if + * they occupy a display cell. If the terminal emulators are capable of + * handling the characters correctly, then, this logic of returning + * 1 should be revisited and changed. See CR 6660526 for more + * details on this. + */ + return ((i == 0) ? '\1' : (uchar_t)i); } |