This won't work if your calling convention is cdecl because the caller cleans up the stack, so by skipping the x=1 statement you also skip the stack cleanup code and thus leak stack memory (stack memory, which is more severe than heap memory cos there's usually a lot less).
This shouldn't cause a crash though, so what you'll need to do is to step through the code at the assembler level to find out where it's going wrong. Probably your calculations are off by a few.

A better solution is to return a value and let the caller decide what to do, e.g.
Code:
if (function(1,2,3))
  x=1;
so x=1 is skipped if function() returns zero.