In all the years of writing C code, how did I not spot this.
I know memcpy is not safe if src and dst overlap. I know I should use memmove.
This is not news...
Somehow I managed to not take in this detail when dst is ahead of src in memory.
Somehow I have got away with that for god knows how many years.
Just so you know, some versions of gcc are now optimising to copy from right hand back to left hand or some such, in some cases. i.e. memcpy is not safe if src and dst overlap, either way.
Just one of those silly mistakes from the earliest days of learning C code, many decades ago, which somehow had not caused any problems, until today!
Some global editing has been going on this morning to make sure I am not caught out by it again. I feel so stupid. I may have to go and get a new copy of K&R and re-read it :-)