FS#1430 - Segfault on resolving certain NewGRF strings in specific environments

Attached to Project: OpenTTD
Opened by divide (divide) - Monday, 12 November 2007, 06:28 GMT
Last edited by Remko Bijker (Rubidium) - Monday, 12 November 2007, 07:46 GMT
Type Bug
Category NewGRF
Status Closed
Assigned To No-one
Operating System All
Severity High
Priority Normal
Reported Version trunk
Due in Version 0.6.0
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


I've came across a bug in which resolving a NewGRF string leads to a segfault.

To reproduce: (tested on r11418)
- download NewCargo and NewShips from ,
- put them on the newgrf list (NewShips first),
- set language to Polish,
- start a new game,
- use cheat to get some money,
- try to fund fishing grounds.

Openttd then segfaults when resolving "Fishing grounds" name for the news message. It seems that is because, when trying to find the gender of the name, it uses GetStringPtr() to find the string, but as table 28 is empty, this returns garbage. I'm puzzled as to why this bug doesn't manifest itself when only NewCargo (and not NewShips) is loaded; I'm also not sure that language needs to be Polish, but I think it has to be some language that checks gender of the industry name.

Anyway, as for the fix: simply replacing GetStringPtr with GetStringWithArgs fixes the problem (as GetStringWithArgs recognizes the 28 prefix of the StrID and reads the string from the proper newgrf table). This solves the segfault and provides the text needed. I've had enough hunting this bug already (that's some last three days), but it's perhaps important to find the exact reason this happens, as this could signal existence of some deeper problem with handling newgrfs.
This task depends upon

Closed by  Remko Bijker (Rubidium)
Monday, 12 November 2007, 20:05 GMT
Reason for closing:  Fixed
Additional comments about closing:  In r11422. Thanks for the patch!