--- np2/codecnv/eucsjis.c 2005/02/12 12:13:56 1.1 +++ np2/codecnv/eucsjis.c 2005/04/01 15:35:48 1.2 @@ -5,23 +5,30 @@ UINT codecnv_euctosjis(char *dst, UINT dcnt, const char *src, UINT scnt) { UINT orgdcnt; + BOOL stringmode; UINT h; UINT l; - (void)scnt; // 判定してないのかよ if (src == NULL) { return(0); } - - orgdcnt = dcnt; if (dcnt == 0) { dst = NULL; + dcnt = (UINT)-1; + } + orgdcnt = dcnt; + stringmode = (((SINT)scnt) < 0); + if (stringmode) { + dcnt--; } - dcnt--; - while(dcnt) { + while(scnt > 0) { + scnt--; h = (UINT8)*src++; - if (h < 0x80) { // ascii - if (!h) { + if ((h == 0) && (stringmode)) { + break; + } + else if (h < 0x80) { // ascii + if (dcnt == 0) { break; } dcnt--; @@ -31,10 +38,17 @@ UINT codecnv_euctosjis(char *dst, UINT d } } else if (h == 0x8e) { + if (scnt == 0) { + break; + } + scnt--; l = (UINT8)*src++; if (!l) { break; } + if (dcnt == 0) { + break; + } dcnt--; if (dst) { dst[0] = (char)h; @@ -42,6 +56,10 @@ UINT codecnv_euctosjis(char *dst, UINT d } } else { + if (scnt == 0) { + break; + } + scnt--; l = (UINT8)*src++; if (!l) { break; @@ -67,8 +85,15 @@ UINT codecnv_euctosjis(char *dst, UINT d } } } - if (dst) { - dst[0] = '\0'; + if (dst != NULL) { + if (stringmode) { + *dst = '\0'; + } +#if 1 // 一応互換の為に NULLつける + else if (dcnt) { + *dst = '\0'; + } +#endif } return((UINT)(orgdcnt - dcnt)); }