News for hackers. Stuff that matters.
Re:Massacring C Pointers by userbinator on Tuesday June 26, 2018 @07:28AM (#17399622)
I know there are already plenty of comments about the problems but might as well give mine too...

In one sentence: this guy managed to reinvent a variant of strcat and get it completely wrong.

Here's a somewhat better version:

    char *combine(char *s, char *t) {
        size_t m = strlen(s), n = strlen(t);
        char *ret = malloc(m + n + 1);
        if(ret) {
            memcpy(ret, s, m);
            strcpy(ret + m, t);
        }
        return ret;
    }
Re:Massacring C Pointers by jmts on Tuesday June 26, 2018 @08:35AM (#17400031)
You already know the length of t. strcpy is inefficient when another memcpy will do.
Re:Massacring C Pointers by jwilk on Tuesday June 26, 2018 @07:53AM (#17399751)
Minor bug:

If s and t are very long and overlapping, m + n could wrap around.