glShaderSource itself won’t cut a source string, unless you have a very very odd driver bug (and if so it would break with every other program that uses shaders too) - the most likely cause of this problem is in your own code.
Have a look at the documentation for glShaderSource - you’ll see that the last parameter is an array of string lengths. One probable cause of this is that you’re just passing in the wrong lengths. Other causes are that your file loader is failing to get the full text or is injecting (or somehow otherwise picking up) garbage into the source string that somehow includes a ‘\0’ (unlikely as printf works). Also, won’t str be out of scope after loadShaderAsString returns? You’re probably corrupting the stack here too, so there’s something else to check.
Set a breakpoint and run in your debugger - you’ll be able to check the string that is being passed to glShaderSource, the lengths you’re passing, and backtrack up the call stack until you discover the point at which it goes bad.
Actually, this will be the problem. Once loadShaderAsString returns the str string object is released and you are returning an invalid pointer. Yes, if you print out immediately the pointer as a string, it will work as nobody else had the chance to overwrite the data at that memory location, but that memory no longer belongs to the string object, it is unallocated memory.