mirror of https://github.com/OpenTTD/OpenTTD.git
Fix: comparison of narrow type to wide type in loop (potential for infinite loops)
This commit is contained in:
parent
031e91de6e
commit
bb9121dbd4
|
@ -395,11 +395,11 @@ struct DepotWindow : Window {
|
||||||
|
|
||||||
uint16 rows_in_display = wid->current_y / wid->resize_y;
|
uint16 rows_in_display = wid->current_y / wid->resize_y;
|
||||||
|
|
||||||
uint16 num = this->vscroll->GetPosition() * this->num_columns;
|
uint num = this->vscroll->GetPosition() * this->num_columns;
|
||||||
uint maxval = static_cast<uint>(std::min<size_t>(this->vehicle_list.size(), num + (rows_in_display * this->num_columns)));
|
uint maxval = static_cast<uint>(std::min<size_t>(this->vehicle_list.size(), num + (rows_in_display * this->num_columns)));
|
||||||
int y;
|
int y;
|
||||||
for (y = r.top + 1; num < maxval; y += this->resize.step_height) { // Draw the rows
|
for (y = r.top + 1; num < maxval; y += this->resize.step_height) { // Draw the rows
|
||||||
for (byte i = 0; i < this->num_columns && num < maxval; i++, num++) {
|
for (uint i = 0; i < this->num_columns && num < maxval; i++, num++) {
|
||||||
/* Draw all vehicles in the current row */
|
/* Draw all vehicles in the current row */
|
||||||
const Vehicle *v = this->vehicle_list[num];
|
const Vehicle *v = this->vehicle_list[num];
|
||||||
if (this->num_columns == 1) {
|
if (this->num_columns == 1) {
|
||||||
|
|
|
@ -357,7 +357,7 @@ class BuildIndustryWindow : public Window {
|
||||||
int numcargo = 0;
|
int numcargo = 0;
|
||||||
int firstcargo = -1;
|
int firstcargo = -1;
|
||||||
|
|
||||||
for (byte j = 0; j < cargolistlen; j++) {
|
for (int j = 0; j < cargolistlen; j++) {
|
||||||
if (cargolist[j] == CT_INVALID) continue;
|
if (cargolist[j] == CT_INVALID) continue;
|
||||||
numcargo++;
|
numcargo++;
|
||||||
if (firstcargo < 0) {
|
if (firstcargo < 0) {
|
||||||
|
@ -419,7 +419,7 @@ public:
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_DPI_MATRIX_WIDGET: {
|
case WID_DPI_MATRIX_WIDGET: {
|
||||||
Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES);
|
Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES);
|
||||||
for (byte i = 0; i < this->count; i++) {
|
for (uint16 i = 0; i < this->count; i++) {
|
||||||
if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
|
if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
|
||||||
d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(this->index[i])->name));
|
d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(this->index[i])->name));
|
||||||
}
|
}
|
||||||
|
@ -438,7 +438,7 @@ public:
|
||||||
uint extra_lines_newgrf = 0;
|
uint extra_lines_newgrf = 0;
|
||||||
uint max_minwidth = FONT_HEIGHT_NORMAL * MAX_MINWIDTH_LINEHEIGHTS;
|
uint max_minwidth = FONT_HEIGHT_NORMAL * MAX_MINWIDTH_LINEHEIGHTS;
|
||||||
Dimension d = {0, 0};
|
Dimension d = {0, 0};
|
||||||
for (byte i = 0; i < this->count; i++) {
|
for (uint16 i = 0; i < this->count; i++) {
|
||||||
if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
|
if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
|
||||||
|
|
||||||
const IndustrySpec *indsp = GetIndustrySpec(this->index[i]);
|
const IndustrySpec *indsp = GetIndustrySpec(this->index[i]);
|
||||||
|
@ -528,7 +528,7 @@ public:
|
||||||
int icon_bottom = icon_top + this->legend.height;
|
int icon_bottom = icon_top + this->legend.height;
|
||||||
|
|
||||||
int y = r.top;
|
int y = r.top;
|
||||||
for (byte i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->count; i++) {
|
for (uint16 i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->count; i++) {
|
||||||
bool selected = this->selected_index == i + this->vscroll->GetPosition();
|
bool selected = this->selected_index == i + this->vscroll->GetPosition();
|
||||||
|
|
||||||
if (this->index[i + this->vscroll->GetPosition()] == INVALID_INDUSTRYTYPE) {
|
if (this->index[i + this->vscroll->GetPosition()] == INVALID_INDUSTRYTYPE) {
|
||||||
|
|
|
@ -495,7 +495,7 @@ public:
|
||||||
* Get the current size of the component.
|
* Get the current size of the component.
|
||||||
* @return Size.
|
* @return Size.
|
||||||
*/
|
*/
|
||||||
inline uint Size() const { return (uint)this->nodes.size(); }
|
inline uint16 Size() const { return (uint16)this->nodes.size(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get date of last compression.
|
* Get date of last compression.
|
||||||
|
|
|
@ -101,7 +101,7 @@ LinkGraphJob::~LinkGraphJob()
|
||||||
/* Link graph has been merged into another one. */
|
/* Link graph has been merged into another one. */
|
||||||
if (!LinkGraph::IsValidID(this->link_graph.index)) return;
|
if (!LinkGraph::IsValidID(this->link_graph.index)) return;
|
||||||
|
|
||||||
uint size = this->Size();
|
uint16 size = this->Size();
|
||||||
for (NodeID node_id = 0; node_id < size; ++node_id) {
|
for (NodeID node_id = 0; node_id < size; ++node_id) {
|
||||||
Node from = (*this)[node_id];
|
Node from = (*this)[node_id];
|
||||||
|
|
||||||
|
|
|
@ -260,7 +260,7 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
|
||||||
{
|
{
|
||||||
typedef std::set<Tannotation *, typename Tannotation::Comparator> AnnoSet;
|
typedef std::set<Tannotation *, typename Tannotation::Comparator> AnnoSet;
|
||||||
Tedge_iterator iter(this->job);
|
Tedge_iterator iter(this->job);
|
||||||
uint size = this->job.Size();
|
uint16 size = this->job.Size();
|
||||||
AnnoSet annos;
|
AnnoSet annos;
|
||||||
paths.resize(size, nullptr);
|
paths.resize(size, nullptr);
|
||||||
for (NodeID node = 0; node < size; ++node) {
|
for (NodeID node = 0; node < size; ++node) {
|
||||||
|
@ -473,7 +473,7 @@ bool MCF1stPass::EliminateCycles(PathVector &path, NodeID origin_id, NodeID next
|
||||||
bool MCF1stPass::EliminateCycles()
|
bool MCF1stPass::EliminateCycles()
|
||||||
{
|
{
|
||||||
bool cycles_found = false;
|
bool cycles_found = false;
|
||||||
uint size = this->job.Size();
|
uint16 size = this->job.Size();
|
||||||
PathVector path(size, nullptr);
|
PathVector path(size, nullptr);
|
||||||
for (NodeID node = 0; node < size; ++node) {
|
for (NodeID node = 0; node < size; ++node) {
|
||||||
/* Starting at each node in the graph find all cycles involving this
|
/* Starting at each node in the graph find all cycles involving this
|
||||||
|
@ -491,7 +491,7 @@ bool MCF1stPass::EliminateCycles()
|
||||||
MCF1stPass::MCF1stPass(LinkGraphJob &job) : MultiCommodityFlow(job)
|
MCF1stPass::MCF1stPass(LinkGraphJob &job) : MultiCommodityFlow(job)
|
||||||
{
|
{
|
||||||
PathVector paths;
|
PathVector paths;
|
||||||
uint size = job.Size();
|
uint16 size = job.Size();
|
||||||
uint accuracy = job.Settings().accuracy;
|
uint accuracy = job.Settings().accuracy;
|
||||||
bool more_loops;
|
bool more_loops;
|
||||||
std::vector<bool> finished_sources(size);
|
std::vector<bool> finished_sources(size);
|
||||||
|
@ -540,7 +540,7 @@ MCF2ndPass::MCF2ndPass(LinkGraphJob &job) : MultiCommodityFlow(job)
|
||||||
{
|
{
|
||||||
this->max_saturation = UINT_MAX; // disable artificial cap on saturation
|
this->max_saturation = UINT_MAX; // disable artificial cap on saturation
|
||||||
PathVector paths;
|
PathVector paths;
|
||||||
uint size = job.Size();
|
uint16 size = job.Size();
|
||||||
uint accuracy = job.Settings().accuracy;
|
uint accuracy = job.Settings().accuracy;
|
||||||
bool demand_left = true;
|
bool demand_left = true;
|
||||||
std::vector<bool> finished_sources(size);
|
std::vector<bool> finished_sources(size);
|
||||||
|
|
|
@ -374,14 +374,13 @@ uint64 Packet::Recv_uint64()
|
||||||
*/
|
*/
|
||||||
void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings settings)
|
void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings settings)
|
||||||
{
|
{
|
||||||
PacketSize pos;
|
|
||||||
char *bufp = buffer;
|
char *bufp = buffer;
|
||||||
const char *last = buffer + size - 1;
|
const char *last = buffer + size - 1;
|
||||||
|
|
||||||
/* Don't allow reading from a closed socket */
|
/* Don't allow reading from a closed socket */
|
||||||
if (cs->HasClientQuit()) return;
|
if (cs->HasClientQuit()) return;
|
||||||
|
|
||||||
pos = this->pos;
|
size_t pos = this->pos;
|
||||||
while (--size > 0 && pos < this->Size() && (*buffer++ = this->buffer[pos++]) != '\0') {}
|
while (--size > 0 && pos < this->Size() && (*buffer++ = this->buffer[pos++]) != '\0') {}
|
||||||
|
|
||||||
if (size == 0 || pos == this->Size()) {
|
if (size == 0 || pos == this->Size()) {
|
||||||
|
@ -391,7 +390,9 @@ void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings set
|
||||||
while (pos < this->Size() && this->buffer[pos] != '\0') pos++;
|
while (pos < this->Size() && this->buffer[pos] != '\0') pos++;
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
this->pos = pos;
|
|
||||||
|
assert(pos <= std::numeric_limits<PacketSize>::max());
|
||||||
|
this->pos = static_cast<PacketSize>(pos);
|
||||||
|
|
||||||
str_validate(bufp, last, settings);
|
str_validate(bufp, last, settings);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1219,7 +1219,7 @@ public:
|
||||||
StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
|
StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
|
||||||
for (auto station_class : this->station_classes) {
|
for (auto station_class : this->station_classes) {
|
||||||
StationClass *stclass = StationClass::Get(station_class);
|
StationClass *stclass = StationClass::Get(station_class);
|
||||||
for (uint16 j = 0; j < stclass->GetSpecCount(); j++) {
|
for (uint j = 0; j < stclass->GetSpecCount(); j++) {
|
||||||
const StationSpec *statspec = stclass->GetSpec(j);
|
const StationSpec *statspec = stclass->GetSpec(j);
|
||||||
SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
|
SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
|
||||||
d = maxdim(d, GetStringBoundingBox(str));
|
d = maxdim(d, GetStringBoundingBox(str));
|
||||||
|
|
|
@ -139,7 +139,7 @@ static const SaveLoad _edge_desc[] = {
|
||||||
*/
|
*/
|
||||||
void SaveLoad_LinkGraph(LinkGraph &lg)
|
void SaveLoad_LinkGraph(LinkGraph &lg)
|
||||||
{
|
{
|
||||||
uint size = lg.Size();
|
uint16 size = lg.Size();
|
||||||
for (NodeID from = 0; from < size; ++from) {
|
for (NodeID from = 0; from < size; ++from) {
|
||||||
Node *node = &lg.nodes[from];
|
Node *node = &lg.nodes[from];
|
||||||
SlObject(node, _node_desc);
|
SlObject(node, _node_desc);
|
||||||
|
|
|
@ -776,7 +776,7 @@ public:
|
||||||
case WID_SB_SEL_PAGE: {
|
case WID_SB_SEL_PAGE: {
|
||||||
|
|
||||||
/* Get max title width. */
|
/* Get max title width. */
|
||||||
for (uint16 i = 0; i < this->story_pages.size(); i++) {
|
for (size_t i = 0; i < this->story_pages.size(); i++) {
|
||||||
const StoryPage *s = this->story_pages[i];
|
const StoryPage *s = this->story_pages[i];
|
||||||
|
|
||||||
if (s->title != nullptr) {
|
if (s->title != nullptr) {
|
||||||
|
@ -822,7 +822,7 @@ public:
|
||||||
if (!list.empty()) {
|
if (!list.empty()) {
|
||||||
/* Get the index of selected page. */
|
/* Get the index of selected page. */
|
||||||
int selected = 0;
|
int selected = 0;
|
||||||
for (uint16 i = 0; i < this->story_pages.size(); i++) {
|
for (size_t i = 0; i < this->story_pages.size(); i++) {
|
||||||
const StoryPage *p = this->story_pages[i];
|
const StoryPage *p = this->story_pages[i];
|
||||||
if (p->index == this->selected_page_id) break;
|
if (p->index == this->selected_page_id) break;
|
||||||
selected++;
|
selected++;
|
||||||
|
|
|
@ -24,7 +24,7 @@ enum TextEffectMode {
|
||||||
INVALID_TE_ID = 0xFFFF,
|
INVALID_TE_ID = 0xFFFF,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef uint16 TextEffectID;
|
typedef size_t TextEffectID;
|
||||||
|
|
||||||
void MoveAllTextEffects(uint delta_ms);
|
void MoveAllTextEffects(uint delta_ms);
|
||||||
TextEffectID AddTextEffect(StringID msg, int x, int y, uint8 duration, TextEffectMode mode);
|
TextEffectID AddTextEffect(StringID msg, int x, int y, uint8 duration, TextEffectMode mode);
|
||||||
|
|
Loading…
Reference in New Issue