Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some signed/unsigned int comparison issues #167

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions pxr/base/lib/arch/systemInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ _DynamicSizedRead(
// Repeatedly invoke the callback with our buffer until it's big enough.
size_t size = initialSize;
while (!callback(buffer.get(), &size)) {
if (size == -1) {
if (size == static_cast<size_t>(-1)) {
// callback is never going to succeed.
return std::string();
}
Expand All @@ -119,7 +119,16 @@ ArchGetExecutablePath()
_DynamicSizedRead(ARCH_PATH_MAX,
[](char* buffer, size_t* size) {
const ssize_t n = readlink("/proc/self/exe", buffer, *size);
if (n >= *size) {
// Need to do this check BEFORE the n >= *size, because
// when comparing signed and unsigned, the signed is
// automatically converted to unsigned, so -1 >= 2U is true.
if (n == -1) {
ARCH_WARNING("Unable to read /proc/self/exe to obtain "
"executable path");
*size = -1;
return false;
}
else if (static_cast<size_t>(n) >= *size) {
// Find out how much space we need.
struct stat sb;
if (lstat("/proc/self/exe", &sb) == 0) {
Expand All @@ -131,12 +140,6 @@ ArchGetExecutablePath()
}
return false;
}
else if (n == -1) {
ARCH_WARNING("Unable to read /proc/self/exe to obtain "
"executable path");
*size = -1;
return false;
}
else {
buffer[n] = '\0';
return true;
Expand Down