Sprintf() causing core dump sporadically on old existing code.
Posted on 2003-11-14
Sun Solaris 2.8 running in 32 bit mode with 6.2 compiler.
I've been running into a problem sporadically in the use of sprintf:
sprintf(char_string, " ... %s", function());
where function() returns a character string
This has been causing core dumps in some places (function return is probably in limbo), often in old code that has been in production for years. It has been popping up when I make changes, usually completely unrelated, other places in the code. So far it has always been caught in development, but may become a production issue.
To fix this copy the function return to a character array and pass that in to sprintf.
This has been a rare bug so far, but you may more of a problem and I need to come up with the cause. Any ideas?