There are two problems in the code.
First, left does not have nul-terminated, so strcat will end the scan outside the array with a suitable place to add characters. Put a '\0' at the end of the array.
Secondly, left not large enough to hold the result of calling strcat . There should be enough space for the resulting string, including the nul terminator. Therefore, the size of left must be at least 4 + 9 to allow three characters (plus nul terminator), with which left begins, and 9 characters following from str (provided that gets caused an overflow).
Each of these errors results in undefined behavior that takes into account different results on different platforms.
source share