Reply to post: Re: Just use known patterns ffs

'I bet Russian hackers weren't expecting their target to suck so epically hard as this'

Vic

Re: Just use known patterns ffs

The bug was that the subscript indexer inside the loop was only incremented once regardless of how many times the containing for() iterated. I think it might have been related to compiler optimisations so only showed up in release code as well.

That sounds like a compiler bug; however iffy the code fragment in question, the middle part of the for loop is supposed to be executed on every iteration...

But increment/decrement operators become fun when you start using macros. Consider the following :-

#include <stdio.h>

#define MIN(a,b) ((a) < (b) ? (a) : (b))

void main (void)

{

int foo = 3;

int bar = 4;

int smaller = MIN(++foo, ++bar);

printf("Smaller value is %d\n", smaller);

}

[Apologies for the formatting - ElReg does strange and wonderful things to posts...]

Should print 4, right? It doesn't.

I deliberately used pre-increment here to force the error; post-increment is even more dangerous, because altohugh it would print the value you might nominally expect, it doesn't leave that value in foo...

Yes, this fragement is entirely contrived to demonstrate the point - but I've seen it in the wild.

Vic.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon