From 7a5bcd1bb16268b8d9091f75b1372cefeef21598 Mon Sep 17 00:00:00 2001 From: koron Date: Sun, 20 Sep 2009 02:27:32 +0000 Subject: [PATCH 08/36] =?UTF-8?q?=20=20*=20VC9(VisualStudio2008)=E3=81=A7?= =?UTF-8?q?=E3=81=AE64bit=E7=89=88=E3=81=AE=E3=82=B3=E3=83=B3=E3=83=91?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --HG-- extra : convert_revision : svn%3A1dcf550d-b01c-dc11-aeac-0020ed62593b/trunk%40176 --- doc/README_j.txt | 5 +++-- src/charset.c | 9 +++++---- src/filename.c | 26 ++++++++++++++++++-------- src/migemo.c | 19 ++++++++++++++++--- src/migemo.rc | 14 +++++++------- src/wordbuf.c | 12 +++++++++--- src/wordlist.c | 12 ++++++++++-- 7 files changed, 68 insertions(+), 29 deletions(-) diff --git a/doc/README_j.txt b/doc/README_j.txt index cb53153..56ca10d 100644 --- a/doc/README_j.txt +++ b/doc/README_j.txt @@ -2,7 +2,7 @@ C/Migemo Since: 15-Aug-2001 Version: 1.2.0 Author: MURAOKA Taro (KoRoN) - Last Change: 19-Sep-2009. + Last Change: 20-Sep-2009. 説明 C/MigemoはMigemo(Ruby/Migemo)をC言語で実装したものです。C/Migemoライブラリを @@ -339,7 +339,8 @@ C/Migemo 更新箇所 {{{1 ● (1.3 開発版) - VS2009でのコンパイルに対応 + VC9(VisualStudio2008)での64bit版のコンパイルに対応 + VC9(VisualStudio2008)でのコンパイルに対応 ローマ字が子音で終わる際に「xtu{子音}{母音}」を加えるように変更 configureの--prefixが機能していなかった問題の修正 生queryでの辞書検索をignore caseに diff --git a/src/charset.c b/src/charset.c index ea07535..6024944 100644 --- a/src/charset.c +++ b/src/charset.c @@ -3,12 +3,13 @@ * charset.c - * * Written By: MURAOKA Taro - * Last Change: 19-Jun-2004. + * Last Change: 20-Sep-2009. */ #define BUFLEN_DETECT 4096 #include +#include #include "charset.h" int @@ -305,10 +306,10 @@ charset_detect_file(const char* path) if ((fp = fopen(path, "rt")) != NULL) { unsigned char buf[BUFLEN_DETECT]; - int len = fread(buf, sizeof(buf[0]), sizeof(buf), fp); + size_t len = fread(buf, sizeof(buf[0]), sizeof(buf), fp); fclose(fp); - if (len > 0) - charset = charset_detect_buf(buf, len); + if (len > 0 && len <= INT_MAX) + charset = charset_detect_buf(buf, (int)len); } return charset; } diff --git a/src/filename.c b/src/filename.c index 7cb81f2..ec1306f 100644 --- a/src/filename.c +++ b/src/filename.c @@ -2,11 +2,21 @@ /* * filename.c - Operate filename. * - * Last change: 15-May-2002. + * Last change: 20-Sep-2009. * Written by: Muraoka Taro */ #include +#include + + static int +my_strlen(const char* s) +{ + size_t len; + + len = strlen(s); + return len <= INT_MAX ? (int)len : INT_MAX; +} /* * Cut out base string of filename from filepath. If base is NULL, then @@ -16,7 +26,7 @@ filename_base(char *base, const char *path) { int i; - int len = strlen(path) - 1; + int len = my_strlen(path) - 1; int end; for (i = len; i >= 0; --i) @@ -52,7 +62,7 @@ filename_directory(char *dir, const char *path) { int i; - for (i = strlen(path) - 1; i >= 0; --i) + for (i = my_strlen(path) - 1; i >= 0; --i) if (path[i] == '\\' || path[i] == '/') break; if (i <= 0) @@ -77,7 +87,7 @@ filename_directory(char *dir, const char *path) filename_extension(char *ext, const char *path) { int i; - int len = strlen(path); + int len = my_strlen(path); for (i = len - 1; i >= 0; --i) if (path[i] == '.') @@ -101,7 +111,7 @@ filename_extension(char *ext, const char *path) filename_filename(char *name, const char *path) { int i; - int len = strlen(path); + int len = my_strlen(path); for (i = len - 1; i >= 0; --i) if (path[i] == '\\' || path[i] == '/') @@ -134,13 +144,13 @@ filename_generate(char *filepath, const char *dir, const char *base, strcat(filepath, dir); strcat(filepath, "/"); } - len += strlen(dir) + 1; + len += my_strlen(dir) + 1; } if (base) { if (filepath) strcat(filepath, base); - len += strlen(base); + len += my_strlen(base); } if (ext) { @@ -149,7 +159,7 @@ filename_generate(char *filepath, const char *dir, const char *base, strcat(filepath, "."); strcat(filepath, ext); } - len += 1 + strlen(ext); + len += 1 + my_strlen(ext); } return len; } diff --git a/src/migemo.c b/src/migemo.c index 23525ec..75491e3 100644 --- a/src/migemo.c +++ b/src/migemo.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "wordbuf.h" #include "wordlist.h" @@ -51,6 +52,15 @@ struct _migemo static const unsigned char VOWEL_CHARS[] = "aiueo"; + static int +my_strlen(const char* s) +{ + size_t len; + + len = strlen(s); + return len <= INT_MAX ? (int)len : INT_MAX; +} + static mtree_p load_mtree_dictionary(mtree_p mtree, const char* dict_file) { @@ -363,7 +373,7 @@ add_dubious_roma(migemo* object, rxgen* rx, unsigned char* query) int len; char *buf; - if (!(len = strlen(query))) + if (!(len = my_strlen(query))) return; /* * ローマ字の末尾のアレンジのためのバッファを確保する。 @@ -415,12 +425,14 @@ parse_query(migemo* object, const unsigned char* query) while (1) { int len, upper; + int sum = 0; if (!object->char2int || (len = object->char2int(curr, NULL)) < 1) len = 1; start = curr; upper = (len == 1 && isupper(*curr) && isupper(curr[1])); curr += len; + sum += len; while (1) { if (!object->char2int || (len = object->char2int(curr, NULL)) < 1) @@ -428,11 +440,12 @@ parse_query(migemo* object, const unsigned char* query) if (*curr == '\0' || (len == 1 && (isupper(*curr) != 0) != upper)) break; curr += len; + sum += len; } /* 文節を登録する */ if (start && start < curr) { - *pp = wordlist_open_len(start, curr - start); + *pp = wordlist_open_len(start, sum); pp = &(*pp)->next; } if (*curr == '\0') @@ -450,7 +463,7 @@ query_a_word(migemo* object, unsigned char* query) unsigned char* zen; unsigned char* han; unsigned char* lower; - int len = strlen(query); + int len = my_strlen(query); /* query自信はもちろん候補に加える */ object->addword(object, query); diff --git a/src/migemo.rc b/src/migemo.rc index 641b1cf..f2ebd2b 100644 --- a/src/migemo.rc +++ b/src/migemo.rc @@ -28,8 +28,8 @@ LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2002,6,22,17 - PRODUCTVERSION 1,1,0,7 + FILEVERSION 1,3,0,175 + PRODUCTVERSION 1,3,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -46,15 +46,15 @@ BEGIN BEGIN VALUE "Comments", "ローマ字による日本語検索正規表現生成ライブラリ\0" VALUE "CompanyName", "KaoriYa\0" - VALUE "FileDescription", "migemo in C\0" - VALUE "FileVersion", "2002, 6, 22, 17\0" - VALUE "InternalName", "migemo\0" - VALUE "LegalCopyright", "2002 (C) MURAOKA Taro (KoRoN)/KaoriYa\0" + VALUE "FileDescription", "Migemo written in C\0" + VALUE "FileVersion", "1, 3, 0, 175\0" + VALUE "InternalName", "CMigemo\0" + VALUE "LegalCopyright", "2009 (C) MURAOKA Taro (KoRoN)/KaoriYa\0" VALUE "LegalTrademarks", "C/Migemo library\0" VALUE "OriginalFilename", "migemo.dll\0" VALUE "PrivateBuild", "\0" VALUE "ProductName", "Migemo DLL\0" - VALUE "ProductVersion", "1, 1, 0, 7\0" + VALUE "ProductVersion", "1, 3, 0, 0\0" VALUE "SpecialBuild", "\0" END END diff --git a/src/wordbuf.c b/src/wordbuf.c index bb133cd..00a1112 100644 --- a/src/wordbuf.c +++ b/src/wordbuf.c @@ -3,7 +3,7 @@ * wordbuf.h - * * Written By: MURAOKA Taro - * Last Change: 04-May-2004. + * Last Change: 20-Sep-2009. */ #include @@ -110,9 +110,15 @@ wordbuf_add(wordbuf_p p, unsigned char ch) int wordbuf_cat(wordbuf_p p, const unsigned char* sz) { - int len; + int len = 0; - if (sz && (len = strlen(sz)) > 0) + if (sz != NULL) + { + size_t l = strlen(sz); + len = l < INT_MAX ? (int)l : INT_MAX; + } + + if (len > 0) { int newlen = p->last + len + 1; diff --git a/src/wordlist.c b/src/wordlist.c index 299c89e..fa4dd78 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -3,11 +3,12 @@ * wordlist.h - * * Written By: MURAOKA Taro - * Last Change: 04-May-2004. + * Last Change: 20-Sep-2009. */ #include #include +#include #include "wordlist.h" int n_wordlist_open = 0; @@ -43,7 +44,14 @@ wordlist_open_len(const unsigned char* ptr, int len) wordlist_p wordlist_open(const unsigned char* ptr) { - return ptr ? wordlist_open_len(ptr, strlen(ptr)) : NULL; + wordlist_p p = NULL; + if (ptr != NULL) + { + size_t len; + len = strlen(ptr); + p = wordlist_open_len(ptr, (len < INT_MAX ? (int)len : INT_MAX)); + } + return p; } void -- 2.39.2