[Scummvm-git-logs] scummvm master -> 21cd732b6063e41f48a08f9485773dd3d7d9567c

dwatteau noreply at scummvm.org
Mon Nov 28 23:43:42 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
21cd732b60 TINSEL: Fix UB for enum TINSEL_EVENT in DW2. PVS-Studio V1016


Commit: 21cd732b6063e41f48a08f9485773dd3d7d9567c
    https://github.com/scummvm/scummvm/commit/21cd732b6063e41f48a08f9485773dd3d7d9567c
Author: Donovan Watteau (contrib at dwatteau.fr)
Date: 2022-11-29T00:41:03+01:00

Commit Message:
TINSEL: Fix UB for enum TINSEL_EVENT in DW2. PVS-Studio V1016

In DW2, some large TINSEL_EVENT values are read, and they're bigger than
the last TINSEL_EVENT value, but we cast them to `enum TINSEL_EVENT`
values in tinlib.cpp, which is apparently "unspecified behavior up to
C++17 and undefined behavior starting from C++17".

  tinlib.cpp:1925:39: runtime error: load of value 9041, which is not
     a valid value for type 'Tinsel::TINSEL_EVENT'
  tinlib.cpp:1935:31: runtime error: load of value 77, which is not
     a valid value for type 'Tinsel::TINSEL_EVENT'

Found with UBSan but the really clear help comes from PVS-Studio
documentation.

Changed paths:
    engines/tinsel/events.h


diff --git a/engines/tinsel/events.h b/engines/tinsel/events.h
index 0fa888591e5..fb03b0ecde3 100644
--- a/engines/tinsel/events.h
+++ b/engines/tinsel/events.h
@@ -87,7 +87,8 @@ enum PLR_EVENT {
  *
  * Note: DW2 renames ENTER & LEAVE to WALKIN & WALKOUT, and has a new LEAVE event
  */
-enum TINSEL_EVENT {
+// ': int' because out-of-range values happen in DW2 and we do enum casts (PVS-Studio V1016)
+enum TINSEL_EVENT : int {
 	NOEVENT, STARTUP, CLOSEDOWN, POINTED, UNPOINT, WALKIN, WALKOUT,
 	PICKUP,	PUTDOWN, WALKTO, LOOK, ACTION, CONVERSE, SHOWEVENT,
 	HIDEEVENT, TALKING, ENDTALK, LEAVE_T2, RESTORE, PROV_WALKTO




More information about the Scummvm-git-logs mailing list