The problem is here:
if (x+y > sizeof(msg)-1){break;}
In the first instance, myMsg is an array declared with a size, so sizeof() knows how big the array is.
In the second instance, msg is an unsized array, so sizeof() returns the size of the pointer, not the length of the array.
Either make a #defined constant for the array size, and use that, or call strlen() to find the length of the string. You could also modify the function to detect the end of the string ('\0') and stop there.
Something like:
if (msg[x+y] == '\0') break;
enjoy,