Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(567)

Unified Diff: base/mime_util_xdg.cc

Issue 7134090: Avoid abs() of unsigned values. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mime_util_xdg.cc
diff --git a/base/mime_util_xdg.cc b/base/mime_util_xdg.cc
index e510b689457b8303ddb9b2e919b647976c37b83d..a25a0d51bd3b7584c8263b81c78bf31624b3d416 100644
--- a/base/mime_util_xdg.cc
+++ b/base/mime_util_xdg.cc
@@ -198,13 +198,13 @@ FilePath IconTheme::GetIconPath(const std::string& icon_name, int size,
}
}
// Now looking for the mostly matched.
- int min_delta_seen = 9999;
+ size_t min_delta_seen = 9999;
for (subdir_iter = subdirs_.begin();
subdir_iter != subdirs_.end();
++subdir_iter) {
SubDirInfo* info = &info_array_[subdir_iter->second];
- int delta = abs(MatchesSize(info, size));
+ size_t delta = MatchesSize(info, size);
if (delta < min_delta_seen) {
FilePath path = GetIconPathUnderSubdir(icon_name, subdir_iter->first);
if (!path.empty()) {
@@ -325,24 +325,22 @@ bool IconTheme::LoadIndexTheme(const FilePath& file) {
size_t IconTheme::MatchesSize(SubDirInfo* info, size_t size) {
if (info->type == SubDirInfo::Fixed) {
- return size - info->size;
+ if (size > info->size)
+ return size - info->size;
+ else
+ return info->size - size;
} else if (info->type == SubDirInfo::Scalable) {
- if (size >= info->min_size && size <= info->max_size) {
- return 0;
- } else {
- return abs(size - info->min_size) < abs(size - info->max_size) ?
- (size - info->min_size) : (size - info->max_size);
- }
+ if (size < info->min_size)
+ return info->min_size - size;
+ if (size > info->max_size)
+ return size - info->max_size;
+ return 0;
} else {
- if (size >= info->size - info->threshold &&
- size <= info->size + info->threshold) {
- return 0;
- } else {
- return abs(size - info->size - info->threshold) <
- abs(size - info->size + info->threshold)
- ? size - info->size - info->threshold
- : size - info->size + info->threshold;
- }
+ if (size + info->threshold < info->size)
+ return info->size - size - info->threshold;
+ if (size > info->size + info->threshold)
+ return size - info->size - info->threshold;
+ return 0;
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698