Abstrct / Schemaverse

The Schemaverse is a space-based strategy game implemented entirely within a PostgreSQL database. Compete against other players using raw SQL commands to command your fleet. Or, if your PL/pgSQL-foo is strong, wield it to write AI and have your fleet command itself!
schemaverse.com
PostgreSQL License
356 stars 39 forks source link

Serious bug in upgrade() #18

Closed cbbrowne closed 12 years ago

cbbrowne commented 12 years ago

function upgrade() declares ship_value as smallint, which indicates a signed 2 byte integer.

Thus, the maximum value of ship_value is 32767.

Unfortunately, the value of SHIP_MAX_SPEED is 50000, which is larger than that.

if you try to upgrade a ship's speed to beyond ~32768, you get an error:

schemaverse@db.schemaverse.com-> select upgrade(34131, 'MAX_SPEED', 5000); ERROR: value "41795" is out of range for type smallint CONTEXT: PL/pgSQL function "upgrade" line 53 at SQL statement

Note that 41795 was the previous value of the maximum speed for that ship; that's a failure of SELECT max_speed INTO ship_value FROM ship WHERE id=reference_id;

The fix should be to change the type of ship_value to integer.

Abstrct commented 12 years ago

ship_value has been changed to integer in the UPGRADE function.

https://github.com/Abstrct/Schemaverse/commit/d187bf1ee3a60255d686e0cbccfe589b863de29e

Thanks for the bug report! -Abstrct

cbbrowne commented 12 years ago

Excellent, thanks!