Avoid implementation-defined behaviour

This commit is contained in:
Learath 2019-05-15 18:11:22 +02:00
parent 0d39eb128d
commit db5c17ce71
3 changed files with 4 additions and 2 deletions

View file

@ -2811,6 +2811,7 @@ int str_isallnum(const char *str)
int str_toint(const char *str) { return atoi(str); }
int str_toint_base(const char *str, int base) { return strtol(str, NULL, base); }
unsigned long str_toulong_base(const char *str, int base) { return strtoul(str, NULL, base); }
float str_tofloat(const char *str) { return atof(str); }
int str_utf8_comp_nocase(const char *a, const char *b)

View file

@ -1657,6 +1657,7 @@ void net_stats(NETSTATS *stats);
int str_toint(const char *str);
int str_toint_base(const char *str, int base);
unsigned long str_toulong_base(const char *str, int base);
float str_tofloat(const char *str);
int str_isspace(char c);
char str_uppercase(char c);

View file

@ -54,14 +54,14 @@ ColorHSLA CConsole::CResult::GetColor(unsigned Index, bool Light)
int Len = str_length(pStr);
if(Len == 4)
{
unsigned Num = str_toint_base(pStr + 1, 16);
unsigned Num = str_toulong_base(pStr + 1, 16);
rgb.r = (((Num >> 8) & 0x0F) + ((Num >> 4) & 0xF0)) / 255.0f;
rgb.g = (((Num >> 4) & 0x0F) + ((Num >> 0) & 0xF0)) / 255.0f;
rgb.b = (((Num >> 0) & 0x0F) + ((Num << 4) & 0xF0)) / 255.0f;
}
else if(Len == 7)
{
unsigned Num = str_toint_base(pStr + 1, 16);
unsigned Num = str_toulong_base(pStr + 1, 16);
rgb.r = ((Num >> 16) & 0xFF) / 255.0f;
rgb.g = ((Num >> 8) & 0xFF) / 255.0f;
rgb.b = ((Num >> 0) & 0xFF) / 255.0f;