Changeset - r25482:5d7a2a26621c
[Not reviewed]
master
0 10 0
Rubidium - 4 years ago 2021-05-10 21:43:52
rubidium@openttd.org
Fix: comparison of narrow type to wide type in loop (potential for infinite loops)
10 files changed with 21 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/depot_gui.cpp
Show inline comments
 
@@ -395,11 +395,11 @@ struct DepotWindow : Window {
 

	
 
		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)));
 
		int y;
 
		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 */
 
				const Vehicle *v = this->vehicle_list[num];
 
				if (this->num_columns == 1) {
src/industry_gui.cpp
Show inline comments
 
@@ -357,7 +357,7 @@ class BuildIndustryWindow : public Windo
 
		int numcargo = 0;
 
		int firstcargo = -1;
 

	
 
		for (byte j = 0; j < cargolistlen; j++) {
 
		for (int j = 0; j < cargolistlen; j++) {
 
			if (cargolist[j] == CT_INVALID) continue;
 
			numcargo++;
 
			if (firstcargo < 0) {
 
@@ -419,7 +419,7 @@ public:
 
		switch (widget) {
 
			case WID_DPI_MATRIX_WIDGET: {
 
				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;
 
					d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(this->index[i])->name));
 
				}
 
@@ -438,7 +438,7 @@ public:
 
				uint extra_lines_newgrf = 0;
 
				uint max_minwidth = FONT_HEIGHT_NORMAL * MAX_MINWIDTH_LINEHEIGHTS;
 
				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;
 

	
 
					const IndustrySpec *indsp = GetIndustrySpec(this->index[i]);
 
@@ -528,7 +528,7 @@ public:
 
				int icon_bottom = icon_top + this->legend.height;
 

	
 
				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();
 

	
 
					if (this->index[i + this->vscroll->GetPosition()] == INVALID_INDUSTRYTYPE) {
src/linkgraph/linkgraph.h
Show inline comments
 
@@ -495,7 +495,7 @@ public:
 
	 * Get the current size of the component.
 
	 * @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.
src/linkgraph/linkgraphjob.cpp
Show inline comments
 
@@ -101,7 +101,7 @@ LinkGraphJob::~LinkGraphJob()
 
	/* Link graph has been merged into another one. */
 
	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) {
 
		Node from = (*this)[node_id];
 

	
src/linkgraph/mcf.cpp
Show inline comments
 
@@ -260,7 +260,7 @@ void MultiCommodityFlow::Dijkstra(NodeID
 
{
 
	typedef std::set<Tannotation *, typename Tannotation::Comparator> AnnoSet;
 
	Tedge_iterator iter(this->job);
 
	uint size = this->job.Size();
 
	uint16 size = this->job.Size();
 
	AnnoSet annos;
 
	paths.resize(size, nullptr);
 
	for (NodeID node = 0; node < size; ++node) {
 
@@ -473,7 +473,7 @@ bool MCF1stPass::EliminateCycles(PathVec
 
bool MCF1stPass::EliminateCycles()
 
{
 
	bool cycles_found = false;
 
	uint size = this->job.Size();
 
	uint16 size = this->job.Size();
 
	PathVector path(size, nullptr);
 
	for (NodeID node = 0; node < size; ++node) {
 
		/* 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)
 
{
 
	PathVector paths;
 
	uint size = job.Size();
 
	uint16 size = job.Size();
 
	uint accuracy = job.Settings().accuracy;
 
	bool more_loops;
 
	std::vector<bool> finished_sources(size);
 
@@ -540,7 +540,7 @@ MCF2ndPass::MCF2ndPass(LinkGraphJob &job
 
{
 
	this->max_saturation = UINT_MAX; // disable artificial cap on saturation
 
	PathVector paths;
 
	uint size = job.Size();
 
	uint16 size = job.Size();
 
	uint accuracy = job.Settings().accuracy;
 
	bool demand_left = true;
 
	std::vector<bool> finished_sources(size);
src/network/core/packet.cpp
Show inline comments
 
@@ -374,14 +374,13 @@ uint64 Packet::Recv_uint64()
 
 */
 
void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings settings)
 
{
 
	PacketSize pos;
 
	char *bufp = buffer;
 
	const char *last = buffer + size - 1;
 

	
 
	/* Don't allow reading from a closed socket */
 
	if (cs->HasClientQuit()) return;
 

	
 
	pos = this->pos;
 
	size_t pos = this->pos;
 
	while (--size > 0 && pos < this->Size() && (*buffer++ = this->buffer[pos++]) != '\0') {}
 

	
 
	if (size == 0 || pos == this->Size()) {
 
@@ -391,7 +390,9 @@ void Packet::Recv_string(char *buffer, s
 
		while (pos < this->Size() && this->buffer[pos] != '\0') pos++;
 
		pos++;
 
	}
 
	this->pos = pos;
 

	
 
	assert(pos <= std::numeric_limits<PacketSize>::max());
 
	this->pos = static_cast<PacketSize>(pos);
 

	
 
	str_validate(bufp, last, settings);
 
}
src/rail_gui.cpp
Show inline comments
 
@@ -1219,7 +1219,7 @@ public:
 
				StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
 
				for (auto station_class : this->station_classes) {
 
					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);
 
						SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
 
						d = maxdim(d, GetStringBoundingBox(str));
src/saveload/linkgraph_sl.cpp
Show inline comments
 
@@ -139,7 +139,7 @@ static const SaveLoad _edge_desc[] = {
 
 */
 
void SaveLoad_LinkGraph(LinkGraph &lg)
 
{
 
	uint size = lg.Size();
 
	uint16 size = lg.Size();
 
	for (NodeID from = 0; from < size; ++from) {
 
		Node *node = &lg.nodes[from];
 
		SlObject(node, _node_desc);
src/story_gui.cpp
Show inline comments
 
@@ -776,7 +776,7 @@ public:
 
			case WID_SB_SEL_PAGE: {
 

	
 
				/* 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];
 

	
 
					if (s->title != nullptr) {
 
@@ -822,7 +822,7 @@ public:
 
				if (!list.empty()) {
 
					/* Get the index of selected page. */
 
					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];
 
						if (p->index == this->selected_page_id) break;
 
						selected++;
src/texteff.hpp
Show inline comments
 
@@ -24,7 +24,7 @@ enum TextEffectMode {
 
	INVALID_TE_ID = 0xFFFF,
 
};
 

	
 
typedef uint16 TextEffectID;
 
typedef size_t TextEffectID;
 

	
 
void MoveAllTextEffects(uint delta_ms);
 
TextEffectID AddTextEffect(StringID msg, int x, int y, uint8 duration, TextEffectMode mode);
0 comments (0 inline, 0 general)