Prevent Q_IsColorString from asserting on negative ascii chars

This commit is contained in:
kungfooman authored and Tim Angus committed 2018-12-14 10:00:24 +00:00
1 parent 09166ba05e
commit a6df505d59
2 files changed
+23 -1

No files matched your search

+22
View File
@@ -23,6 +23,28 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// q_shared.c -- stateless support routines that are included in each code dll
#include "q_shared.h"
// ^[0-9a-zA-Z]
qboolean Q_IsColorString(const char *p) {
if (!p)
return qfalse;
if (p[0] != Q_COLOR_ESCAPE)
return qfalse;
if (p[1] == 0)
return qfalse;
// isalnum expects a signed integer in the range -1 (EOF) to 255, or it might assert on undefined behaviour
// a dereferenced char pointer has the range -128 to 127, so we just need to rangecheck the negative part
if (p[1] < 0)
return qfalse;
if (isalnum(p[1]) == 0)
return qfalse;
return qtrue;
}
float Com_Clamp( float min, float max, float value ) {
if ( value < min ) {
return min;