why does readlink function cause a segmentation fault instead of moving the path string to a pointer?

249 Views Asked by At

when I run the code

char* dirPath = (char*) malloc(pathSize); // pathSize is 512 and its pre defined
readlink("/proc/self/exe",dirPath,pathSize); //segfault here

it segfaults. I've tried increasing the value of pathSize or passing the pathSize value one larger into readlink.I've also put the /proc/self/exe in separate variable and passing that that didn't work either. running the program through gdb says.

Program received signal SIGSEGV, Segmentation fault.
__memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:384
384     ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S: No such file or directory.

the code work for a long time but only recently broke

0

There are 0 best solutions below