Skip to content

Commit 1a90750

Browse files
committed
Fix UB: don't dereference end iterators, they're out-of-bounds!
1 parent dec554f commit 1a90750

File tree

9 files changed

+14
-14
lines changed

9 files changed

+14
-14
lines changed

src/DSF/DSFPointPool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ void DSFOptimizePrimitives(
721721

722722
vector<unsigned short> pure_tris;
723723

724-
unsigned short * s = &*indices.begin(), * e = &*indices.end();
724+
unsigned short * s = indices.data(), * e = indices.data() + indices.size();
725725
while(s != e)
726726
{
727727
unsigned short * b = strip_break(s,e);

src/GUI/GUI_Button.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void GUI_Button::Draw(GUI_GraphState * state)
167167

168168
if (!desc.empty())
169169
{
170-
w = GUI_MeasureRange(font_UI_Basic, &*desc.begin(), &*desc.end());
170+
w = GUI_MeasureRange(font_UI_Basic, desc.data(), desc.data() + desc.size());
171171
w = (bounds[2] - bounds[0] - w) / 2;
172172
h = GUI_GetLineAscent(font_UI_Basic);
173173
h = (bounds[3] - bounds[1] - h) / 2;

src/GUI/GUI_Fonts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ void GUI_TruncateText(
476476
{
477477
if (ioText.empty()) return;
478478

479-
int chars = GUI_FitForward(inFontID, &*ioText.begin(), &*ioText.end(), inSpace);
479+
int chars = GUI_FitForward(inFontID, ioText.data(), ioText.data() + ioText.size(), inSpace);
480480
if (chars == ioText.length()) return;
481481
if (chars < 0) { ioText.clear(); return; }
482482
if (chars > 2)

src/GUI/GUI_PopupButton.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void GUI_PopupButton::Draw(GUI_GraphState * state)
8989
if (i >= 0 && i < mItems.size())
9090
{
9191
float c[4] = { 0,0,0,1 };
92-
float w = GUI_MeasureRange(font_UI_Basic, &*mItems[i].begin(), &*mItems[i].end());
92+
float w = GUI_MeasureRange(font_UI_Basic, mItems[i].data(), mItems[i].data() + mItems[i].size());
9393
GUI_FontDraw(state,font_UI_Basic, c, (bounds[0]+bounds[2]-w) /2, bounds[1], mItems[i].c_str());
9494
}
9595
}

src/GUI/GUI_TabControl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ void GUI_TabControl::SetDescriptor(const string& inDesc)
8383
if(pos > 0 && pos < mItems[n].length())
8484
{
8585
int w1 = GUI_MeasureRange(font_UI_Basic, mItems[n].c_str(), mItems[n].c_str() + pos);
86-
int w2 = GUI_MeasureRange(font_UI_Basic, mItems[n].c_str() + pos + 1,&* mItems[n].end() );
86+
int w2 = GUI_MeasureRange(font_UI_Basic, mItems[n].c_str() + pos + 1, mItems[n].data() + mItems[n].size() );
8787
mWidths[n] = max(w1, w2) + TAB_PADDING * 2;
8888
}
8989
else
90-
mWidths[n] = GUI_MeasureRange(font_UI_Basic, &*mItems[n].begin(), &*mItems[n].end()) + TAB_PADDING * 2;
90+
mWidths[n] = GUI_MeasureRange(font_UI_Basic, &*mItems[n].begin(), mItems[n].data() + mItems[n].size()) + TAB_PADDING * 2;
9191
}
9292

9393
SetMax(mItems.size());
@@ -137,7 +137,7 @@ void GUI_TabControl::Draw(GUI_GraphState * state)
137137
y += 0.5 * h;
138138
GUI_FontDrawScaled(state, font_UI_Basic, mTextColor, x, y, 0, y+h, mItems[n].c_str(), mItems[n].c_str() + pos, align_Left);
139139
y -= h;
140-
GUI_FontDrawScaled(state, font_UI_Basic, mTextColor, x, y, 0, y+h, mItems[n].c_str() + pos + 1, &*mItems[n].end(), align_Left);
140+
GUI_FontDrawScaled(state, font_UI_Basic, mTextColor, x, y, 0, y+h, mItems[n].c_str() + pos + 1, mItems[n].data() + mItems[n].size(), align_Left);
141141
}
142142
else
143143
GUI_FontDraw(state, font_UI_Basic, mTextColor, x, y, mItems[n].c_str());

src/GUI/GUI_TextField.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ int GUI_TextField::HandleCommand(int command)
247247
if (GUI_GetTextFromClipboard(txt))
248248
{
249249
GetSelection(&s1, &s2);
250-
DoReplaceText(s1, s2, &*txt.begin(), &*txt.end());
250+
DoReplaceText(s1, s2, txt.data(), txt.data() + txt.size());
251251
SetSelection(s1+txt.size(),s1+txt.size());
252252
}
253253
}
@@ -399,8 +399,8 @@ void GUI_TextField::GetText(
399399
const char ** end_p)
400400
{
401401
GetDescriptor(mText);
402-
*start_p = &*mText.begin();
403-
*end_p = &*mText.end();
402+
*start_p = mText.data();
403+
*end_p = mText.data() + mText.size();
404404
}
405405

406406
void GUI_TextField::ReplaceText(

src/WEDImportExport/WED_GatewayImport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ WED_Airport * WED_GatewayImportDialog::ImportSpecificVersion(const string& json_
10561056
vector<char> outString = vector<char>(zipString.length());
10571057

10581058
char * outP;
1059-
decode(&*zipString.begin(),&*zipString.end(),&*outString.begin(),&outP);
1059+
decode(zipString.data(),zipString.data() + zipString.size(), outString.data(), &outP);
10601060

10611061
//Fixes the terrible vector padding bug by shrinking it back down to precisely the correct size
10621062
outString.resize(outP - &*outString.begin());

src/WEDMap/WED_ToolInfoAdapter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,12 @@ int WED_ToolInfoAdapter::GetCellWidth(int n)
336336
case prop_TaxiSign: return 150;
337337
// mTool->GetNthPropertyDict(n / 2, dict);
338338
// for(PropertyDict_t::iterator d = dict.begin(); d != dict.end(); ++d)
339-
// w = max(w,(int) GUI_MeasureRange(OUR_FONT, &*d->second.begin(),&*d->second.end())+20);
339+
// w = max(w,(int) GUI_MeasureRange(OUR_FONT, d->second.data(), d->second.data() + d->second.size())+20);
340340
// return w;
341341
default: return 50;
342342
}
343343
else
344-
return GUI_MeasureRange(OUR_FONT, &*inf.prop_name.begin(), &*inf.prop_name.end()) + 18;
344+
return GUI_MeasureRange(OUR_FONT, inf.prop_name.data(), inf.prop_name.data() + inf.prop_name.size()) + 18;
345345
}
346346

347347
int WED_ToolInfoAdapter::GetCellBottom(int n)

src/XESCore/AptIO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static void parse_linear_codes(const string& codes, set<int> * attributes)
143143
{
144144
attributes->clear();
145145
MFScanner scanner;
146-
MFS_init(&scanner, &*codes.begin(), &*codes.end());
146+
MFS_init(&scanner, codes.data(), codes.data() + codes.size());
147147
int code;
148148
while (!MFS_done(&scanner) && ((code = MFS_int(&scanner)) != 0))
149149
attributes->insert(code);

0 commit comments

Comments
 (0)