]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Fix signed int overflows and tidy nearby documentation
authorbones_was_here <bones_was_here@xonotic.au>
Tue, 23 Jan 2024 22:10:40 +0000 (08:10 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Mon, 29 Jan 2024 15:27:04 +0000 (01:27 +1000)
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
16 files changed:
cl_parse.c
cmd.h
cvar.c
cvar.h
gl_rmain.c
gl_textures.c
mdfour.c
model_alias.c
model_shared.h
netconn.c
protocol.h
prvm_cmds.c
prvm_cmds.h
quakedef.h
render.h
sbar.c

index f02f63e169c147d5d3066f4b34e5e34d195f4c67..dbeda3864f362d9fc8721b9b4822841b138203ab 100644 (file)
@@ -1067,9 +1067,10 @@ static void CL_UpdateItemsAndWeapon(void)
        // check for important changes
 
        // set flash times
+       // UBSan: unsigned literals because left shifting by 31 causes signed overflow, although it works as expected on x86.
        if (cl.olditems != cl.stats[STAT_ITEMS])
                for (j = 0;j < 32;j++)
-                       if ((cl.stats[STAT_ITEMS] & (1<<j)) && !(cl.olditems & (1<<j)))
+                       if ((cl.stats[STAT_ITEMS] & (1u<<j)) && !(cl.olditems & (1u<<j)))
                                cl.item_gettime[j] = cl.time;
        cl.olditems = cl.stats[STAT_ITEMS];
 
diff --git a/cmd.h b/cmd.h
index cc912f31767adf280e4e180f882a7deab10422ca..ada9769c433282a40d75ea69344c26799dd37d17 100644 (file)
--- a/cmd.h
+++ b/cmd.h
@@ -44,34 +44,35 @@ The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute ();
 struct cmd_state_s;
 
 // Command flags
-#define CF_NONE 0
-#define CF_CLIENT               (1<<0)  // cvar/command that only the client can change/execute
-#define CF_SERVER               (1<<1)  // cvar/command that only the server can change/execute
-#define CF_CLIENT_FROM_SERVER   (1<<2)  // command that the server is allowed to execute on the client
-#define CF_SERVER_FROM_CLIENT   (1<<3)  // command the client is allowed to execute on the server as a stringcmd
-#define CF_CHEAT                (1<<4)  // command or cvar that gives an unfair advantage over other players and is blocked unless sv_cheats is 1
-#define CF_ARCHIVE              (1<<5)  // cvar should have its set value saved to config.cfg and persist across sessions
-#define CF_READONLY             (1<<6)  // cvar cannot be changed from the console or the command buffer
-#define CF_NOTIFY               (1<<7)  // cvar should trigger a chat notification to all connected clients when changed
-#define CF_SERVERINFO           (1<<8)  // command or cvar relevant to serverinfo string handling
-#define CF_USERINFO             (1<<9)  // command or cvar used to communicate userinfo to the server
-#define CF_PERSISTENT           (1<<10) // cvar must not be reset on gametype switch (such as scr_screenshot_name, which otherwise isn't set to the mod name properly)
-#define CF_PRIVATE              (1<<11) // cvar should not be $ expanded or sent to the server under any circumstances (rcon_password, etc)
-#define CF_MAXFLAGSVAL          ((1<<12) - 1)    // used to determine if flags is valid
+#define CF_NONE 0u
+#define CF_CLIENT               (1u<<0)  ///< cvar/command that only the client can change/execute
+#define CF_SERVER               (1u<<1)  ///< cvar/command that only the server can change/execute
+#define CF_CLIENT_FROM_SERVER   (1u<<2)  ///< command that the server is allowed to execute on the client
+#define CF_SERVER_FROM_CLIENT   (1u<<3)  ///< command the client is allowed to execute on the server as a stringcmd
+#define CF_CHEAT                (1u<<4)  ///< command or cvar that gives an unfair advantage over other players and is blocked unless sv_cheats is 1
+#define CF_ARCHIVE              (1u<<5)  ///< cvar should have its set value saved to config.cfg and persist across sessions
+#define CF_READONLY             (1u<<6)  ///< cvar cannot be changed from the console or the command buffer
+#define CF_NOTIFY               (1u<<7)  ///< cvar should trigger a chat notification to all connected clients when changed
+#define CF_SERVERINFO           (1u<<8)  ///< command or cvar relevant to serverinfo string handling
+#define CF_USERINFO             (1u<<9)  ///< command or cvar used to communicate userinfo to the server
+#define CF_PERSISTENT           (1u<<10) ///< cvar must not be reset on gametype switch (such as scr_screenshot_name, which otherwise isn't set to the mod name properly)
+#define CF_PRIVATE              (1u<<11) ///< cvar should not be $ expanded or sent to the server under any circumstances (rcon_password, etc)
+#define CF_MAXFLAGSVAL          ((1u<<12) - 1) ///< used to determine if flags is valid
 // for internal use only!
-#define CF_REGISTERED (1<<29)  // created by Cvar_RegisterVariable()
-#define CF_DEFAULTSET (1<<30)
-#define CF_ALLOCATED (1<<31)   // created by Cvar_Get() (console or QC)
+#define CF_REGISTERED           (1u<<29) ///< created by Cvar_RegisterVariable()
+#define CF_DEFAULTSET           (1u<<30)
+#define CF_ALLOCATED            (1u<<31) ///< created by Cvar_Get() (console or QC)
+// UBSan: unsigned literals because left shifting by 31 causes signed overflow, although it works as expected on x86.
 
-#define CF_SHARED 3
+#define CF_SHARED (CF_CLIENT | CF_SERVER)
 
 typedef void(*xcommand_t) (struct cmd_state_s *cmd);
 
 typedef enum cmd_source_s
 {
-       src_client,             ///< came in over a net connection as a clc_stringcmd
-                                       ///< host_client will be valid during this state.
-       src_local               ///< from the command buffer
+       src_client,  ///< came in over a net connection as a clc_stringcmd
+                    ///< host_client will be valid during this state.
+       src_local    ///< from the command buffer
 } cmd_source_t;
 
 typedef struct cmd_alias_s
@@ -79,8 +80,8 @@ typedef struct cmd_alias_s
        struct cmd_alias_s *next;
        char name[MAX_ALIAS_NAME];
        char *value;
-       qbool initstate; // indicates this command existed at init
-       char *initialvalue; // backup copy of value at init
+       qbool initstate;           ///< indicates this command existed at init
+       char *initialvalue;        ///< backup copy of value at init
 } cmd_alias_t;
 
 typedef struct cmd_function_s
@@ -91,9 +92,9 @@ typedef struct cmd_function_s
        const char *description;
        xcommand_t function;
        qbool qcfunc;
-       struct cmd_function_s *overridden; // the engine cmd overriden by this QC cmd, if applicable
+       struct cmd_function_s *overridden; ///< the engine cmd overriden by this QC cmd, if applicable
        qbool autofunc;
-       qbool initstate; // indicates this command existed at init
+       qbool initstate;                   ///< indicates this command existed at init
 } cmd_function_t;
 
 /// container for user-defined QC functions and aliases, shared between different command interpreters
@@ -135,13 +136,13 @@ typedef struct cmd_state_s
 
        cmd_buf_t *cbuf;
 
-       cmd_userdefined_t *userdefined; // possible csqc functions and aliases to execute
+       cmd_userdefined_t *userdefined;   ///< possible csqc functions and aliases to execute
 
        cmd_function_t *engine_functions;
 
-       struct cvar_state_s *cvars; // which cvar system is this cmd state able to access? (&cvars_all or &cvars_null)
-       unsigned cvars_flagsmask; // which CVAR_* flags should be visible to this interpreter? (CF_CLIENT | CF_SERVER, or just CF_SERVER)
-       unsigned cmd_flagsmask; // cmd flags that identify this interpreter
+       struct cvar_state_s *cvars;       ///< which cvar system is this cmd state able to access? (&cvars_all or &cvars_null)
+       unsigned cvars_flagsmask;         ///< which CVAR_* flags should be visible to this interpreter? (CF_CLIENT | CF_SERVER, or just CF_SERVER)
+       unsigned cmd_flagsmask;           ///< cmd flags that identify this interpreter
 
        qbool (*Handle)(struct cmd_state_s *, struct cmd_function_s *, const char *, size_t, enum cmd_source_s);
 }
@@ -162,14 +163,14 @@ typedef struct cmd_input_s
        qbool pending;
 } cmd_input_t;
 
-extern cmd_userdefined_t cmd_userdefined_all; // aliases and csqc functions
-extern cmd_userdefined_t cmd_userdefined_null; // intentionally empty
+extern cmd_userdefined_t cmd_userdefined_all;  ///< aliases and csqc functions
+extern cmd_userdefined_t cmd_userdefined_null; ///< intentionally empty
 
-// command interpreter for local commands injected by SVQC, CSQC, MQC, server or client engine code
-// uses cmddefs_all
+/// command interpreter for local commands injected by SVQC, CSQC, MQC, server or client engine code
+/// uses cmddefs_all
 extern cmd_state_t *cmd_local;
-// command interpreter for server commands received over network from clients
-// uses cmddefs_null
+/// command interpreter for server commands received over network from clients
+/// uses cmddefs_null
 extern cmd_state_t *cmd_serverfromclient;
 
 extern qbool host_stuffcmdsrun;
@@ -201,7 +202,7 @@ void Cbuf_Clear(cmd_buf_t *cbuf);
 
 //===========================================================================
 
-/*
+/**
 
 Command execution takes a null terminated string, breaks it into tokens,
 then searches for a command or variable that matches the first token.
@@ -215,15 +216,15 @@ not apropriate.
 void Cmd_Init(void);
 void Cmd_Shutdown(void);
 
-// called by Host_Init, this marks cvars, commands and aliases with their init values
+/// called by Host_Init, this marks cvars, commands and aliases with their init values
 void Cmd_SaveInitState(void);
-// called by FS_GameDir_f, this restores cvars, commands and aliases to init values
+/// called by FS_GameDir_f, this restores cvars, commands and aliases to init values
 void Cmd_RestoreInitState(void);
 
+/// called by the init functions of other parts of the program to
+/// register commands and functions to call for them.
+/// The cmd_name is referenced later, so it should not be in temp memory
 void Cmd_AddCommand(unsigned flags, const char *cmd_name, xcommand_t function, const char *description);
-// called by the init functions of other parts of the program to
-// register commands and functions to call for them.
-// The cmd_name is referenced later, so it should not be in temp memory
 
 /// used by the cvar code to check for cvar / command name overlap
 qbool Cmd_Exists (cmd_state_t *cmd, const char *cmd_name);
@@ -243,13 +244,12 @@ void Cmd_CompleteAliasPrint (cmd_state_t *cmd, const char *partial);
 // Enhanced console completion by Fett erich@heintz.com
 // Added by EvilTypeGuy eviltypeguy@qeradiant.com
 
-// The functions that execute commands get their parameters with these
-// functions. Cmd_Argv(cmd, ) will return an empty string, not a NULL
-// if arg > argc, so string operations are always safe.
+// The functions that execute commands get their parameters with these functions.
 static inline int Cmd_Argc (cmd_state_t *cmd)
 {
        return cmd->argc;
 }
+/// Cmd_Argv(cmd, ) will return an empty string (not a NULL) if arg > argc, so string operations are always safe.
 static inline const char *Cmd_Argv(cmd_state_t *cmd, int arg)
 {
        if (arg >= cmd->argc )
diff --git a/cvar.c b/cvar.c
index 3008bb2088bba4d056f38c5ac48b92094e6fe078..b1d7d91a4f7c8c5025932f1531c44b2bfadd4369 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -694,7 +694,7 @@ Cvar_Get
 Adds a newly allocated variable to the variable list or sets its value.
 ============
 */
-cvar_t *Cvar_Get(cvar_state_t *cvars, const char *name, const char *value, int flags, const char *newdescription)
+cvar_t *Cvar_Get(cvar_state_t *cvars, const char *name, const char *value, unsigned flags, const char *newdescription)
 {
        cvar_t *cvar;
        int i;
diff --git a/cvar.h b/cvar.h
index 709bc6aaf7a296fb49493128c401eed34995d057..a489e1dcc9437fb679a87086b6ff6c0823bfbe49 100644 (file)
--- a/cvar.h
+++ b/cvar.h
@@ -193,7 +193,7 @@ void Cvar_Del_f(struct cmd_state_s *cmd);
 
 /// allocates a cvar by name and returns its address,
 /// or merely sets its value if it already exists.
-cvar_t *Cvar_Get(cvar_state_t *cvars, const char *name, const char *value, int flags, const char *newdescription);
+cvar_t *Cvar_Get(cvar_state_t *cvars, const char *name, const char *value, unsigned flags, const char *newdescription);
 
 extern const char *cvar_dummy_description; // ALWAYS the same pointer
 
index cb77104b063eacf27d2667955ecdd8fbe0c683b6..cc0895cd3bbbcb34d1f0c8a1aeca07f882426a2e 100644 (file)
@@ -1023,7 +1023,7 @@ static char *ShaderModeInfo_GetShaderText(shadermodeinfo_t *modeinfo, qbool prin
 
 static void R_GLSL_CompilePermutation(r_glsl_permutation_t *p, unsigned int mode, uint64_t permutation)
 {
-       int i;
+       unsigned i;
        int ubibind;
        int sampler;
        shadermodeinfo_t *modeinfo = &shadermodeinfo[SHADERLANGUAGE_GLSL][mode];
@@ -1359,7 +1359,7 @@ static void R_SetupShader_SetPermutationGLSL(unsigned int mode, uint64_t permuta
                        if (!r_glsl_permutation->program)
                        {
                                // remove features until we find a valid permutation
-                               int i;
+                               unsigned i;
                                for (i = 0;i < SHADERPERMUTATION_COUNT;i++)
                                {
                                        // reduce i more quickly whenever it would not remove any bits
@@ -1418,7 +1418,7 @@ void R_GLSL_Restart_f(cmd_state_t *cmd)
 
 static void R_GLSL_DumpShader_f(cmd_state_t *cmd)
 {
-       int i, language, mode, dupe;
+       unsigned i, language, mode, dupe;
        char *text;
        shadermodeinfo_t *modeinfo;
        qfile_t *file;
index b1cc74a114cc9395727c7dea64be377d8ac05114..100989729b7742f82d7aef250ecc83493fdd49e5 100644 (file)
@@ -1969,7 +1969,8 @@ rtexture_t *R_LoadTextureDDSFile(rtexturepool_t *rtexturepool, const char *filen
                unsigned char *p = mipnewpixels;
                for (i = bytesperblock == 16 ? 8 : 0;i < (int)mipsize_total;i += bytesperblock, p += 4)
                {
-                       c = mippixels_start[i] + 256*mippixels_start[i+1] + 65536*mippixels_start[i+2] + 16777216*mippixels_start[i+3];
+                       // UBSan: unsigned literals because promotion to int causes signed overflow when mippixels_start >= 128
+                       c = mippixels_start[i] + 256u*mippixels_start[i+1] + 65536u*mippixels_start[i+2] + 16777216u*mippixels_start[i+3];
                        p[2] = (((c >> 11) & 0x1F) + ((c >> 27) & 0x1F)) * (0.5f / 31.0f * 255.0f);
                        p[1] = (((c >>  5) & 0x3F) + ((c >> 21) & 0x3F)) * (0.5f / 63.0f * 255.0f);
                        p[0] = (((c      ) & 0x1F) + ((c >> 16) & 0x1F)) * (0.5f / 31.0f * 255.0f);
@@ -2014,7 +2015,8 @@ rtexture_t *R_LoadTextureDDSFile(rtexturepool_t *rtexturepool, const char *filen
                {
                        for (i = bytesperblock == 16 ? 8 : 0;i < mipsize;i += bytesperblock)
                        {
-                               c = mippixels[i] + 256*mippixels[i+1] + 65536*mippixels[i+2] + 16777216*mippixels[i+3];
+                               // UBSan: unsigned literals because promotion to int causes signed overflow when mippixels >= 128
+                               c = mippixels[i] + 256u*mippixels[i+1] + 65536u*mippixels[i+2] + 16777216u*mippixels[i+3];
                                avgcolor[0] += ((c >> 11) & 0x1F) + ((c >> 27) & 0x1F);
                                avgcolor[1] += ((c >>  5) & 0x3F) + ((c >> 21) & 0x3F);
                                avgcolor[2] += ((c      ) & 0x1F) + ((c >> 16) & 0x1F);
index ae92e3758af2ac487f1b732662fe731a6d1cda79..5164994a01e246974c6ae8995a072c1f4b39f1b6 100644 (file)
--- a/mdfour.c
+++ b/mdfour.c
@@ -98,8 +98,9 @@ static void copy64(uint32_t *M, const unsigned char *in)
 {
        int i;
 
+       // UBSan: (unsigned) is because promotion to int causes signed overflow when in[] >= 128
        for (i=0;i<16;i++)
-               M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) |
+               M[i] = ((unsigned)in[i*4+3]<<24) | (in[i*4+2]<<16) |
                        (in[i*4+1]<<8) | (in[i*4+0]<<0);
 }
 
index aea60dad8a10bb45ed1247528151cd2aeba45ac3..649324d17e2a9842d6e01358e459401ec808e7bd 100644 (file)
@@ -1041,7 +1041,7 @@ void Mod_IDP0_Load(model_t *mod, void *buffer, void *bufferend)
        BOUNDI((int)loadmodel->synctype,0,2);
        // convert model flags to EF flags (MF_ROCKET becomes EF_ROCKET, etc)
        i = LittleLong (pinmodel->flags);
-       loadmodel->effects = ((i & 255) << 24) | (i & 0x00FFFF00);
+       loadmodel->effects = (((unsigned)i & 255) << 24) | (i & 0x00FFFF00);
 
        if (strstr(r_nolerp_list.string, loadmodel->name))
                loadmodel->nolerp = true;
@@ -1616,7 +1616,7 @@ void Mod_IDP3_Load(model_t *mod, void *buffer, void *bufferend)
        loadmodel->synctype = ST_RAND;
        // convert model flags to EF flags (MF_ROCKET becomes EF_ROCKET, etc)
        i = LittleLong (pinmodel->flags);
-       loadmodel->effects = ((i & 255) << 24) | (i & 0x00FFFF00);
+       loadmodel->effects = (((unsigned)i & 255) << 24) | (i & 0x00FFFF00);
 
        // set up some global info about the model
        loadmodel->numframes = LittleLong(pinmodel->num_frames);
index cf5e02dc1ec4450210fceb52f9767a01ca738caf..39572b5408315dc02d7dd7a8bba25a8483849620 100644 (file)
@@ -442,7 +442,7 @@ typedef struct model_s
        // all models use textures...
        rtexturepool_t  *texturepool;
        // EF_* flags (translated from the model file's different flags layout)
-       int                             effects;
+       unsigned                                effects;
        // number of QC accessible frame(group)s in the model
        int                             numframes;
        // number of QC accessible skin(group)s in the model
index 6a78bd7e8b2ebb4befaae2d7e42416792d5d4e41..5b569bf713e8494bd194306d1114d452273e6b33 100644 (file)
--- a/netconn.c
+++ b/netconn.c
@@ -1353,8 +1353,8 @@ static int NetConn_ReceivedMessage(netconn_t *conn, const unsigned char *data, s
                conn->packetsReceived++;
                reliable_message = (sequence >> 31) != 0;
                reliable_ack = (sequence_ack >> 31) != 0;
-               sequence &= ~(1<<31);
-               sequence_ack &= ~(1<<31);
+               sequence &= ~(1u<<31);
+               sequence_ack &= ~(1u<<31);
                if (sequence <= conn->qw.incoming_sequence)
                {
                        //Con_DPrint("Got a stale datagram\n");
index 047262d6a979604c1cefb5096f141674bdd8b2ab..5a747a050a61ee55430764807696514ec402c0dc 100644 (file)
@@ -109,80 +109,82 @@ void Protocol_Names(char *buffer, size_t buffersize);
 #define PFLAGS_FULLDYNAMIC             128 // must be set or the light fields are ignored
 
 // if the high bit of the servercmd is set, the low bits are fast update flags:
-#define U_MOREBITS             (1<<0)
-#define U_ORIGIN1              (1<<1)
-#define U_ORIGIN2              (1<<2)
-#define U_ORIGIN3              (1<<3)
-#define U_ANGLE2               (1<<4)
-// LadyHavoc: U_NOLERP was only ever used for monsters, so I renamed it U_STEP
-#define U_STEP                 (1<<5)
-#define U_FRAME                        (1<<6)
-// just differentiates from other updates
-#define U_SIGNAL               (1<<7)
-
-#define U_ANGLE1               (1<<8)
-#define U_ANGLE3               (1<<9)
-#define U_MODEL                        (1<<10)
-#define U_COLORMAP             (1<<11)
-#define U_SKIN                 (1<<12)
-#define U_EFFECTS              (1<<13)
-#define U_LONGENTITY   (1<<14)
+#define U_MOREBITS       (1u<<0)
+#define U_ORIGIN1        (1u<<1)
+#define U_ORIGIN2        (1u<<2)
+#define U_ORIGIN3        (1u<<3)
+#define U_ANGLE2         (1u<<4)
+// LadyHavoc: U_NOLERP was uonly ever used for monsters, so I renamed it U_STEP
+#define U_STEP           (1u<<5)
+#define U_FRAME          (1u<<6)
+// just differentiates fromu other updates
+#define U_SIGNAL         (1u<<7)
+
+#define U_ANGLE1         (1u<<8)
+#define U_ANGLE3         (1u<<9)
+#define U_MODEL          (1u<<10)
+#define U_COLORMAP       (1u<<11)
+#define U_SKIN           (1u<<12)
+#define U_EFFECTS        (1u<<13)
+#define U_LONGENTITY     (1u<<14)
 
 // LadyHavoc: protocol extension
-#define U_EXTEND1              (1<<15)
+#define U_EXTEND1        (1u<<15)
 // LadyHavoc: first extend byte
-#define U_DELTA                        (1<<16) // no data, while this is set the entity is delta compressed (uses previous frame as a baseline, meaning only things that have changed from the previous frame are sent, except for the forced full update every half second)
-#define U_ALPHA                        (1<<17) // 1 byte, 0.0-1.0 maps to 0-255, not sent if exactly 1, and the entity is not sent if <=0 unless it has effects (model effects are checked as well)
-#define U_SCALE                        (1<<18) // 1 byte, scale / 16 positive, not sent if 1.0
-#define U_EFFECTS2             (1<<19) // 1 byte, this is .effects & 0xFF00 (second byte)
-#define U_GLOWSIZE             (1<<20) // 1 byte, encoding is float/4.0, unsigned, not sent if 0
-#define U_GLOWCOLOR            (1<<21) // 1 byte, palette index, default is 254 (white), this IS used for darklight (allowing colored darklight), however the particles from a darklight are always black, not sent if default value (even if glowsize or glowtrail is set)
-#define U_COLORMOD             (1<<22) // 1 byte, 3 bit red, 3 bit green, 2 bit blue, this lets you tint an object artifically, so you could make a red rocket, or a blue fiend...
-#define U_EXTEND2              (1<<23) // another byte to follow
+#define U_DELTA          (1u<<16) ///< no data, while this is set the entity is delta compressed (uses previous frame as a baseline, meaning only things that have changed from the previous frame are sent, except for the forced full update every half second)
+#define U_ALPHA          (1u<<17) ///< 1 byte, 0.0-1.0 maps to 0-255, not sent if exactly 1, and the entity is not sent if <=0 unless it has effects (model effects are checked as well)
+#define U_SCALE          (1u<<18) ///< 1 byte, scale / 16 positive, not sent if 1.0
+#define U_EFFECTS2       (1u<<19) ///< 1 byte, this is .effects & 0xFF00 (second byte)
+#define U_GLOWSIZE       (1u<<20) ///< 1 byte, encoding is float/4.0, unsigned, not sent if 0
+#define U_GLOWCOLOR      (1u<<21) ///< 1 byte, palette index, default is 254 (white), this IS used for darklight (allowing colored darklight), however the particles from a darklight are always black, not sent if default value (even if glowsize or glowtrail is set)
+#define U_COLORMOD       (1u<<22) ///< 1 byte, 3 bit red, 3 bit green, 2 bit blue, this lets you tint an object artifically, so you could make a red rocket, or a blue fiend...
+#define U_EXTEND2        (1u<<23) ///< another byte to follow
 // LadyHavoc: second extend byte
-#define U_GLOWTRAIL            (1<<24) // leaves a trail of particles (of color .glowcolor, or black if it is a negative glowsize)
-#define U_VIEWMODEL            (1<<25) // attachs the model to the view (origin and angles become relative to it), only shown to owner, a more powerful alternative to .weaponmodel and such
-#define U_FRAME2               (1<<26) // 1 byte, this is .frame & 0xFF00 (second byte)
-#define U_MODEL2               (1<<27) // 1 byte, this is .modelindex & 0xFF00 (second byte)
-#define U_EXTERIORMODEL        (1<<28) // causes this model to not be drawn when using a first person view (third person will draw it, first person will not)
-#define U_UNUSED29             (1<<29) // future expansion
-#define U_UNUSED30             (1<<30) // future expansion
-#define U_EXTEND3              (1<<31) // another byte to follow, future expansion
-
-#define        SU_VIEWHEIGHT   (1<<0)
-#define        SU_IDEALPITCH   (1<<1)
-#define        SU_PUNCH1               (1<<2)
-#define        SU_PUNCH2               (1<<3)
-#define        SU_PUNCH3               (1<<4)
-#define        SU_VELOCITY1    (1<<5)
-#define        SU_VELOCITY2    (1<<6)
-#define        SU_VELOCITY3    (1<<7)
-//define       SU_AIMENT               (1<<8)  AVAILABLE BIT
-#define        SU_ITEMS                (1<<9)
-#define        SU_ONGROUND             (1<<10)         // no data follows, the bit is it
-#define        SU_INWATER              (1<<11)         // no data follows, the bit is it
-#define        SU_WEAPONFRAME  (1<<12)
-#define        SU_ARMOR                (1<<13)
-#define        SU_WEAPON               (1<<14)
-#define SU_EXTEND1             (1<<15)
+#define U_GLOWTRAIL      (1u<<24) ///< leaves a trail of particles (of color .glowcolor, or black if it is a negative glowsize)
+#define U_VIEWMODEL      (1u<<25) ///< attachs the model to the view (origin and angles become relative to it), only shown to owner, a more powerful alternative to .weaponmodel and such
+#define U_FRAME2         (1u<<26) ///< 1 byte, this is .frame & 0xFF00 (second byte)
+#define U_MODEL2         (1u<<27) ///< 1 byte, this is .modelindex & 0xFF00 (second byte)
+#define U_EXTERIORMODEL  (1u<<28) ///< causes this model to not be drawn when using a first person view (third person will draw it, first person will not)
+#define U_UNUSED29       (1u<<29) ///< future expansion
+#define U_UNUSED30       (1u<<30) ///< future expansion
+#define U_EXTEND3        (1u<<31) ///< another byte to follow, future expansion
+// UBSan: unsigned literals because left shifting by 31 causes signed overflow, although it works as expected on x86.
+
+#define SU_VIEWHEIGHT    (1u<<0)
+#define SU_IDEALPITCH    (1u<<1)
+#define SU_PUNCH1        (1u<<2)
+#define SU_PUNCH2        (1u<<3)
+#define SU_PUNCH3        (1u<<4)
+#define SU_VELOCITY1     (1u<<5)
+#define SU_VELOCITY2     (1u<<6)
+#define SU_VELOCITY3     (1u<<7)
+//#define SU_AIMENT        (1u<<8)  AVAILABLE BIT
+#define SU_ITEMS         (1u<<9)
+#define SU_ONGROUND      (1u<<10) ///< no data follows, the bit is it
+#define SU_INWATER       (1u<<11) ///< no data follows, the bit is it
+#define SU_WEAPONFRAME   (1u<<12)
+#define SU_ARMOR         (1u<<13)
+#define SU_WEAPON        (1u<<14)
+#define SU_EXTEND1       (1u<<15)
 // first extend byte
-#define SU_PUNCHVEC1   (1<<16)
-#define SU_PUNCHVEC2   (1<<17)
-#define SU_PUNCHVEC3   (1<<18)
-#define SU_VIEWZOOM            (1<<19) // byte factor (0 = 0.0 (not valid), 255 = 1.0)
-#define SU_UNUSED20            (1<<20)
-#define SU_UNUSED21            (1<<21)
-#define SU_UNUSED22            (1<<22)
-#define SU_EXTEND2             (1<<23) // another byte to follow, future expansion
+#define SU_PUNCHVEC1     (1u<<16)
+#define SU_PUNCHVEC2     (1u<<17)
+#define SU_PUNCHVEC3     (1u<<18)
+#define SU_VIEWZOOM      (1u<<19) ///< byte factor (0 = 0.0 (not valid), 255 = 1.0)
+#define SU_UNUSED20      (1u<<20)
+#define SU_UNUSED21      (1u<<21)
+#define SU_UNUSED22      (1u<<22)
+#define SU_EXTEND2       (1u<<23) ///< another byte to follow, future expansion
 // second extend byte
-#define SU_UNUSED24            (1<<24)
-#define SU_UNUSED25            (1<<25)
-#define SU_UNUSED26            (1<<26)
-#define SU_UNUSED27            (1<<27)
-#define SU_UNUSED28            (1<<28)
-#define SU_UNUSED29            (1<<29)
-#define SU_UNUSED30            (1<<30)
-#define SU_EXTEND3             (1<<31) // another byte to follow, future expansion
+#define SU_UNUSED24      (1u<<24)
+#define SU_UNUSED25      (1u<<25)
+#define SU_UNUSED26      (1u<<26)
+#define SU_UNUSED27      (1u<<27)
+#define SU_UNUSED28      (1u<<28)
+#define SU_UNUSED29      (1u<<29)
+#define SU_UNUSED30      (1u<<30)
+#define SU_EXTEND3       (1u<<31) ///< another byte to follow, future expansion
+// UBSan: unsigned literals because left shifting by 31 causes signed overflow, although it works as expected on x86.
 
 // a sound with no channel is a local only sound
 #define        SND_VOLUME              (1<<0)          // a byte
@@ -609,43 +611,44 @@ entityframe_database_t;
 // order of the bits to minimize overhead from extend bytes
 
 // enough to describe a nail, gib, shell casing, bullet hole, or rocket
-#define E_ORIGIN1              (1<<0)
-#define E_ORIGIN2              (1<<1)
-#define E_ORIGIN3              (1<<2)
-#define E_ANGLE1               (1<<3)
-#define E_ANGLE2               (1<<4)
-#define E_ANGLE3               (1<<5)
-#define E_MODEL1               (1<<6)
-#define E_EXTEND1              (1<<7)
+#define E_ORIGIN1        (1u<<0)
+#define E_ORIGIN2        (1u<<1)
+#define E_ORIGIN3        (1u<<2)
+#define E_ANGLE1         (1u<<3)
+#define E_ANGLE2         (1u<<4)
+#define E_ANGLE3         (1u<<5)
+#define E_MODEL1         (1u<<6)
+#define E_EXTEND1        (1u<<7)
 
 // enough to describe almost anything
-#define E_FRAME1               (1<<8)
-#define E_EFFECTS1             (1<<9)
-#define E_ALPHA                        (1<<10)
-#define E_SCALE                        (1<<11)
-#define E_COLORMAP             (1<<12)
-#define E_SKIN                 (1<<13)
-#define E_FLAGS                        (1<<14)
-#define E_EXTEND2              (1<<15)
+#define E_FRAME1         (1u<<8)
+#define E_EFFECTS1       (1u<<9)
+#define E_ALPHA          (1u<<10)
+#define E_SCALE          (1u<<11)
+#define E_COLORMAP       (1u<<12)
+#define E_SKIN           (1u<<13)
+#define E_FLAGS          (1u<<14)
+#define E_EXTEND2        (1u<<15)
 
 // players, custom color glows, high model numbers
-#define E_FRAME2               (1<<16)
-#define E_MODEL2               (1<<17)
-#define E_EFFECTS2             (1<<18)
-#define E_GLOWSIZE             (1<<19)
-#define E_GLOWCOLOR            (1<<20)
-#define E_LIGHT                        (1<<21)
-#define E_LIGHTPFLAGS  (1<<22)
-#define E_EXTEND3              (1<<23)
-
-#define E_SOUND1               (1<<24)
-#define E_SOUNDVOL             (1<<25)
-#define E_SOUNDATTEN   (1<<26)
-#define E_TAGATTACHMENT        (1<<27)
-#define E_LIGHTSTYLE   (1<<28)
-#define E_UNUSED6              (1<<29)
-#define E_UNUSED7              (1<<30)
-#define E_EXTEND4              (1<<31)
+#define E_FRAME2         (1u<<16)
+#define E_MODEL2         (1u<<17)
+#define E_EFFECTS2       (1u<<18)
+#define E_GLOWSIZE       (1u<<19)
+#define E_GLOWCOLOR      (1u<<20)
+#define E_LIGHT          (1u<<21)
+#define E_LIGHTPFLAGS    (1u<<22)
+#define E_EXTEND3        (1u<<23)
+
+#define E_SOUND1         (1u<<24)
+#define E_SOUNDVOL       (1u<<25)
+#define E_SOUNDATTEN     (1u<<26)
+#define E_TAGATTACHMENT  (1u<<27)
+#define E_LIGHTSTYLE     (1u<<28)
+#define E_UNUSED6        (1u<<29)
+#define E_UNUSED7        (1u<<30)
+#define E_EXTEND4        (1u<<31)
+// UBSan: unsigned literals because left shifting by 31 causes signed overflow, although it works as expected on x86.
 
 // returns difference between two states as E_ flags
 int EntityState_DeltaBits(const entity_state_t *o, const entity_state_t *n);
@@ -736,89 +739,90 @@ qbool EntityFrame4_WriteFrame(struct sizebuf_s *msg, int maxsize, entityframe4_d
 // reads a frame from the network stream
 void EntityFrame4_CL_ReadFrame(void);
 
-// reset all entity fields (typically used if status changed)
-#define E5_FULLUPDATE (1<<0)
-// E5_ORIGIN32=0: short[3] = s->origin[0] * 8, s->origin[1] * 8, s->origin[2] * 8
-// E5_ORIGIN32=1: float[3] = s->origin[0], s->origin[1], s->origin[2]
-#define E5_ORIGIN (1<<1)
-// E5_ANGLES16=0: byte[3] = s->angle[0] * 256 / 360, s->angle[1] * 256 / 360, s->angle[2] * 256 / 360
-// E5_ANGLES16=1: short[3] = s->angle[0] * 65536 / 360, s->angle[1] * 65536 / 360, s->angle[2] * 65536 / 360
-#define E5_ANGLES (1<<2)
-// E5_MODEL16=0: byte = s->modelindex
-// E5_MODEL16=1: short = s->modelindex
-#define E5_MODEL (1<<3)
-// E5_FRAME16=0: byte = s->frame
-// E5_FRAME16=1: short = s->frame
-#define E5_FRAME (1<<4)
-// byte = s->skin
-#define E5_SKIN (1<<5)
-// E5_EFFECTS16=0 && E5_EFFECTS32=0: byte = s->effects
-// E5_EFFECTS16=1 && E5_EFFECTS32=0: short = s->effects
-// E5_EFFECTS16=0 && E5_EFFECTS32=1: int = s->effects
-// E5_EFFECTS16=1 && E5_EFFECTS32=1: int = s->effects
-#define E5_EFFECTS (1<<6)
-// bits >= (1<<8)
-#define E5_EXTEND1 (1<<7)
-
-// byte = s->renderflags
-#define E5_FLAGS (1<<8)
-// byte = bound(0, s->alpha * 255, 255)
-#define E5_ALPHA (1<<9)
-// byte = bound(0, s->scale * 16, 255)
-#define E5_SCALE (1<<10)
-// flag
-#define E5_ORIGIN32 (1<<11)
-// flag
-#define E5_ANGLES16 (1<<12)
-// flag
-#define E5_MODEL16 (1<<13)
-// byte = s->colormap
-#define E5_COLORMAP (1<<14)
-// bits >= (1<<16)
-#define E5_EXTEND2 (1<<15)
-
-// short = s->tagentity
-// byte = s->tagindex
-#define E5_ATTACHMENT (1<<16)
-// short[4] = s->light[0], s->light[1], s->light[2], s->light[3]
-// byte = s->lightstyle
-// byte = s->lightpflags
-#define E5_LIGHT (1<<17)
-// byte = s->glowsize
-// byte = s->glowcolor
-#define E5_GLOW (1<<18)
-// short = s->effects
-#define E5_EFFECTS16 (1<<19)
-// int = s->effects
-#define E5_EFFECTS32 (1<<20)
-// flag
-#define E5_FRAME16 (1<<21)
-// byte[3] = s->colormod[0], s->colormod[1], s->colormod[2]
-#define E5_COLORMOD (1<<22)
-// bits >= (1<<24)
-#define E5_EXTEND3 (1<<23)
-
-// byte[3] = s->glowmod[0], s->glowmod[1], s->glowmod[2]
-#define E5_GLOWMOD (1<<24)
-// byte type=0 short frames[1] short times[1]
-// byte type=1 short frames[2] short times[2] byte lerps[2]
-// byte type=2 short frames[3] short times[3] byte lerps[3]
-// byte type=3 short frames[4] short times[4] byte lerps[4]
-// byte type=4 short modelindex byte numbones {short pose7s[7]}
-// see also RENDER_COMPLEXANIMATION
-#define E5_COMPLEXANIMATION (1<<25)
-// ushort traileffectnum
-#define E5_TRAILEFFECTNUM (1<<26)
-// unused
-#define E5_UNUSED27 (1<<27)
-// unused
-#define E5_UNUSED28 (1<<28)
-// unused
-#define E5_UNUSED29 (1<<29)
-// unused
-#define E5_UNUSED30 (1<<30)
-// bits2 > 0
-#define E5_EXTEND4 (1<<31)
+/// reset all entity fields (typically used if status changed)
+#define E5_FULLUPDATE        (1u<<0)
+/// E5_ORIGIN32=0: short[3] = s->origin[0] * 8, s->origin[1] * 8, s->origin[2] * 8
+/// E5_ORIGIN32=1: float[3] = s->origin[0], s->origin[1], s->origin[2]
+#define E5_ORIGIN            (1u<<1)
+/// E5_ANGLES16=0: byte[3] = s->angle[0] * 256 / 360, s->angle[1] * 256 / 360, s->angle[2] * 256 / 360
+/// E5_ANGLES16=1: short[3] = s->angle[0] * 65536 / 360, s->angle[1] * 65536 / 360, s->angle[2] * 65536 / 360
+#define E5_ANGLES            (1u<<2)
+/// E5_MODEL16=0: byte = s->modelindex
+/// E5_MODEL16=1: short = s->modelindex
+#define E5_MODEL             (1u<<3)
+/// E5_FRAME16=0: byte = s->frame
+/// E5_FRAME16=1: short = s->frame
+#define E5_FRAME             (1u<<4)
+/// byte = s->skin
+#define E5_SKIN              (1u<<5)
+/// E5_EFFECTS16=0 && E5_EFFECTS32=0: byte = s->effects
+/// E5_EFFECTS16=1 && E5_EFFECTS32=0: short = s->effects
+/// E5_EFFECTS16=0 && E5_EFFECTS32=1: int = s->effects
+/// E5_EFFECTS16=1 && E5_EFFECTS32=1: int = s->effects
+#define E5_EFFECTS           (1u<<6)
+/// bits >= (1<<8)
+#define E5_EXTEND1           (1u<<7)
+
+/// byte = s->renderflags
+#define E5_FLAGS             (1u<<8)
+/// byte = bound(0, s->alpha * 255, 255)
+#define E5_ALPHA             (1u<<9)
+/// byte = bound(0, s->scale * 16, 255)
+#define E5_SCALE             (1u<<10)
+/// flag
+#define E5_ORIGIN32          (1u<<11)
+/// flag
+#define E5_ANGLES16          (1u<<12)
+/// flag
+#define E5_MODEL16           (1u<<13)
+/// byte = s->colormap
+#define E5_COLORMAP          (1u<<14)
+/// bits >= (1<<16)
+#define E5_EXTEND2           (1u<<15)
+
+/// short = s->tagentity
+/// byte = s->tagindex
+#define E5_ATTACHMENT        (1u<<16)
+/// short[4] = s->light[0], s->light[1], s->light[2], s->light[3]
+/// byte = s->lightstyle
+/// byte = s->lightpflags
+#define E5_LIGHT             (1u<<17)
+/// byte = s->glowsize
+/// byte = s->glowcolor
+#define E5_GLOW              (1u<<18)
+/// short = s->effects
+#define E5_EFFECTS16         (1u<<19)
+/// int = s->effects
+#define E5_EFFECTS32         (1u<<20)
+/// flag
+#define E5_FRAME16           (1u<<21)
+/// byte[3] = s->colormod[0], s->colormod[1], s->colormod[2]
+#define E5_COLORMOD          (1u<<22)
+/// bits >= (1<<24)
+#define E5_EXTEND3           (1u<<23)
+
+/// byte[3] = s->glowmod[0], s->glowmod[1], s->glowmod[2]
+#define E5_GLOWMOD           (1u<<24)
+/// byte type=0 short frames[1] short times[1]
+/// byte type=1 short frames[2] short times[2] byte lerps[2]
+/// byte type=2 short frames[3] short times[3] byte lerps[3]
+/// byte type=3 short frames[4] short times[4] byte lerps[4]
+/// byte type=4 short modelindex byte numbones {short pose7s[7]}
+/// see also RENDER_COMPLEXANIMATION
+#define E5_COMPLEXANIMATION  (1u<<25)
+/// ushort traileffectnum
+#define E5_TRAILEFFECTNUM    (1u<<26)
+/// unused
+#define E5_UNUSED27          (1u<<27)
+/// unused
+#define E5_UNUSED28          (1u<<28)
+/// unused
+#define E5_UNUSED29          (1u<<29)
+/// unused
+#define E5_UNUSED30          (1u<<30)
+/// bits2 > 0
+#define E5_EXTEND4           (1u<<31)
+// UBSan: unsigned literals because left shifting by 31 causes signed overflow, although it works as expected on x86.
 
 #define ENTITYFRAME5_MAXPACKETLOGS 64
 #define ENTITYFRAME5_MAXSTATES 1024
index 6bc211c66cacfd5bc3ca5820864dde82dafabaab..9a4e692173405cfc46b681abd3de2ff34dd6a672 100644 (file)
@@ -1753,7 +1753,7 @@ float     registercvar (string name, string value[, float flags])
 void VM_registercvar(prvm_prog_t *prog)
 {
        const char *name, *value;
-       int     flags;
+       unsigned flags;
 
        VM_SAFEPARMCOUNTRANGE(2, 3, VM_registercvar);
 
@@ -3881,7 +3881,7 @@ static int BufStr_SortStringsDOWN (const void *in1, const void *in2)
        return strncmp(b, a, stringbuffers_sortlength);
 }
 
-prvm_stringbuffer_t *BufStr_FindCreateReplace (prvm_prog_t *prog, int bufindex, int flags, const char *format)
+prvm_stringbuffer_t *BufStr_FindCreateReplace (prvm_prog_t *prog, int bufindex, unsigned flags, const char *format)
 {
        prvm_stringbuffer_t *stringbuffer;
        int i;
index 24fe4a91b1f7b589aa6ffbcf041a40d32f0da9a6..217d67f1c7d1dbf5e7f1400c2cadaeed67fb9850 100644 (file)
@@ -219,7 +219,7 @@ void VM_CheckEmptyString (prvm_prog_t *prog, const char *s);
 /// Returns the length of the *out string excluding the \0 terminator.
 size_t VM_VarString(prvm_prog_t *prog, int first, char *out, size_t outsize);
 qbool PRVM_ConsoleCommand(prvm_prog_t *prog, const char *text, size_t textlen, int *func, qbool preserve_self, int curself, double ptime, qbool prog_loaded, const char *error_message);
-prvm_stringbuffer_t *BufStr_FindCreateReplace (prvm_prog_t *prog, int bufindex, int flags, const char *format);
+prvm_stringbuffer_t *BufStr_FindCreateReplace (prvm_prog_t *prog, int bufindex, unsigned flags, const char *format);
 void BufStr_Set(prvm_prog_t *prog, prvm_stringbuffer_t *stringbuffer, int strindex, const char *str);
 void BufStr_Del(prvm_prog_t *prog, prvm_stringbuffer_t *stringbuffer);
 void BufStr_Flush(prvm_prog_t *prog);
index f423d5985aab35137cab98ed205e47f8c9f43a13..510b4ec20bc7b4d90ae6228d96ffcb42c5814a11 100644 (file)
@@ -35,14 +35,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE 0x00000004
 
 // stock defines
-
-#define        IT_SHOTGUN                              1
-#define        IT_SUPER_SHOTGUN                2
-#define        IT_NAILGUN                              4
-#define        IT_SUPER_NAILGUN                8
-#define        IT_GRENADE_LAUNCHER             16
-#define        IT_ROCKET_LAUNCHER              32
-#define        IT_LIGHTNING                    64
+#define IT_SHOTGUN              1
+#define IT_SUPER_SHOTGUN        2
+#define IT_NAILGUN              4
+#define IT_SUPER_NAILGUN        8
+#define IT_GRENADE_LAUNCHER     16
+#define IT_ROCKET_LAUNCHER      32
+#define IT_LIGHTNING            64
 #define IT_SUPER_LIGHTNING      128
 #define IT_SHELLS               256
 #define IT_NAILS                512
@@ -55,14 +54,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define IT_SUPERHEALTH          65536
 #define IT_KEY1                 131072
 #define IT_KEY2                 262144
-#define        IT_INVISIBILITY                 524288
-#define        IT_INVULNERABILITY              1048576
-#define        IT_SUIT                                 2097152
-#define        IT_QUAD                                 4194304
-#define IT_SIGIL1               (1<<28)
-#define IT_SIGIL2               (1<<29)
-#define IT_SIGIL3               (1<<30)
-#define IT_SIGIL4               (1<<31)
+#define IT_INVISIBILITY         524288
+#define IT_INVULNERABILITY      1048576
+#define IT_SUIT                 2097152
+#define IT_QUAD                 4194304
+#define IT_SIGIL1               (1u<<28)
+#define IT_SIGIL2               (1u<<29)
+#define IT_SIGIL3               (1u<<30)
+#define IT_SIGIL4               (1u<<31)
+// UBSan: unsigned literals because left shifting by 31 causes signed overflow, although it works as expected on x86.
 
 //===========================================
 // AK nexuiz changed and added defines
index 273e214775ba02d4d93a68ca0245a72635596576..8bfd9b77fac8f1344d941b2179b84d6efdb22962 100644 (file)
--- a/render.h
+++ b/render.h
@@ -46,7 +46,7 @@ typedef enum shaderlanguage_e
 }
 shaderlanguage_t;
 
-// this enum selects which of the glslshadermodeinfo entries should be used
+/// this enum selects which of the glslshadermodeinfo entries should be used
 typedef enum shadermode_e
 {
        SHADERMODE_GENERIC, ///< (particles/HUD/etc) vertex color, optionally multiplied by one texture
@@ -70,39 +70,40 @@ typedef enum shadermode_e
 }
 shadermode_t;
 
-#define SHADERPERMUTATION_DIFFUSE (1<<0) ///< (lightsource) whether to use directional shading
-#define SHADERPERMUTATION_VERTEXTEXTUREBLEND (1<<1) ///< indicates this is a two-layer material blend based on vertex alpha (q3bsp)
-#define        SHADERPERMUTATION_VIEWTINT (1<<2) ///< view tint (postprocessing only), use vertex colors (generic only)
-#define        SHADERPERMUTATION_COLORMAPPING (1<<3) ///< indicates this is a colormapped skin
-#define        SHADERPERMUTATION_SATURATION (1<<4) ///< saturation (postprocessing only)
-#define        SHADERPERMUTATION_FOGINSIDE (1<<5) ///< tint the color by fog color or black if using additive blend mode
-#define        SHADERPERMUTATION_FOGOUTSIDE (1<<6) ///< tint the color by fog color or black if using additive blend mode
-#define        SHADERPERMUTATION_FOGHEIGHTTEXTURE (1<<7) ///< fog color and density determined by texture mapped on vertical axis
-#define        SHADERPERMUTATION_FOGALPHAHACK (1<<8) ///< fog color and density determined by texture mapped on vertical axis
-#define        SHADERPERMUTATION_GAMMARAMPS (1<<9) ///< gamma (postprocessing only)
-#define        SHADERPERMUTATION_CUBEFILTER (1<<10) ///< (lightsource) use cubemap light filter
-#define        SHADERPERMUTATION_GLOW (1<<11) ///< (lightmap) blend in an additive glow texture
-#define        SHADERPERMUTATION_BLOOM (1<<12) ///< bloom (postprocessing only)
-#define        SHADERPERMUTATION_SPECULAR (1<<13) ///< (lightsource or deluxemapping) render specular effects
-#define        SHADERPERMUTATION_POSTPROCESSING (1<<14) ///< user defined postprocessing (postprocessing only)
-#define        SHADERPERMUTATION_REFLECTION (1<<15) ///< normalmap-perturbed reflection of the scene infront of the surface, preformed as an overlay on the surface
-#define        SHADERPERMUTATION_OFFSETMAPPING (1<<16) ///< adjust texcoords to roughly simulate a displacement mapped surface
-#define        SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING (1<<17) ///< adjust texcoords to accurately simulate a displacement mapped surface (requires OFFSETMAPPING to also be set!)
-#define        SHADERPERMUTATION_SHADOWMAP2D (1<<18) ///< (lightsource) use shadowmap texture as light filter
-#define        SHADERPERMUTATION_SHADOWMAPVSDCT (1<<19) ///< (lightsource) use virtual shadow depth cube texture for shadowmap indexing
-#define        SHADERPERMUTATION_SHADOWMAPORTHO (1<<20) ///< (lightsource) use orthographic shadowmap projection
-#define        SHADERPERMUTATION_DEFERREDLIGHTMAP (1<<21) ///< (lightmap) read Texture_ScreenDiffuse/Specular textures and add them on top of lightmapping
-#define        SHADERPERMUTATION_ALPHAKILL (1<<22) ///< (deferredgeometry) discard pixel if diffuse texture alpha below 0.5, (generic) apply global alpha
-#define        SHADERPERMUTATION_REFLECTCUBE (1<<23) ///< fake reflections using global cubemap (not HDRI light probe)
-#define        SHADERPERMUTATION_NORMALMAPSCROLLBLEND (1<<24) ///< (water) counter-direction normalmaps scrolling
-#define        SHADERPERMUTATION_BOUNCEGRID (1<<25) ///< (lightmap) use Texture_BounceGrid as an additional source of ambient light
-#define        SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL (1<<26) ///< (lightmap) use 16-component pixels in bouncegrid texture for directional lighting rather than standard 4-component
-#define SHADERPERMUTATION_TRIPPY (1<<27) ///< use trippy vertex shader effect
-#define        SHADERPERMUTATION_DEPTHRGB (1<<28) ///< read/write depth values in RGB color coded format for older hardware without depth samplers
-#define        SHADERPERMUTATION_ALPHAGEN_VERTEX (1<<29) ///< alphaGen vertex
-#define        SHADERPERMUTATION_SKELETAL (1<<30) ///< (skeletal models) use skeletal matrices to deform vertices (gpu-skinning)
-#define        SHADERPERMUTATION_OCCLUDE (1<<31) ///< use occlusion buffer for corona
-#define        SHADERPERMUTATION_COUNT 32 ///< size of shaderpermutationinfo array
+#define SHADERPERMUTATION_DIFFUSE (1u<<0) ///< (lightsource) whether to use directional shading
+#define SHADERPERMUTATION_VERTEXTEXTUREBLEND (1u<<1) ///< indicates this is a two-layer material blend based on vertex alpha (q3bsp)
+#define SHADERPERMUTATION_VIEWTINT (1u<<2) ///< view tint (postprocessing only), use vertex colors (generic only)
+#define SHADERPERMUTATION_COLORMAPPING (1u<<3) ///< indicates this is a colormapped skin
+#define SHADERPERMUTATION_SATURATION (1u<<4) ///< saturation (postprocessing only)
+#define SHADERPERMUTATION_FOGINSIDE (1u<<5) ///< tint the color by fog color or black if using additive blend mode
+#define SHADERPERMUTATION_FOGOUTSIDE (1u<<6) ///< tint the color by fog color or black if using additive blend mode
+#define SHADERPERMUTATION_FOGHEIGHTTEXTURE (1u<<7) ///< fog color and density determined by texture mapped on vertical axis
+#define SHADERPERMUTATION_FOGALPHAHACK (1u<<8) ///< fog color and density determined by texture mapped on vertical axis
+#define SHADERPERMUTATION_GAMMARAMPS (1u<<9) ///< gamma (postprocessing only)
+#define SHADERPERMUTATION_CUBEFILTER (1u<<10) ///< (lightsource) use cubemap light filter
+#define SHADERPERMUTATION_GLOW (1u<<11) ///< (lightmap) blend in an additive glow texture
+#define SHADERPERMUTATION_BLOOM (1u<<12) ///< bloom (postprocessing only)
+#define SHADERPERMUTATION_SPECULAR (1u<<13) ///< (lightsource or deluxemapping) render specular effects
+#define SHADERPERMUTATION_POSTPROCESSING (1u<<14) ///< user defined postprocessing (postprocessing only)
+#define SHADERPERMUTATION_REFLECTION (1u<<15) ///< normalmap-perturbed reflection of the scene infront of the surface, preformed as an overlay on the surface
+#define SHADERPERMUTATION_OFFSETMAPPING (1u<<16) ///< adjust texcoords to roughly simulate a displacement mapped surface
+#define SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING (1u<<17) ///< adjust texcoords to accurately simulate a displacement mapped surface (requires OFFSETMAPPING to also be set!)
+#define SHADERPERMUTATION_SHADOWMAP2D (1u<<18) ///< (lightsource) use shadowmap texture as light filter
+#define SHADERPERMUTATION_SHADOWMAPVSDCT (1u<<19) ///< (lightsource) use virtual shadow depth cube texture for shadowmap indexing
+#define SHADERPERMUTATION_SHADOWMAPORTHO (1u<<20) ///< (lightsource) use orthographic shadowmap projection
+#define SHADERPERMUTATION_DEFERREDLIGHTMAP (1u<<21) ///< (lightmap) read Texture_ScreenDiffuse/Specular textures and add them on top of lightmapping
+#define SHADERPERMUTATION_ALPHAKILL (1u<<22) ///< (deferredgeometry) discard pixel if diffuse texture alpha below 0.5, (generic) apply global alpha
+#define SHADERPERMUTATION_REFLECTCUBE (1u<<23) ///< fake reflections using global cubemap (not HDRI light probe)
+#define SHADERPERMUTATION_NORMALMAPSCROLLBLEND (1u<<24) ///< (water) counter-direction normalmaps scrolling
+#define SHADERPERMUTATION_BOUNCEGRID (1u<<25) ///< (lightmap) use Texture_BounceGrid as an additional source of ambient light
+#define SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL (1u<<26) ///< (lightmap) use 16-component pixels in bouncegrid texture for directional lighting rather than standard 4-component
+#define SHADERPERMUTATION_TRIPPY (1u<<27) ///< use trippy vertex shader effect
+#define SHADERPERMUTATION_DEPTHRGB (1u<<28) ///< read/write depth values in RGB color coded format for older hardware without depth samplers
+#define SHADERPERMUTATION_ALPHAGEN_VERTEX (1u<<29) ///< alphaGen vertex
+#define SHADERPERMUTATION_SKELETAL (1u<<30) ///< (skeletal models) use skeletal matrices to deform vertices (gpu-skinning)
+#define SHADERPERMUTATION_OCCLUDE (1u<<31) ///< use occlusion buffer for corona
+#define SHADERPERMUTATION_COUNT 32u ///< size of shaderpermutationinfo array
+// UBSan: unsigned literals because left shifting by 31 causes signed overflow, although it works as expected on x86.
 
 // 1.0f / N table
 extern float ixtable[4096];
@@ -236,9 +237,9 @@ r_viewport_type_t;
 
 typedef struct r_viewport_s
 {
-       matrix4x4_t cameramatrix; // from entity (transforms from camera entity to world)
-       matrix4x4_t viewmatrix; // actual matrix for rendering (transforms to viewspace)
-       matrix4x4_t projectmatrix; // actual projection matrix (transforms from viewspace to screen)
+       matrix4x4_t cameramatrix;  ///< from entity (transforms from camera entity to world)
+       matrix4x4_t viewmatrix;    ///< actual matrix for rendering (transforms to viewspace)
+       matrix4x4_t projectmatrix; ///< actual projection matrix (transforms from viewspace to screen)
        int x;
        int y;
        int z;
@@ -246,7 +247,7 @@ typedef struct r_viewport_s
        int height;
        int depth;
        r_viewport_type_t type;
-       float screentodepth[2]; // used by deferred renderer to calculate linear depth from device depth coordinates
+       float screentodepth[2];    ///< used by deferred renderer to calculate linear depth from device depth coordinates
 }
 r_viewport_t;
 
@@ -271,17 +272,17 @@ typedef struct r_refdef_view_s
        int numfrustumplanes;
        mplane_t frustum[6];
        qbool useclipplane;
-       qbool usecustompvs; // uses r_refdef.viewcache.pvsbits as-is rather than computing it
+       qbool usecustompvs; ///< uses r_refdef.viewcache.pvsbits as-is rather than computing it
        mplane_t clipplane;
        float frustum_x, frustum_y;
        vec3_t frustumcorner[4];
-       // if turned off it renders an ortho view
+       /// if turned off it renders an ortho view
        int useperspective;
-       // allows visibility culling based on the view origin (e.g. pvs and R_CanSeeBox)
-       // this is turned off by:
-       // r_trippy
-       // !r_refdef.view.useperspective
-       // (sometimes) r_refdef.view.useclipplane
+       /// allows visibility culling based on the view origin (e.g. pvs and R_CanSeeBox)
+       /// this is turned off by:
+       /// r_trippy
+       /// !r_refdef.view.useperspective
+       /// (sometimes) r_refdef.view.useclipplane
        int usevieworiginculling;
        float ortho_x, ortho_y;
 
@@ -292,19 +293,19 @@ typedef struct r_refdef_view_s
        int width;
        int height;
        int depth;
-       r_viewport_t viewport; // note: if r_viewscale is used, the viewport.width and viewport.height may be less than width and height
+       r_viewport_t viewport; ///< note: if r_viewscale is used, the viewport.width and viewport.height may be less than width and height
 
-       // which color components to allow (for anaglyph glasses)
+       /// which color components to allow (for anaglyph glasses)
        int colormask[4];
 
-       // global RGB color multiplier for rendering
+       /// global RGB color multiplier for rendering
        float colorscale;
 
-       // whether to call R_ClearScreen before rendering stuff
+       /// whether to call R_ClearScreen before rendering stuff
        qbool clear;
-       // if true, don't clear or do any post process effects (bloom, etc)
+       /// if true, don't clear or do any post process effects (bloom, etc)
        qbool isoverlay;
-       // if true, this is the MAIN view (which is, after CSQC, copied into the scene for use e.g. by r_speeds 1, showtex, prydon cursor)
+       /// if true, this is the MAIN view (which is, after CSQC, copied into the scene for use e.g. by r_speeds 1, showtex, prydon cursor)
        qbool ismain;
 
        // whether to draw r_showtris and such, this is only true for the main
@@ -316,7 +317,7 @@ typedef struct r_refdef_view_s
        int cullface_front;
        int cullface_back;
 
-       // render quality (0 to 1) - affects r_drawparticles_drawdistance and others
+       /// render quality (0 to 1) - affects r_drawparticles_drawdistance and others
        float quality;
 }
 r_refdef_view_t;
@@ -332,8 +333,8 @@ typedef struct r_refdef_viewcache_s
 
        // these properties are generated by R_View_Update()
 
-       // which entities are currently visible for this viewpoint
-       // (the used range is 0...r_refdef.scene.numentities)
+       /// which entities are currently visible for this viewpoint
+       /// (the used range is 0...r_refdef.scene.numentities)
        unsigned char *entityvisible;
 
        // flag arrays used for visibility checking on world model
@@ -341,7 +342,7 @@ typedef struct r_refdef_viewcache_s
        unsigned char *world_pvsbits;
        unsigned char *world_leafvisible;
        unsigned char *world_surfacevisible;
-       // if true, the view is currently in a leaf without pvs data
+       /// if true, the view is currently in a leaf without pvs data
        qbool world_novis;
 }
 r_refdef_viewcache_t;
@@ -349,24 +350,24 @@ r_refdef_viewcache_t;
 // TODO: really think about which fields should go into scene and which one should stay in refdef [1/7/2008 Black]
 // maybe also refactor some of the functions to support different setting sources (ie. fogenabled, etc.) for different scenes
 typedef struct r_refdef_scene_s {
-       // whether to call S_ExtraUpdate during render to reduce sound chop
+       /// whether to call S_ExtraUpdate during render to reduce sound chop
        qbool extraupdate;
 
-       // (client gameworld) time for rendering time based effects
+       /// (client gameworld) time for rendering time based effects
        double time;
 
-       // the world
+       /// the world
        entity_render_t *worldentity;
 
-       // same as worldentity->model
+       /// same as worldentity->model
        model_t *worldmodel;
 
-       // renderable entities (excluding world)
+       /// renderable entities (excluding world)
        entity_render_t **entities;
        int numentities;
        int maxentities;
 
-       // field of temporary entities that is reset each (client) frame
+       /// field of temporary entities that is reset each (client) frame
        entity_render_t *tempentities;
        int numtempentities;
        int maxtempentities;
@@ -378,10 +379,10 @@ typedef struct r_refdef_scene_s {
        int numlights;
 
        // intensities for light styles right now, controls rtlights
-       float rtlightstylevalue[MAX_LIGHTSTYLES];       // float fraction of base light value
+       float rtlightstylevalue[MAX_LIGHTSTYLES]; ///< float fraction of base light value
        // 8.8bit fixed point intensities for light styles
        // controls intensity lightmap layers
-       unsigned short lightstylevalue[MAX_LIGHTSTYLES];        // 8.8 fraction of base light value
+       unsigned short lightstylevalue[MAX_LIGHTSTYLES]; ///< 8.8 fraction of base light value
 
        // adds brightness to the whole scene, separate from lightmapintensity
        // see CL_UpdateEntityShading
diff --git a/sbar.c b/sbar.c
index 7b914d84882100e9f61988ff0738c90d854294ec..1a0b4a905ac72a5770b3827af46f4869e932c14c 100644 (file)
--- a/sbar.c
+++ b/sbar.c
@@ -891,7 +891,7 @@ static void Sbar_DrawInventory (void)
 
        // items
        for (i=0 ; i<6 ; i++)
-               if (cl.stats[STAT_ITEMS] & (1<<(17+i)))
+               if (cl.stats[STAT_ITEMS] & (1u<<(17+i)))
                {
                        //MED 01/04/97 changed keys
                        if (!(gamemode == GAME_HIPNOTIC || gamemode == GAME_QUOTH) || (i>1))
@@ -903,7 +903,7 @@ static void Sbar_DrawInventory (void)
        if (gamemode == GAME_HIPNOTIC || gamemode == GAME_QUOTH)
        {
                for (i=0 ; i<2 ; i++)
-                       if (cl.stats[STAT_ITEMS] & (1<<(24+i)))
+                       if (cl.stats[STAT_ITEMS] & (1u<<(24+i)))
                                Sbar_DrawPic (288 + i*16, -16, hsb_items[i]);
        }
 
@@ -911,14 +911,14 @@ static void Sbar_DrawInventory (void)
        {
                // new rogue items
                for (i=0 ; i<2 ; i++)
-                       if (cl.stats[STAT_ITEMS] & (1<<(29+i)))
+                       if (cl.stats[STAT_ITEMS] & (1u<<(29+i)))
                                Sbar_DrawPic (288 + i*16, -16, rsb_items[i]);
        }
        else
        {
                // sigils
                for (i=0 ; i<4 ; i++)
-                       if (cl.stats[STAT_ITEMS] & (1<<(28+i)))
+                       if (cl.stats[STAT_ITEMS] & (1u<<(28+i)))
                                Sbar_DrawPic (320-32 + i*8, -16, sb_sigil[i]);
        }
 }