mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Avoid implementation-defined behaviour
This commit is contained in:
parent
0d39eb128d
commit
db5c17ce71
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue