Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6066719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:31:51+00:00 2026-05-23T09:31:51+00:00

strdup(null) dumps core. Tried in on ubuntu and freeBSD both. why? Shouldn’t it return

  • 0

strdup(null) dumps core.

Tried in on ubuntu and freeBSD both.

why? Shouldn’t it return null?

char *b = NULL;
a = strdup(b);

This will dump core on strdup call.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:31:51+00:00Added an answer on May 23, 2026 at 9:31 am

    That’s quite ok.

    The documentation implies that it’s argument must be string, if it’s something else, such as a null pointer, it’s anyones guess what’ll happen. In essence, you get undefined behavior when passing a NULL pointer to strdup.

    It’s quite normal for functions to yield undefined behavor if you pass them something you’re not supposed to. Many standard C function such as strcpy, strlen does not accept null pointers either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code: char *strs[] = { string1, string2, NULL }; char *ptr1 =
I tried this but it's not working for me: char * remove_nl(char * newstr)
char *getInput2(char *param) { int data_len; data_len=atoi(getenv(CONTENT_LENGTH)); char input[9]; fgets(input, 9, stdin); return strdup
here is the c code: char **s; s[334]=strdup(test); printf(%s\n,s[334]);` i know that strdup does
Please examine the following code: if (foo->bar == NULL); foo->bar = strdup("Unknown"); I spent
I have come across this before, and the answer has been either to null-terminate
I have few issues regarding when to use malloc or in this case strdup
The following code: #include <stdlib.h> #include <string.h> int main() { char *s = strdup(keep-alive);
What is the purpose of the strdup() function in C?
I've been instructed to write a model strdup by creating a String struct on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.