summaryrefslogtreecommitdiff
path: root/src/nsfns.m
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2019-12-23 21:24:37 +0100
committerPhilipp Stephani <phst@google.com>2019-12-23 21:27:23 +0100
commit00c9949158e82fc93135ac62013bee1c08161649 (patch)
treee4905c8be7020ad36d54528a3b10d8cbab79cd0b /src/nsfns.m
parent17c19817f7f4ec918a3a9bb3c957b1aa0463da82 (diff)
downloademacs-00c9949158e82fc93135ac62013bee1c08161649.tar.gz
Remove some undefined behavior related to left shifts.
Found by UBSan. * src/nsfns.m (ns_set_foreground_color, ns_set_background_color): * src/nsimage.m (getPixelAtX:Y:): * src/nsterm.m (ns_color_index_to_rgba): Add explicit casts to avoid undefined behavior when left-shifting beyond the bounds of the int type. * src/macfont.m (METRICS_VALUE): Add explicit casts to avoid undefined behavior when left-shifting a negative value.
Diffstat (limited to 'src/nsfns.m')
-rw-r--r--src/nsfns.m10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index 1d3aea038ae..3e835a71d03 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -255,7 +255,10 @@ ns_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
[col getRed: &r green: &g blue: &b alpha: &alpha];
FRAME_FOREGROUND_PIXEL (f) =
- ARGB_TO_ULONG ((int)(alpha*0xff), (int)(r*0xff), (int)(g*0xff), (int)(b*0xff));
+ ARGB_TO_ULONG ((unsigned long) (alpha * 0xff),
+ (unsigned long) (r * 0xff),
+ (unsigned long) (g * 0xff),
+ (unsigned long) (b * 0xff));
if (FRAME_NS_VIEW (f))
{
@@ -296,7 +299,10 @@ ns_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
[col getRed: &r green: &g blue: &b alpha: &alpha];
FRAME_BACKGROUND_PIXEL (f) =
- ARGB_TO_ULONG ((int)(alpha*0xff), (int)(r*0xff), (int)(g*0xff), (int)(b*0xff));
+ ARGB_TO_ULONG ((unsigned long) (alpha * 0xff),
+ (unsigned long) (r * 0xff),
+ (unsigned long) (g * 0xff),
+ (unsigned long) (b * 0xff));
if (view != nil)
{