Skip to main content
Notice removed Reward existing answer by 200_success
Bounty Ended with Cody Gray's answer chosen by 200_success
Notice added Reward existing answer by 200_success
Bounty Started worth 500 reputation by 200_success
Tweeted twitter.com/StackCodeReview/status/814088466921295873
edited tags
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481
Source Link
Junius L
  • 779
  • 1
  • 9
  • 13

Implementing realloc in C

I have an assignment to implement realloc in C, This's my code please review it.

void    *my_realloc(void *ptr, size_t len)
{
    void    *real;

    real = malloc(len);
    memset(real, 0, len);
    if (real)
        memcpy(real, ptr, len);
    free(ptr);
    return (real);
}