nagi icon indicating copy to clipboard operation
nagi copied to clipboard

calls to `strdup` crashes on linux

Open vafada opened this issue 2 years ago • 0 comments

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

vafada avatar Sep 18 '22 23:09 vafada