this is part of the xString.h file ... and it does compile.
I have no doubt it does. The code in the original post will not, thus it cannot be the function producing the result you described. It's difficult to tell you what your problem might be when we don't see code that actually produces the results described.
I suspect, however, that you are not nul-terminating your string.