Live data from Hacker News

How a 20 year old bug in GTA San Andreas surfaced in Windows 11 24H2

cookieplmonster.github.io

271–280 of 315 posts

Re: How a 20 year old bug in GTA San Andreas surfaced in Windows 11 24H2

#271

Earlier quoted context omitted.

User has working software. User updates operating system. User has broken software. That's a problem for the party trying to sell operating system updates.

The software was fundamentally broken before the OS update. It was working by pure random chance with undefined behaviour. It’s a C++ issue, not an OS issue. The same code compiled for another OS would have different random results.

Not a C++ issue, but a sloppy developer issue.

Re: How a 20 year old bug in GTA San Andreas surfaced in Windows 11 24H2

#272

Am I the only one to be annoyed by this...? while (this->m_fBladeAngle > 6.2831855) { this->m_fBladeAngle = this->m_fBladeAngle - 6.2831855; } Like, "let's just write a while loop that could turn into an infinite loop coz I'm too lazy to do a division"

I want to assume that the GTA developers did this hack because it was faster than floating point division on the Playstation 2 or something. But knowing they were able to they were able to blow up loading GTA5 by 5 minutes by just parsing json with sscanf, I don't have much hope.

They were not the only one to make that mistake e.g. rapidjson had to fix the same error, few people expect parsing one token out of sscanf to strlen the entire input (not only that but there are c++ APIs which call sscanf under the hood).

The second error of deduplicating values by linear scanning an array was way more egregious.

Re: How a 20 year old bug in GTA San Andreas surfaced in Windows 11 24H2

#273
post #206

Earlier quoted context omitted.

I interpret "don't allow unintialized locals when declared" as meaning that this call: int n = scanf("%d %d %d", &x, &y, &z); Would be caught, because it takes references to undeclared variables. To be allowed, the programmer would have to initialize the variables beforehand.

Then people would complain about the wasteful initialisation of out-params. Foolishly, perhaps

I think it would make sense to have a keyword that permits unsafe instantiation specifically for the edge cases where initialization is too expensive. But I think it makes sense for the lazy case to be a little bit safer.

Re: How a 20 year old bug in GTA San Andreas surfaced in Windows 11 24H2

#274
post #134

IMHO, if something isn’t part of the contract, it should be randomized. Eg if iteration order of maps isn’t guaranteed in your language, then your language should go out of its way to randomize it. Otherwise, you end up with brittle code: code that works fine until it doesn’t.

one might argue that one of the advantages of languages like C is that you only pay for the features you choose to use, no unnecessary overhead like initializing unused variables

However, the compiler does not tell you this. We're back to the problem that it's possible to have a "working" C program that relies on UB and will therefore break at some point, but the tools will not yell at you for doing this. Whereas in Java or C# you get warnings or errors for using maybe-uninitialized variables.

Also, scanf should be deprecated. Terrible API. Never use scanf or sscanf etc. We managed to get "gets()" deprecated, time to spread that to other parts of the API.

atoi() or atof() etc. work OK, but really you need a parser.

Re: How a 20 year old bug in GTA San Andreas surfaced in Windows 11 24H2

#275
post #250

> all these findings prove that the bug is NOT an issue with Windows 11 24H2, as things like the way the stack is used by internal WinAPI functions are not contractual and they may change at any time, with no prior notice. This reminds me of an excellent article I read a while back, the gist of it was that, given sufficient success, there's no such thing as a private API.

I know there’s an XKCD comic about this

Just bring back spacebar heating

Re: How a 20 year old bug in GTA San Andreas surfaced in Windows 11 24H2

#276
post #94

My takeaway, speaking as someone who leans towards functional programming and immutability, is "this is yet another example of a mutability problem that could never happen in a functional context" (so, for example, this bug would have never been created by Rust unless it was deeply misused)

Could you elaborate? I cannot see how a functional programming language would have protected you from reading a non existing value while not providing a default

It simply would not have allowed you to write code which did that. And you wouldn't have a function like sscanf() either. You'd probably end up with a much more normal looking parser function that returned a value-or-error type.

Re: How a 20 year old bug in GTA San Andreas surfaced in Windows 11 24H2

#277
post #71

> all these findings prove that the bug is NOT an issue with Windows 11 24H2, as things like the way the stack is used by internal WinAPI functions are not contractual and they may change at any time, with no prior notice. The real issue here is the game relying on undefined behavior (uninitialized local variables), and to be honest, I’m shocked that the game didn’t hit this bug on so many OS versions, although as I…

Other than C#, there is no reason to use those other languages for game dev. Unless the game is fairly simple, or you want to risk a fairly long project by employing a language that hasn't been proven in tge space yet (Rust). No shade at any of those languages, I don't even like C#, just being pragmatic.

Unity+C# is now a pretty common combo.

Re: How a 20 year old bug in GTA San Andreas surfaced in Windows 11 24H2

#278

IMHO, if something isn’t part of the contract, it should be randomized. Eg if iteration order of maps isn’t guaranteed in your language, then your language should go out of its way to randomize it. Otherwise, you end up with brittle code: code that works fine until it doesn’t.

I once updated a little shy of 1mloc of Perl 5.8 code to run on Perl 5.32 (ish). There were, overall, remarkably few issues that cropped up. One of these issues (that showed itself a few times) was more or less exactly this: the iteration order through a hash is not defined. It has never been defined, but in Perl 5.8 it was consistent: for the same insertion order of the same set of keys, a hash would always iterate…

At booking.com? :)

Re: How a 20 year old bug in GTA San Andreas surfaced in Windows 11 24H2

#279
Knowing C/C++, I more or less guessed what's happening (uninitialized variable) early in the blog post.

It blows my mind that the languages allow you to leave variables uninitialized which has caused countless bugs (including production bugs that I have seen first hand), and you often need to rely on additional compiler flags or static analysis tools/valgrind etc to catch them. Even though newer languages often use a different solution (default zero value or must initialize a variable before use), people still go back to C/C++ all the time.

Re: How a 20 year old bug in GTA San Andreas surfaced in Windows 11 24H2

#280
post #250

> all these findings prove that the bug is NOT an issue with Windows 11 24H2, as things like the way the stack is used by internal WinAPI functions are not contractual and they may change at any time, with no prior notice. This reminds me of an excellent article I read a while back, the gist of it was that, given sufficient success, there's no such thing as a private API.

I know there’s an XKCD comic about this

https://xkcd.com/1172/
Post reply on HN