瀏覽代碼

Fixed unsafe casts

Rainer Deyke 3 年之前
父節點
當前提交
56ae5bbafb
共有 1 個文件被更改,包括 8 次插入4 次删除
  1. 8 4
      core/os/keyboard.h

+ 8 - 4
core/os/keyboard.h

@@ -315,7 +315,8 @@ constexpr Key operator-(uint32_t a, Key b) {
 }
 
 constexpr Key &operator-=(Key &a, int b) {
-	return (Key &)((int &)a -= b);
+  a = static_cast<Key>(static_cast<int>(a) - static_cast<int>(b));
+	return a;
 }
 
 constexpr Key operator+(Key a, int b) {
@@ -339,15 +340,18 @@ constexpr Key operator|(Key a, Key b) {
 }
 
 constexpr Key &operator|=(Key &a, Key b) {
-	return (Key &)((int &)a |= (int)b);
+  a = static_cast<Key>(static_cast<int>(a) | static_cast<int>(b));
+	return a;
 }
 
 constexpr Key &operator|=(Key &a, KeyModifierMask b) {
-	return (Key &)((int &)a |= (int)b);
+  a = static_cast<Key>(static_cast<int>(a) | static_cast<int>(b));
+	return a;
 }
 
 constexpr Key &operator&=(Key &a, KeyModifierMask b) {
-	return (Key &)((int &)a &= (int)b);
+  a = static_cast<Key>(static_cast<int>(a) & static_cast<int>(b));
+	return a;
 }
 
 constexpr Key operator|(Key a, KeyModifierMask b) {