ref: 7388792a124756a528666cb5c375ee919db9ca11
parent: 14cd6df332475cb6535b638104283ab12ae609c6
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun May 11 18:29:47 EDT 2014
tcs: prevent accidents with runes beyond 16-bit
--- a/sys/src/cmd/tcs/conv_big5.c
+++ b/sys/src/cmd/tcs/conv_big5.c
@@ -137,7 +137,7 @@
if(r < 128)
*p++ = r;
else {
- if(tab[r] != -1){
+ if(r < NRUNE && tab[r] != -1){
r = tab[r];
if(r >= BIG5MAX){
*p++ = 0xA1;
--- a/sys/src/cmd/tcs/conv_gb.c
+++ b/sys/src/cmd/tcs/conv_gb.c
@@ -115,7 +115,7 @@
if(r < 128)
*p++ = r;
else {
- if(tab[r] != -1){
+ if(r < NRUNE && tab[r] != -1){
r = tab[r];
*p++ = 0xA0 + (r/100);
*p++ = 0xA0 + (r%100);
--- a/sys/src/cmd/tcs/conv_gbk.c
+++ b/sys/src/cmd/tcs/conv_gbk.c
@@ -106,7 +106,7 @@
if(r < 0x80)
*p++ = r;
else {
- if(tab[r] != -1){
+ if(r < NRUNE && tab[r] != -1){
r = tab[r];
*p++ = (r>>8) & 0xFF;
*p++ = r & 0xFF;
--- a/sys/src/cmd/tcs/conv_jis.c
+++ b/sys/src/cmd/tcs/conv_jis.c
@@ -438,7 +438,7 @@
}
*p++ = r;
} else {
- if(tab[r] != -1){
+ if(r < NRUNE && tab[r] != -1){
if(state != jp2022){
*p++ = ESC; *p++ = '$'; *p++ = 'B';
state = jp2022;
@@ -478,7 +478,7 @@
if(r < 128)
*p++ = r;
else {
- if(tab[r] != -1){
+ if(r < NRUNE && tab[r] != -1){
hi = tab[r]/100 + ' ';
lo = tab[r]%100 + ' ';
J2S(hi, lo);
@@ -517,7 +517,7 @@
if(r < 128)
*p++ = r;
else {
- if(tab[r] != -1){
+ if(r < NRUNE && tab[r] != -1){
*p++ = 0x80 | (tab[r]/100 + ' ');
*p++ = 0x80 | (tab[r]%100 + ' ');
continue;
--- a/sys/src/cmd/tcs/conv_ksc.c
+++ b/sys/src/cmd/tcs/conv_ksc.c
@@ -141,7 +141,7 @@
if(r < 128)
*p++ = r;
else {
- if(tab[r] != -1){
+ if(r < NRUNE && tab[r] != -1){
*p++ = 0x80 | (tab[r]/94 + 0x21);
*p++ = 0x80 | (tab[r]%94 + 0x21);
continue;