Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

変換先バッファ確保の new で例外処理を行わないように std::nothrow 指定追加 #287

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions sakura_core/charset/CCodePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,7 @@ EConvertResult CCodePage::CPToUnicode(const CMemory& cSrc, CNativeW* pDst, int c
UINT codepage = CodePageExToMSCP(codepageEx);
int nDstCch = MultiByteToWideChar2(codepage, nToWideCharFlags, pSrc, nSrcLen, NULL, 0);
// 変換先バッファサイズとその確保
wchar_t* pDstBuffer;
try{
pDstBuffer = new wchar_t[nDstCch];
}catch( ... ){
pDstBuffer = NULL;
}
wchar_t* pDstBuffer = new (std::nothrow) wchar_t[nDstCch];
if( pDstBuffer == NULL ){
return RESULT_FAILURE;
}
Expand Down Expand Up @@ -209,12 +204,7 @@ EConvertResult CCodePage::UnicodeToCP(const CNativeW& cSrc, CMemory* pDst, int c
#endif
return RESULT_FAILURE;
}
char* pDstBuffer;
try{
pDstBuffer = new char[nBuffSize];
}catch( ... ){
pDstBuffer = NULL;
}
char* pDstBuffer = new (std::nothrow) char[nBuffSize];
if( pDstBuffer == NULL ){
return RESULT_FAILURE;
}
Expand Down
14 changes: 2 additions & 12 deletions sakura_core/charset/CEuc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ EConvertResult CEuc::EUCToUnicode(const CMemory& cSrc, CNativeW* pDstMem)
const char* pSrc = reinterpret_cast<const char*>( cSrc.GetRawPtr(&nSrcLen) );

// 変換先バッファサイズとその確保
wchar_t* pDst;
try{
pDst = new wchar_t[nSrcLen];
}catch( ... ){
pDst = NULL;
}
wchar_t* pDst = new (std::nothrow) wchar_t[nSrcLen];
if( pDst == NULL ){
return RESULT_FAILURE;
}
Expand Down Expand Up @@ -178,12 +173,7 @@ EConvertResult CEuc::UnicodeToEUC(const CNativeW& cSrc, CMemory* pDstMem)
int nSrcLen = cSrc.GetStringLength();

// 必要なバッファサイズを調べてメモリを確保
char* pDst;
try{
pDst = new char[nSrcLen * 2];
}catch( ... ){
pDst = NULL;
}
char* pDst = new (std::nothrow) char[nSrcLen * 2];
if( pDst == NULL ){
return RESULT_FAILURE;
}
Expand Down
16 changes: 3 additions & 13 deletions sakura_core/charset/CJis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,8 @@ EConvertResult CJis::JISToUnicode(const CMemory& cSrc, CNativeW* pDstMem, bool b


// 変換先バッファを取得
wchar_t* pDst;
try{
pDst = new wchar_t[nsrclen * 3 + 1];
if( pDst == NULL ){
return RESULT_FAILURE;
}
}catch( ... ){
wchar_t* pDst = new (std::nothrow) wchar_t[nsrclen * 3 + 1];
if( pDst == NULL ){
return RESULT_FAILURE;
}

Expand Down Expand Up @@ -466,12 +461,7 @@ EConvertResult CJis::UnicodeToJIS(const CNativeW& cSrc, CMemory* pDstMem)
int nSrcLen = cSrc.GetStringLength();

// 必要なバッファ容量を確認してバッファを確保
char* pDst;
try{
pDst = new char[nSrcLen * 8];
}catch( ... ){
pDst = NULL;
}
char* pDst = new (std::nothrow) char[nSrcLen * 8];
if( pDst == NULL ){
return RESULT_FAILURE;
}
Expand Down
14 changes: 2 additions & 12 deletions sakura_core/charset/CLatin1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,7 @@ EConvertResult CLatin1::Latin1ToUnicode( const CMemory& cSrc, CNativeW* pDstMem
const char* pSrc = reinterpret_cast<const char*>( cSrc.GetRawPtr(&nSrcLen) );

// 変換先バッファサイズを設定してメモリ領域確保
wchar_t* pDst;
try{
pDst = new wchar_t[nSrcLen];
}catch( ... ){
pDst = NULL;
}
wchar_t* pDst = new (std::nothrow) wchar_t[nSrcLen];
if( pDst == NULL ){
return RESULT_FAILURE;
}
Expand Down Expand Up @@ -217,12 +212,7 @@ EConvertResult CLatin1::UnicodeToLatin1( const CNativeW& cSrc, CMemory* pDstMem
int nSrcLen = cSrc.GetStringLength();

// 変換先バッファサイズを設定してバッファを確保
char* pDst;
try{
pDst = new char[ nSrcLen * 2 ];
}catch( ... ){
pDst = NULL;
}
char* pDst = new (std::nothrow) char[ nSrcLen * 2 ];
if( pDst == NULL ){
return RESULT_FAILURE;
}
Expand Down
15 changes: 3 additions & 12 deletions sakura_core/charset/CShiftJis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "env/CShareData.h"
#include "env/DLLSHAREDATA.h"

#include <new>

//! 指定した位置の文字が何バイト文字かを返す
/*!
Expand Down Expand Up @@ -119,12 +120,7 @@ EConvertResult CShiftJis::SJISToUnicode( const CMemory& cSrc, CNativeW* pDstMem
if( &cSrc == pDstMem->_GetMemory() )
{
// 変換先バッファサイズを設定してメモリ領域確保
wchar_t* pDst;
try{
pDst = new wchar_t[nSrcLen];
}catch( ... ){
pDst = NULL;
}
wchar_t* pDst = new (std::nothrow) wchar_t[nSrcLen];
if( pDst == NULL ){
return RESULT_FAILURE;
}
Expand Down Expand Up @@ -239,12 +235,7 @@ EConvertResult CShiftJis::UnicodeToSJIS( const CNativeW& cSrc, CMemory* pDstMem
int nSrcLen = pMem->GetRawLength() / sizeof(wchar_t);

// 変換先バッファサイズを設定してバッファを確保
char* pDst;
try{
pDst = new char[ nSrcLen * 2 ];
}catch( ... ){
pDst = NULL;
}
char* pDst = new (std::nothrow) char[ nSrcLen * 2 ];
if( pDst == NULL ){
return RESULT_FAILURE;
}
Expand Down
69 changes: 21 additions & 48 deletions sakura_core/charset/CUtf7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,26 @@ int CUtf7::_Utf7SetDToUni_block( const char* pSrc, const int nSrcLen, wchar_t* p
*/
int CUtf7::_Utf7SetBToUni_block( const char* pSrc, const int nSrcLen, wchar_t* pDst, bool* pbError )
{
int ndecoded_len = 0;
char* pbuf;
bool bError = false;

try{
pbuf = new char[nSrcLen];
}catch( ... ){
pbuf = NULL;
bError = true;
char* pbuf = new (std::nothrow) char[nSrcLen];
if (pbuf == NULL) {
if( pbError ){
*pbError = true;
}
return 0;
}

if( pbuf != NULL ){
ndecoded_len = _DecodeBase64( pSrc, nSrcLen, pbuf );
int nModLen = ndecoded_len % sizeof(wchar_t);
ndecoded_len = ndecoded_len - nModLen;
CMemory::SwapHLByte( pbuf, ndecoded_len ); // UTF-16 BE を UTF-16 LE に直す
memcpy( reinterpret_cast<char*>(pDst), pbuf, ndecoded_len );
if( nModLen ){
ndecoded_len += BinToText( reinterpret_cast<const unsigned char *>(pbuf) + ndecoded_len,
nModLen, &reinterpret_cast<unsigned short*>(pDst)[ndecoded_len / sizeof(wchar_t)]) * sizeof(wchar_t);
bError = true;
int ndecoded_len = _DecodeBase64( pSrc, nSrcLen, pbuf );
int nModLen = ndecoded_len % sizeof(wchar_t);
ndecoded_len = ndecoded_len - nModLen;
CMemory::SwapHLByte( pbuf, ndecoded_len ); // UTF-16 BE を UTF-16 LE に直す
memcpy( reinterpret_cast<char*>(pDst), pbuf, ndecoded_len );
if( nModLen ){
ndecoded_len += BinToText( reinterpret_cast<const unsigned char *>(pbuf) + ndecoded_len,
nModLen, &reinterpret_cast<unsigned short*>(pDst)[ndecoded_len / sizeof(wchar_t)]) * sizeof(wchar_t);
if( pbError ){
*pbError = true;
}
}else{
;
}

delete [] pbuf;

if( pbError ){
*pbError = bError;
}

return ndecoded_len / sizeof(wchar_t);
}

Expand Down Expand Up @@ -136,13 +124,8 @@ EConvertResult CUtf7::UTF7ToUnicode( const CMemory& cSrc, CNativeW* pDstMem )
const char* pData = reinterpret_cast<const char*>( cSrc.GetRawPtr(&nDataLen) );

// 必要なバッファサイズを調べて確保
wchar_t* pDst;
try{
pDst = new wchar_t[nDataLen + 1];
if( pDst == NULL ){
return RESULT_FAILURE;
}
}catch( ... ){
wchar_t* pDst = new (std::nothrow) wchar_t[nDataLen + 1];
if( pDst == NULL ){
return RESULT_FAILURE;
}

Expand Down Expand Up @@ -182,18 +165,13 @@ int CUtf7::_UniToUtf7SetD_block( const wchar_t* pSrc, const int nSrcLen, char* p

int CUtf7::_UniToUtf7SetB_block( const wchar_t* pSrc, const int nSrcLen, char* pDst )
{
wchar_t* psrc;
char* pw;

if( nSrcLen < 1 ){
return 0;
}

try{
psrc = new wchar_t[nSrcLen];
}catch( ... ){
psrc = NULL;
}
wchar_t* psrc = new (std::nothrow) wchar_t[nSrcLen];
if( psrc == NULL ){
return 0;
}
Expand Down Expand Up @@ -271,13 +249,8 @@ EConvertResult CUtf7::UnicodeToUTF7( const CNativeW& cSrc, CMemory* pDstMem )
int nSrcLen = cSrc.GetStringLength();

// 出力先バッファの確保
char *pDst;
try{
// 最大で、変換元のデータ長の5倍。
pDst = new char[ nSrcLen * 5 + 1 ]; // * → +ACo-
}catch( ... ){
pDst = NULL;
}
// 最大で、変換元のデータ長の5倍。
char *pDst = new (std::nothrow) char[ nSrcLen * 5 + 1 ]; // * → +ACo-
if( pDst == NULL ){
return RESULT_FAILURE;
}
Expand Down
14 changes: 2 additions & 12 deletions sakura_core/charset/CUtf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@ EConvertResult CUtf8::_UTF8ToUnicode( const CMemory& cSrc, CNativeW* pDstMem, bo
if( &cSrc == pDstMem->_GetMemory() )
{
// 必要なバッファサイズを調べて確保する
wchar_t* pDst;
try{
pDst = new wchar_t[nSrcLen];
}catch( ... ){
pDst = NULL;
}
wchar_t* pDst = new (std::nothrow) wchar_t[nSrcLen];
if( pDst == NULL ){
return RESULT_FAILURE;
}
Expand Down Expand Up @@ -208,12 +203,7 @@ EConvertResult CUtf8::_UnicodeToUTF8( const CNativeW& cSrc, CMemory* pDstMem, bo


// 必要なバッファサイズを調べてメモリを確保
char* pDst;
try{
pDst = new char[nSrcLen * 3];
}catch( ... ){
pDst = NULL;
}
char* pDst = new (std::nothrow) char[nSrcLen * 3];
if( pDst == NULL ){
return RESULT_FAILURE;
}
Expand Down