summaryrefslogtreecommitdiff
path: root/Build/source/texk/ptexenc/kanjicnv.c
diff options
context:
space:
mode:
authorHironobu Yamashita <h.y.acetaminophen@gmail.com>2021-06-29 12:08:43 +0000
committerHironobu Yamashita <h.y.acetaminophen@gmail.com>2021-06-29 12:08:43 +0000
commit6cee5b73a7fb36a8a1abcdbd0d1be611d2be35f2 (patch)
treee5c2ee2f632c424ffbcbbb41bd3ebee322d27441 /Build/source/texk/ptexenc/kanjicnv.c
parent2edd8ec8e8169698e4dfb44b0f91c1bd3212f25c (diff)
ptexenc: always return 0 for invalid code conversion
git-svn-id: svn://tug.org/texlive/trunk@59749 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/ptexenc/kanjicnv.c')
-rw-r--r--Build/source/texk/ptexenc/kanjicnv.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/Build/source/texk/ptexenc/kanjicnv.c b/Build/source/texk/ptexenc/kanjicnv.c
index 75793863add..d93bbed5f1b 100644
--- a/Build/source/texk/ptexenc/kanjicnv.c
+++ b/Build/source/texk/ptexenc/kanjicnv.c
@@ -5,6 +5,18 @@
#include <ptexenc/c-auto.h>
#include <ptexenc/kanjicnv.h>
+boolean isJISkanji1(int c)
+{
+ c &= 0xff;
+ return (0x21 <= c && c <= 0x7e);
+}
+
+boolean isJISkanji2(int c)
+{
+ c &= 0xff;
+ return (0x21 <= c && c <= 0x7e);
+}
+
boolean isEUCkanji1(int c)
{
c &= 0xff;
@@ -32,11 +44,17 @@ boolean isSJISkanji2(int c)
/* EUC <=> JIS X 0208 code conversion */
int EUCtoJIS(int kcode)
{
+ if ((kcode<=0 || kcode>0x10000)) return 0;
+ if (!isEUCkanji1(HI(kcode))) return 0;
+ if (!isEUCkanji2(LO(kcode))) return 0;
return (kcode & 0x7f7f);
}
int JIStoEUC(int kcode)
{
+ if ((kcode<=0 || kcode>0x10000)) return 0;
+ if (!isJISkanji1(HI(kcode))) return 0;
+ if (!isJISkanji2(LO(kcode))) return 0;
return (kcode | 0x8080);
}
@@ -45,8 +63,9 @@ int SJIStoJIS(int kcode)
{
int byte1, byte2;
- byte1 = HI(kcode);
- byte2 = LO(kcode);
+ if ((kcode<=0 || kcode>0x10000)) return 0;
+ byte1 = HI(kcode); if (!isSJISkanji1(byte1)) return 0;
+ byte2 = LO(kcode); if (!isSJISkanji2(byte2)) return 0;
byte1 -= ( byte1>=0xa0 ) ? 0xc1 : 0x81;
kcode = ((byte1<<1) + 0x21)<<8;
if ( byte2 >= 0x9f ) {
@@ -63,8 +82,9 @@ int JIStoSJIS(int kcode)
int high, low;
int nh, nl;
- high = HI(kcode);
- low = LO(kcode);
+ if ((kcode<=0 || kcode>0x10000)) return 0;
+ high = HI(kcode); if (!isJISkanji1(high)) return 0;
+ low = LO(kcode); if (!isJISkanji2(low)) return 0;
nh = ((high-0x21)>>1) + 0x81;
if (nh > 0x9f) nh += 0x40;
if (high & 1) {
@@ -72,11 +92,7 @@ int JIStoSJIS(int kcode)
if (low > 0x5f) nl++;
} else
nl = low + 0x7e;
- if (isSJISkanji1(nh) && isSJISkanji2(nl)) {
- return HILO(nh, nl);
- } else {
- return 0x813f;
- }
+ return HILO(nh, nl);
}
/* Shift JIS <=> EUC Kanji code conversion */
@@ -94,8 +110,8 @@ int EUCtoSJIS(int kcode)
int KUTENtoJIS(int kcode)
{
/* in case of undefined in kuten code table */
- if (HI(kcode) == 0 || HI(kcode) > 95) return -1;
- if (LO(kcode) == 0 || LO(kcode) > 95) return -1;
+ if (HI(kcode) == 0 || HI(kcode) > 94) return 0;
+ if (LO(kcode) == 0 || LO(kcode) > 94) return 0;
return kcode + 0x2020;
}