I have a C ++ unit test that produces useful output for stderr and basically noise (unless I am debugging) on stdout, so I would like to redirect stdout to / dev / null.
Curiously, this leads to a segmentation error.
Is there a reason why the code may happen with the error "> / dev / null" and doesn't it work otherwise?
The output is completely printf s if it has any bearing.
It’s hard for me to publish the broken code because this is a study submitted for publication. I hope that there is an “obvious” possible reason based on this description.
post mortem
Segaft was called with the following code:
ArrayElt* array = AllocateArrayOfSize(array_size); int index = GetIndex(..) % array_size; ArrayElt elt = array[index];
The third time I forgot that x % y remains negative when x negative in C / C ++.
Ok, so why did this happen when I was redirected to /dev/null ? I assume that the invalid memory address I was accessing was in the output buffer for stdout - and this buffer is not allocated when it is not needed.
Thanks for the good answers!
source share