From 1b4f138ef87332c921b315c18f84462bd1504552 Mon Sep 17 00:00:00 2001 From: berryplus Date: Sat, 25 Apr 2020 12:58:36 +0900 Subject: [PATCH] =?UTF-8?q?=E5=BC=8F=E3=81=AB=E5=90=8D=E5=89=8D=E3=82=92?= =?UTF-8?q?=E4=BB=98=E3=81=91=E3=81=A6=E9=96=93=E9=81=95=E3=81=84=E3=82=92?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/typeprop/CImpExpManager.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sakura_core/typeprop/CImpExpManager.cpp b/sakura_core/typeprop/CImpExpManager.cpp index 3b1dd56b20..6ea86dbec4 100644 --- a/sakura_core/typeprop/CImpExpManager.cpp +++ b/sakura_core/typeprop/CImpExpManager.cpp @@ -661,11 +661,14 @@ bool CImpExpRegex::Import( const wstring& sFileName, wstring& sErrMsg ) } if( k != -1 ) /* 3文字カラー名からインデックス番号に変換 */ { - if( 0 < MAX_REGEX_KEYWORDLISTLEN - keywordPos - 1 ){ + // pKeywordに書き込める残りサイズ(NUL終端分を含む) + const size_t cchAvailableSize = MAX_REGEX_KEYWORDLISTLEN - keywordPos; + + if( 0 < cchAvailableSize - 1 ){ regexKeyArr[count].m_nColorIndex = k; - wcsncpy_s( &pKeyword[keywordPos], std::min(MAX_REGEX_KEYWORDLEN, MAX_REGEX_KEYWORDLISTLEN - keywordPos - 1), p, _TRUNCATE ); + wcsncpy_s( &pKeyword[keywordPos], std::min(MAX_REGEX_KEYWORDLEN, cchAvailableSize), p, _TRUNCATE ); count++; - keywordPos += wcsnlen( &pKeyword[keywordPos], MAX_REGEX_KEYWORDLISTLEN - keywordPos ) + 1; + keywordPos += wcsnlen( &pKeyword[keywordPos], cchAvailableSize) + 1; }else{ sErrMsg = LS(STR_IMPEXP_REGEX2); }