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 bug in auto disk cache size logic #4506

Merged
merged 1 commit into from
Apr 4, 2020
Merged

Conversation

arvidn
Copy link
Owner

@arvidn arvidn commented Apr 4, 2020

No description provided.

@@ -112,7 +112,7 @@ namespace libtorrent {
MEMORYSTATUSEX ms;
ms.dwLength = sizeof(MEMORYSTATUSEX);
if (GlobalMemoryStatusEx(&ms))
ret = int(ms.ullTotalPhys);
ret = ms.ullTotalPhys;
Copy link
Contributor

@FranciscoPombal FranciscoPombal Apr 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, isn't there still an unsigned -> signed conversion happening here which could return a negative number? If the number is bigger than std::numeric_limits<int64_t>::max(), just truncate to that value, so that a negative number is never returned.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right. I assumed DWORDLONG was signed

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interestingly, there is no warning for this. I think it's safe to assume the amount of memory will not exceed the max for int64_t (given that current hardware only can address 48 bits)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still I think explicitly enforcing the the truncation to std::numeric_limits<int64_t>::max() better conveys the intent for humans, even if the machines don't need it.

@arvidn arvidn added this to the 1.2.6 milestone Apr 4, 2020
@arvidn arvidn merged commit 6c88015 into RC_1_2 Apr 4, 2020
@arvidn arvidn deleted the auto-disk-cache-size branch April 4, 2020 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants