Found a "bug" in the trunk.

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1357
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Found a "bug" in the trunk.

Post by MagicBuzz »

Not really a bug, that's just an unusefull line...

In the function "UpdateStationAcceptance(Station *st, bool show_msg)" in station_cmd.cpp we can find this loop :

Code: Select all

	// Adjust in case our station only accepts fewer kinds of goods
	for (CargoID i = 0; i < NUM_CARGO; i++) {
		uint amt = min(accepts[i], 15);

		// Make sure the station can accept the goods type.
		bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
		if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
				(is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP)))
			amt = 0;

		st->goods[i].acceptance = (amt >= 8);
	}
I'm not sure, but imho the "uint amt = min(accepts, 15);" should be simply replaced by "uint amt = accepts;" right ?
steelixb
Engineer
Engineer
Posts: 21
Joined: 23 Nov 2002 14:14

Post by steelixb »

Not knowing what the code does, surely if accepts is greater than 15, then 15 should be returned and not accepts?
Well, what to put for my signature... hmm... ahh forget it!
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1357
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Post by MagicBuzz »

Yes, for sure.

But if you look at the loop, no wonder if the accepts is higher of 15. We just change it to 0 if it's invalid, or keep a boolean value (amt >= 8 ) if the cargo is valid.

Then the amt variable will be overrided in the next loop. I can't see where is any use for this maximum of 15.

Thus, it's not a type problem, as the accepts value is a uint, and amt is also a unit, so we can't get an overflow problem with higher values.
User avatar
benc
Engineer
Engineer
Posts: 62
Joined: 30 Apr 2007 01:57

Post by benc »

A quick "svn blame" shows that amt used to be bit-shifted before r10266. So the min() was necessary. Now it's not needed, but is mostly harmless. Here's where the logic changed:
r10266 | rubidium | 2007-06-22 07:58:59 -0400 (Fri, 22 Jun 2007) | 2 lines

-Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
Ask a dev to fix if it really bugs you. :)

EDIT: per DaleStan, s/completely/mostly. Reminds me of HHGTTG's entry on Earth.
Last edited by benc on 10 Jul 2007 03:36, edited 2 times in total.
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post by DaleStan »

benc wrote:Now it's not needed, but is completely harmless.
Except for consuming unnecessary CPU cycles.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 18 guests