mirror of https://github.com/OpenTTD/OpenTTD
(svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
Note: _total_towns and _total_industries willb e removed soon, so this 'hack' is okay, for now ;)release/0.5
parent
ceb523c29f
commit
93d5b5a355
|
@ -104,7 +104,7 @@ static inline IndustryID GetIndustryArraySize(void)
|
||||||
* _really_ returns the highest index + 1. Now it just returns
|
* _really_ returns the highest index + 1. Now it just returns
|
||||||
* the next safe value we are sure about everything is below.
|
* the next safe value we are sure about everything is below.
|
||||||
*/
|
*/
|
||||||
return _total_industries + 1;
|
return _total_industries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1408,7 +1408,7 @@ static Industry *AllocateIndustry(void)
|
||||||
|
|
||||||
if (IsValidIndustry(i)) continue;
|
if (IsValidIndustry(i)) continue;
|
||||||
|
|
||||||
if (i->index > _total_industries) _total_industries = i->index;
|
if (i->index >= _total_industries) _total_industries = i->index + 1;
|
||||||
|
|
||||||
memset(i, 0, sizeof(*i));
|
memset(i, 0, sizeof(*i));
|
||||||
i->index = index;
|
i->index = index;
|
||||||
|
@ -1974,7 +1974,7 @@ static void Load_INDY(void)
|
||||||
i = GetIndustry(index);
|
i = GetIndustry(index);
|
||||||
SlObject(i, _industry_desc);
|
SlObject(i, _industry_desc);
|
||||||
|
|
||||||
if (index > _total_industries) _total_industries = index;
|
if (index >= _total_industries) _total_industries = index + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
town.h
2
town.h
|
@ -188,7 +188,7 @@ static inline TownID GetTownArraySize(void)
|
||||||
* _really_ returns the highest index + 1. Now it just returns
|
* _really_ returns the highest index + 1. Now it just returns
|
||||||
* the next safe value we are sure about everything is below.
|
* the next safe value we are sure about everything is below.
|
||||||
*/
|
*/
|
||||||
return _total_towns + 1;
|
return _total_towns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -952,8 +952,7 @@ static Town *AllocateTown(void)
|
||||||
if (!IsValidTown(t)) {
|
if (!IsValidTown(t)) {
|
||||||
TownID index = t->index;
|
TownID index = t->index;
|
||||||
|
|
||||||
if (t->index > _total_towns)
|
if (t->index >= _total_towns) _total_towns = t->index + 1;
|
||||||
_total_towns = t->index;
|
|
||||||
|
|
||||||
memset(t, 0, sizeof(Town));
|
memset(t, 0, sizeof(Town));
|
||||||
t->index = index;
|
t->index = index;
|
||||||
|
@ -1956,8 +1955,7 @@ static void Load_TOWN(void)
|
||||||
t = GetTown(index);
|
t = GetTown(index);
|
||||||
SlObject(t, _town_desc);
|
SlObject(t, _town_desc);
|
||||||
|
|
||||||
if ((uint)index > _total_towns)
|
if ((uint)index >= _total_towns) _total_towns = index + 1;
|
||||||
_total_towns = index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is to ensure all pointers are within the limits of
|
/* This is to ensure all pointers are within the limits of
|
||||||
|
|
Loading…
Reference in New Issue