Skip to content

Commit

Permalink
2.1.2
Browse files Browse the repository at this point in the history
・EUC-JIS-2004のSS2(0x8E)またはSS3(0x8F)の直後のバイト列において最上位ビットを無視していたバグを修正しました。
 ・正常系の処理結果に変更はありません。
 ・SS2(0x8E)またはSS3(0x8F)の直後にASCII文字があるような不正な文字列をエラーとするようになります。
  • Loading branch information
nathancorvussolis committed Nov 28, 2015
1 parent 6479f9b commit 8c60a21
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

-------------------------------------------------------------------------------

crvskkserv 2.1.1
crvskkserv 2.1.2

-------------------------------------------------------------------------------

Expand Down
8 changes: 4 additions & 4 deletions crvskkserv/crvskkserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#pragma once

#define RC_PRODUCT "crvskkserv"
#define RC_VERSION "2.1.1"
#define RC_VERSION_D 2,1,1,0
#define RC_TITLE "crvskkserv (ver. 2.1.1)"
#define RC_VERSION "2.1.2"
#define RC_VERSION_D 2,1,2,0
#define RC_TITLE "crvskkserv (ver. 2.1.2)"
#define RC_AUTHOR "nathancorvussolis"

#define APP_TITLE L"crvskkserv"
#define APP_VERSION L"2.1.1"
#define APP_VERSION L"2.1.2"
#define RES_VER RC_PRODUCT "/" RC_VERSION " "

#define REQ_END '0'
Expand Down
33 changes: 18 additions & 15 deletions crvskkserv/eucjis2004.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ size_t UcpToWideChar(UCSCHAR ucp, PWCHAR first, PWCHAR second)

size_t EucJis2004ToUcp(LPCSTR src, size_t srcsize, PUCSCHAR ucp1, PUCSCHAR ucp2)
{
CONST CHAR as = 0x00;
CONST CHAR ae = 0x7F;
CONST CHAR mask = 0x7F;
CONST CHAR ss2 = 0x0E;
CONST CHAR ss3 = 0x0F;
CONST CHAR ss2 = 0x0E | ~mask;
CONST CHAR ss3 = 0x0F | ~mask;
CONST CHAR ejs = 0x21;
CONST CHAR eje = 0x7E;
CHAR ej[2];
Expand All @@ -74,29 +76,29 @@ size_t EucJis2004ToUcp(LPCSTR src, size_t srcsize, PUCSCHAR ucp1, PUCSCHAR ucp2)
*ucp1 = 0;
*ucp2 = 0;

if(src[0] >= 0x00 && src[0] <= 0x7F) //ASCII
if(as <= src[0] && src[0] <= ae) //ASCII
{
*ucp1 = src[0];
*ucp2 = 0;
srcused = 1;
}
else
{
switch(src[0] & mask)
switch(src[0])
{
case ss3: // JIS X 0213 Plane 2
if(srcsize < 3)
{
break;
}

ej[0] = src[1] & mask;
ej[1] = src[2] & mask;
ej[0] = src[1] - ~mask;
ej[1] = src[2] - ~mask;

if((ej[0] >= ejs && ej[0] <= eje) && (ej[1] >= ejs && ej[1] <= eje))
{
*ucp1 = 0;
if(euc2i[ej[0] - ejs] != 0)
if(euc2i[ej[0] - ejs] != 0 && euc2i[ej[0] - ejs] <= ROW2NUM)
{
*ucp1 = euc2[euc2i[ej[0] - ejs] - 1][ej[1] - ejs];
}
Expand All @@ -111,7 +113,7 @@ size_t EucJis2004ToUcp(LPCSTR src, size_t srcsize, PUCSCHAR ucp1, PUCSCHAR ucp2)
break;
}

ej[0] = src[1] & mask;
ej[0] = src[1] - ~mask;

if(ej[0] >= ejs && ej[0] <= eje)
{
Expand All @@ -127,8 +129,8 @@ size_t EucJis2004ToUcp(LPCSTR src, size_t srcsize, PUCSCHAR ucp1, PUCSCHAR ucp2)
break;
}

ej[0] = src[0] & mask;
ej[1] = src[1] & mask;
ej[0] = src[0] - ~mask;
ej[1] = src[1] - ~mask;

if((ej[0] >= ejs && ej[0] <= eje) && (ej[1] >= ejs && ej[1] <= eje))
{
Expand Down Expand Up @@ -276,9 +278,9 @@ void AddNullEucJis2004(size_t *srcsize, size_t si, LPSTR dst, size_t *dstsize, s
BOOL WideCharToEucJis2004(LPCWSTR src, size_t *srcsize, LPSTR dst, size_t *dstsize)
{
CONST CHAR mask = 0x7F;
CONST CHAR ss2 = 0x0E | ~mask;
CONST CHAR ss3 = 0x0F | ~mask;
CONST CHAR ejs = 0x21;
CONST CHAR ss2 = 0x0E;
CONST CHAR ss3 = 0x0F;
size_t si = 0, di = 0, ss = -1;
WCHAR first, second;
UCSCHAR ucp;
Expand Down Expand Up @@ -399,7 +401,8 @@ BOOL WideCharToEucJis2004(LPCWSTR src, size_t *srcsize, LPSTR dst, size_t *dstsi
exist = TRUE;
break;
}
else if(euc2i[i] != 0 && ucp == euc2[euc2i[i] - 1][j]) // JIS X 0213 Plane 2
else if(euc2i[i] != 0 && euc2i[i] <= ROW2NUM &&
ucp == euc2[euc2i[i] - 1][j]) // JIS X 0213 Plane 2
{
if(*dstsize <= di + 3) //limit
{
Expand All @@ -408,7 +411,7 @@ BOOL WideCharToEucJis2004(LPCWSTR src, size_t *srcsize, LPSTR dst, size_t *dstsi
}
if(dst != NULL)
{
*(dst + di) = ss3 | ~mask;
*(dst + di) = ss3;
*(dst + di + 1) = (ejs + i) | ~mask;
*(dst + di + 2) = (ejs + j) | ~mask;
}
Expand Down Expand Up @@ -442,7 +445,7 @@ BOOL WideCharToEucJis2004(LPCWSTR src, size_t *srcsize, LPSTR dst, size_t *dstsi
}
if(dst != NULL)
{
*(dst + di) = ss2 | ~mask;
*(dst + di) = ss2;
*(dst + di + 1) = (ejs + i) | ~mask;
}
di += 2;
Expand Down

0 comments on commit 8c60a21

Please sign in to comment.