As per the test the 4th element of both arrays are not initialized and hence will contain garbage values. Memcmp returns the difference between the garbage values of the 4th element which will be different on every run of the test. And since the return value of memcmp is returned from main, we are getting random exit code every time.
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
Comment Actions
... which can happen to be zero, right? 1 out of 256.
Please do if (!res) printf("equals") to force the check, then return 0.
Comment Actions
... which can happen to be zero, right? 1 out of 256.
Please do if (!res) printf("equals") to force the check, then return 0.
In cases when value of res is not zero, "equals" will not be printed and hence test will fail.
Since the value of res in unpredictable, could we just do return 0 or ignore the exit code?
Comment Actions
Yes, that's what I meant. A check for the return value of memcmp so that it is not optimized out (though it probably won't anyway at -O0), and then always return 0.