From: NARUSE, Yui Date: Sat, 25 Oct 2008 15:28:08 +0000 (+0000) Subject: * Fix: NkfConvert isn't reentrant. patched by VA007219. X-Git-Tag: v2_0_9~33 X-Git-Url: http://git.osdn.net/view?p=nkf%2Fnkf.git;a=commitdiff_plain;h=af8d80cb3c6846be64b02bdaea83a9add04075e2 * Fix: NkfConvert isn't reentrant. patched by VA007219. --- diff --git a/nkf32dll.c b/nkf32dll.c index a3e8b89..75de2a0 100644 --- a/nkf32dll.c +++ b/nkf32dll.c @@ -6,9 +6,9 @@ /* ‚±‚¿‚ç‚̃o[ƒWƒ‡ƒ“‚àXV‚µ‚Ä‚­‚¾‚³‚¢B */ #define NKF_VERSIONW L"2.0.8" /* NKF_VERSION ‚̃ƒCƒh•¶Žš */ -#define DLL_VERSION "2.0.8.0 1" +#define DLL_VERSION "2.0.8.0 2" /* DLL‚ª•Ô‚· */ -#define DLL_VERSIONW L"2.0.8.0 1" +#define DLL_VERSIONW L"2.0.8.0 2" /* DLL‚ª•Ô‚· DLL_VERSION ‚̃ƒCƒh•¶Žš */ /* nkf32.dll main */ @@ -320,27 +320,38 @@ BOOL WINAPI GetNkfVersionSafeW(LPWSTR verStr,DWORD nBufferLength /*in TCHARs*/,L #endif /*UNICODESUPPORT*/ } +static LPSTR optStr0 = NULL; + int CALLBACK SetNkfOption(LPSTR optStr) { LPSTR p; + int len; if ( *optStr == '-' ) { - reinit(); - options(optStr); + len = strlen(optStr) + 1; + p = realloc(optStr0,len); + strcpy(p,optStr); } else { - p = malloc(strlen(optStr) + 2); - if ( p == NULL ) return -1; + len = strlen(optStr) + 2; + p = realloc(optStr0,len); *p = '-'; strcpy(p + 1,optStr); - reinit(); - options(p); - free(p); } + optStr0 = p; return 0; } +void options0(void) +{ + reinit(); + if ( optStr0 != NULL ) { + options(optStr0); + } +} + void CALLBACK NkfConvert(LPSTR outStr, LPCSTR inStr) { + options0(); std_putc_mode = 2; cout = outStr; noutmax = -1; @@ -355,6 +366,7 @@ void CALLBACK NkfConvert(LPSTR outStr, LPCSTR inStr) BOOL WINAPI NkfConvertSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/, LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/){ if ( inStr == NULL ) return FALSE; + options0(); std_putc_mode = 6; cout = outStr; noutmax = nOutBufferLength; @@ -378,7 +390,6 @@ void CALLBACK ToHankaku(LPSTR inStr) p = malloc(len); if ( p == NULL ) return; memcpy(p,inStr,len); - reinit(); options("-ZSs"); NkfConvert(inStr,p); free(p); @@ -386,34 +397,29 @@ void CALLBACK ToHankaku(LPSTR inStr) BOOL WINAPI ToHankakuSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/,LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/) { - reinit(); options("-ZSs"); return NkfConvertSafe(outStr,nOutBufferLength,lpBytesReturned,inStr,nInBufferLength); } void CALLBACK ToZenkakuKana(LPSTR outStr, LPCSTR inStr) { - reinit(); options("-Ss"); NkfConvert(outStr, inStr); } BOOL WINAPI ToZenkakuKanaSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/,LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/) { - reinit(); options("-Ss"); return NkfConvertSafe(outStr,nOutBufferLength,lpBytesReturned,inStr,nInBufferLength); } void CALLBACK EncodeSubject(LPSTR outStr ,LPCSTR inStr){ - reinit(); options("-jM"); NkfConvert(outStr, inStr); } BOOL WINAPI EncodeSubjectSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/,LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/) { - reinit(); options("-jM"); return NkfConvertSafe(outStr,nOutBufferLength,lpBytesReturned,inStr,nInBufferLength); }