Skip to content

Commit fe4cc6d

Browse files
authored
#1914 で確認した問題への対策を追加 (#1966)
* CRuler::DrawRulerBg メソッドで nMaxLineKetas (10240) より keta の値が大きくなる為に結果的に負の値が size_t 型のローカル変数に代入され、極端に大きい値が std::vector::resize メソッドに渡されてしまう問題への対策を追加  * CFigure_Comma::DispSpace で ExtTextOut を呼び出す際に szViewString の文字数が 64 を超過すると pMetrics->GetDxArray_AllHankaku() で取得する領域の範囲外参照が発生する問題への対策を追加
1 parent ea735b6 commit fe4cc6d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

sakura_core/view/CRuler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void CRuler::DrawRulerBg(CGraphics& gr)
184184

185185
// 目盛り線を1本ずつ描画するのではなく後述する PolyPolyline でまとめて描画を行う
186186
const int nWidth = (Int)(m_pEditView->GetTextArea().GetRightCol() - i);
187-
const size_t nLinesToDraw = 1 + std::min<int>((nWidth + 1 + 1 + oneColumn - 1) / oneColumn, nMaxLineKetas - keta + 1);
187+
const size_t nLinesToDraw = 1 + std::min<int>((nWidth + 1 + 1 + oneColumn - 1) / oneColumn, std::max(nMaxLineKetas - keta, 0) + 1);
188188
auto& apt = m_apt;
189189
auto& asz = m_asz;
190190
apt.resize(nLinesToDraw * 2);

sakura_core/view/figures/CFigure_Comma.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ void CFigure_Comma::DispSpace(CGraphics& gr, DispPos* pDispPos, CEditView* pcVie
9090
if (szViewString.length() < nTabDispWidth) {
9191
szViewString.append(nTabDispWidth - szViewString.length(), L' ');
9292
}
93+
const INT* lpDx;
94+
if( szViewString.length() > 64 ) {
95+
static std::vector<int> anHankakuDx; //!< 半角用文字間隔配列
96+
anHankakuDx.resize(szViewString.length(), pMetrics->GetHankakuDx());
97+
lpDx = &anHankakuDx[0];
98+
}else {
99+
lpDx = pMetrics->GetDxArray_AllHankaku();
100+
}
93101
::ExtTextOut(
94102
gr,
95103
sPos.GetDrawPos().x,
@@ -98,7 +106,7 @@ void CFigure_Comma::DispSpace(CGraphics& gr, DispPos* pDispPos, CEditView* pcVie
98106
&rcClip2,
99107
szViewString.c_str(),
100108
static_cast<UINT>(szViewString.length()),
101-
pMetrics->GetDxArray_AllHankaku()
109+
lpDx
102110
);
103111
}
104112
}

0 commit comments

Comments
 (0)