Skip to content

calls to strdup crashes on linux #6

Description

@vafada

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions