From b1babd4b88f55bb2bb34d0df69108b4d9a20f612 Mon Sep 17 00:00:00 2001 From: Nishi Date: Wed, 23 Sep 2026 10:38:16 +0900 Subject: [PATCH] several fixes --- lib/sj4charset/conv.c | 4 ++-- lib/sj4core/init.c | 2 ++ lib/sj4ime/ime.c | 2 +- src/sj4test2/main.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/sj4charset/conv.c b/lib/sj4charset/conv.c index 6c20b11..bcc0178 100644 --- a/lib/sj4charset/conv.c +++ b/lib/sj4charset/conv.c @@ -190,7 +190,7 @@ int sj4_from_utf16(u_char* out, const u_char* in, int len) { out += eucjp_write(out, n); } - return out - o_out; + return (out - o_out) * sizeof(wchar_t); } static u_int eucjp_read(const u_char* in) { @@ -287,7 +287,7 @@ int sj4_to_utf16(u_char* out, const u_char* in, int len) { } } - return w_out - o_out; + return (w_out - o_out) * sizeof(wchar_t); } #endif diff --git a/lib/sj4core/init.c b/lib/sj4core/init.c index 93cdb11..bfa754c 100644 --- a/lib/sj4core/init.c +++ b/lib/sj4core/init.c @@ -79,6 +79,8 @@ Sj4Context* alloccontext(const char* dic) { DictFile* dict; DICTL* node; + if(ctx == NULL) return NULL; + if((ctx->work = calloc(1, sizeof(*ctx->work))) == NULL) { free(ctx); diff --git a/lib/sj4ime/ime.c b/lib/sj4ime/ime.c index 56c3085..3895010 100644 --- a/lib/sj4ime/ime.c +++ b/lib/sj4ime/ime.c @@ -173,7 +173,7 @@ void sj4_ime_key(Sj4Ime* ime, int key) { key = toupper(key); - if(ime->romabuf[strlen(ime->romabuf) - 1] == 'N' && !(key == 'A' || key == 'I' || key == 'U' || key == 'E' || key == 'O' || key == 'Y' || key == 'N')) { + if(strlen(ime->romabuf) > 0 && ime->romabuf[strlen(ime->romabuf) - 1] == 'N' && !(key == 'A' || key == 'I' || key == 'U' || key == 'E' || key == 'O' || key == 'Y' || key == 'N')) { ime->romabuf[strlen(ime->romabuf) + 1] = 0; ime->romabuf[strlen(ime->romabuf)] = 'N'; } diff --git a/src/sj4test2/main.c b/src/sj4test2/main.c index 858f1de..f45ef37 100644 --- a/src/sj4test2/main.c +++ b/src/sj4test2/main.c @@ -26,7 +26,7 @@ int main() { return 1; } - conv = sj4_ime_convbuf(ime); + conv = sj4_ime_convbuf(ime); kouho = sj4_ime_kouho(ime); #ifdef _WIN32