[fpc-devel] Sorting tests
nickysn at gmail.com
Tue Nov 29 21:49:20 CET 2022
On 11/29/22 22:16, J. Gareth Moreton via fpc-devel wrote:
> On 29/11/2022 20:03, Nikolay Nikolov via fpc-devel wrote:
>> if (a<b) and (b<c) then (a<c),
> That's the big one that sorting algorithms rely on... the transitive
> law. If that is violated, then you cannot guarantee a sorted result.
> It doesn't matter if (a < b) or (b < a) return False for equal
> elements, or use (a <=b) or (b <= a) instead, as long as it's
> consistent. Also have to watch out for more subtle instances of it,
> like "if (a < b) then DoX else DoY;" and then having "if (b < a) then
> DoZ else DoQ;".
> While I do wish people would fix any bugs that are found in their own
> code, sometimes we do have to accept that this isn't always possible.
> I think the most famous example I can think of is with SimCity 2000...
> there was a critical bug in it where memory was used after it was
> deallocated. Under DOS and Windows 3.1, this wasn't an issue because
> the memory wouldn't be reused by another application, but under
> Windows 95 this assumption could no longer hold. So, under the
> guidance of Raymond Chen, Microsoft programmed Windows 95 to delay
> actually releasing that block of memory... only for SimCity 2000!
Yes. Horrible. :)
Another example is Quake 2 or 3 (I forgot which one) having a buffer
overflow vulnerability, because of copying (strcpy) the OpenGL
extensions string to a C fixed size buffer (char buf or something
like that). After a certain point, OpenGL video cards became so advanced
and got so many extensions, that the string, returned by the graphics
card simply became too long for that buffer, thus causing Quake to crash
instantly on startup. But since nobody wants to buy a video card, that
doesn't run Quake, graphics card vendors had to implement a hack - the
detect the Quake .exe and report a different, shorter, extensions string.
> fpc-devel maillist - fpc-devel at lists.freepascal.org
More information about the fpc-devel