Hello I'm trying to copy a character pointer into another character pointer. I currently have

static char *my_kstrdup(const char *buf)
{
    char *ptr, *ret;

    ret = ptr = kmalloc(strlen(buf));
    if(ptr = NULL)
	panic("kmalloc returned NULL");

    for(; *buf != '\0'; ++ptr, ++buf)
	*ptr = *buf;

    *ptr = '\0';

    return ret;
}

it seems to be crashing with the for loop, any advice?

Recommended Answers

All 3 Replies

In if check you are re assigning ptr as NULL

wow I can't believe I missed that, thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.