Fix eh_elf path error

The function `readlink` does not null-terminate its strings…
This commit is contained in:
Théophile Bastian 2018-05-09 12:41:01 +02:00
parent 7b6ff32465
commit ba75dfa95f

View file

@ -5,6 +5,7 @@
#include <link.h> #include <link.h>
#include <cstring> #include <cstring>
#include <cassert> #include <cassert>
#include <cctype>
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#include <map> #include <map>
@ -44,10 +45,12 @@ std::string readlink_rec(const char* path) {
strcpy(buf[1], path); strcpy(buf[1], path);
do { do {
int rc = readlink(buf[parity], buf[1-parity], 1024); ssize_t rc = readlink(buf[parity], buf[1-parity], 1024);
parity = 1 - parity; parity = 1 - parity;
if(rc < 0) if(rc < 0)
break; break;
else
buf[parity][rc] = '\0';
} while(true); } while(true);
return std::string(buf[1 - parity]); return std::string(buf[1 - parity]);