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

Unified Diff: ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc

Issue 2598383002: Fix integer overflow. (Closed)
Patch Set: Fix includes Created 4 years 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: ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
index cfc4f0d6f8c37cf2da4e63a17ef5495930eb79f1..c33ace6a3c165c71b682f615d1753b2eafe90fa9 100644
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
@@ -10,6 +10,7 @@
#include <X11/Xregion.h>
#include <X11/Xutil.h>
+#include <algorithm>
#include <utility>
#include "base/command_line.h"
@@ -1092,7 +1093,15 @@ void DesktopWindowTreeHostX11::SetOpacity(float opacity) {
// X server opacity is in terms of 32 bit unsigned int space, and counts from
// the opposite direction.
// XChangeProperty() expects "cardinality" to be long.
- unsigned long cardinality = static_cast<int>(opacity * 255) * 0x1010101;
sky 2017/01/03 17:54:27 Can you outline where this goes wrong? Before my c
+
+ // Clamp opacity to [0.0 .. 1.0] range.
+ float clamped_opacity = std::max(0.0f, std::min(1.0f, opacity));
sky 2017/01/03 17:54:27 We don't do this anywhere else. It's assumed the v
+ // Scale opacity to [0 .. 255] range.
+ unsigned long opacity_8bit =
+ static_cast<unsigned long>(clamped_opacity * 255.0f);
+ // Use opacity value for all channels.
+ const unsigned long channel_multiplier = 0x1010101;
+ unsigned long cardinality = opacity_8bit * channel_multiplier;
if (cardinality == 0xffffffff) {
XDeleteProperty(xdisplay_, xwindow_,
« 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