Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calls to strdup crashes on linux #6

Open
vafada opened this issue Sep 18, 2022 · 0 comments
Open

calls to strdup crashes on linux #6

vafada opened this issue Sep 18, 2022 · 0 comments

Comments

@vafada
Copy link

vafada commented Sep 18, 2022

calls to strdup crashes on linux

strdup is not a C standard:

https://stackoverflow.com/questions/19641460/using-strdup-in-c11

the cmake file compiles with --std=c11

a simple test to reproduce the crash

$ gcc --version
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#include <stdio.h>
#include <string.h>
 
int main()
{
    char *source = "Hello world";
 
    char* target = strdup(source);
 
    printf("%s", target);
    return 0;
}
$ gcc --std=c11 test.c 
$ ./a.out 
Segmentation fault (core dumped)

I believe this line adds the --std=c11 when compiling:

https://github.com/sonneveld/nagi/blob/master/src/CMakeLists.txt#L4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant