linux: fix signedness issue in uv_exepath()
readlink() returns -1 on error. The <= 0 check failed to catch that because the return value was implicitly cast to size_t, which is unsigned.
This commit is contained in:
parent
75ab1ba774
commit
e504719e17
@ -171,13 +171,17 @@ void uv_loadavg(double avg[3]) {
|
||||
|
||||
|
||||
int uv_exepath(char* buffer, size_t* size) {
|
||||
ssize_t n;
|
||||
|
||||
if (!buffer || !size) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*size = readlink("/proc/self/exe", buffer, *size - 1);
|
||||
if (*size <= 0) return -1;
|
||||
buffer[*size] = '\0';
|
||||
n = readlink("/proc/self/exe", buffer, *size - 1);
|
||||
if (n <= 0) return -1;
|
||||
buffer[n] = '\0';
|
||||
*size = n;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user