mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
C client: Relying on undefined behaviour is a bad idea
This commit is contained in:
parent
6fcb90e03f
commit
7b93ad44fe
17
src/Input.c
17
src/Input.c
@ -140,13 +140,11 @@ bool KeyBind_IsPressed(KeyBind binding) { return Key_States[KeyBind_Keys[binding
|
||||
|
||||
void KeyBind_Load(void) {
|
||||
Int32 i;
|
||||
char nameBuffer[STRING_SIZE];
|
||||
String name = String_FromArray(nameBuffer);
|
||||
|
||||
for (i = 0; i < KeyBind_Count; i++) {
|
||||
name.length = 0;
|
||||
String_Format1(&name, "key-%c", KeyBind_Names[i]);
|
||||
char nameBuffer[STRING_SIZE] = { 0 };
|
||||
String name = String_FromArray(nameBuffer);
|
||||
|
||||
String_Format1(&name, "key-%c", KeyBind_Names[i]);
|
||||
Key mapping = Options_GetEnum(name.buffer, KeyBind_Defaults[i], Key_Names, Key_Count);
|
||||
if (mapping != Key_Escape) KeyBind_Keys[i] = mapping;
|
||||
}
|
||||
@ -157,13 +155,12 @@ void KeyBind_Save(void) {
|
||||
Int32 i;
|
||||
char nameBuffer[STRING_SIZE];
|
||||
String name = String_FromArray(nameBuffer);
|
||||
|
||||
for (i = 0; i < KeyBind_Count; i++) {
|
||||
name.length = 0;
|
||||
String_Format1(&name, "key-%c", KeyBind_Names[i]);
|
||||
|
||||
String_Format1(&name, "key-%c", KeyBind_Names[i]);
|
||||
String value = String_FromReadonly(Key_Names[KeyBind_Keys[i]]);
|
||||
Options_Set(name.buffer, &value);
|
||||
Options_SetString(&name, &value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,7 +325,7 @@ void Hotkeys_UserRemovedHotkey(Key trigger, UInt8 flags) {
|
||||
String key = String_FromArray(keyBuffer);
|
||||
|
||||
String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &flags);
|
||||
Options_Set(key.buffer, NULL);
|
||||
Options_SetString(&key, NULL);
|
||||
}
|
||||
|
||||
void Hotkeys_UserAddedHotkey(Key trigger, UInt8 flags, bool moreInput, STRING_PURE String* text) {
|
||||
@ -339,5 +336,5 @@ void Hotkeys_UserAddedHotkey(Key trigger, UInt8 flags, bool moreInput, STRING_PU
|
||||
|
||||
String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &flags);
|
||||
String_Format2(&value, "%t&%s", &moreInput, text);
|
||||
Options_Set(key.buffer, &value);
|
||||
Options_SetString(&key, &value);
|
||||
}
|
||||
|
@ -138,6 +138,10 @@ void Options_SetInt(const char* keyRaw, Int32 value) {
|
||||
|
||||
void Options_Set(const char* keyRaw, STRING_PURE String* value) {
|
||||
String key = String_FromReadonly(keyRaw);
|
||||
Options_SetString(&key, value);
|
||||
}
|
||||
|
||||
void Options_SetString(STRING_PURE String* key, STRING_PURE String* value) {
|
||||
UInt32 i;
|
||||
if (value == NULL || value->buffer == NULL) {
|
||||
i = Options_Find(&key);
|
||||
|
@ -73,18 +73,19 @@ extern const char* FpsLimit_Names[FpsLimit_Count];
|
||||
StringsBuffer Options_Keys;
|
||||
StringsBuffer Options_Values;
|
||||
|
||||
bool Options_HasAnyChanged(void);
|
||||
void Options_Free(void);
|
||||
NOINLINE_ bool Options_HasAnyChanged(void);
|
||||
NOINLINE_ void Options_Free(void);
|
||||
|
||||
void Options_Get(const char* key, STRING_TRANSIENT String* value, const char* defValue);
|
||||
Int32 Options_GetInt(const char* key, Int32 min, Int32 max, Int32 defValue);
|
||||
bool Options_GetBool(const char* key, bool defValue);
|
||||
Real32 Options_GetFloat(const char* key, Real32 min, Real32 max, Real32 defValue);
|
||||
UInt32 Options_GetEnum(const char* key, UInt32 defValue, const char** names, UInt32 namesCount);
|
||||
NOINLINE_ void Options_Get(const char* key, STRING_TRANSIENT String* value, const char* defValue);
|
||||
NOINLINE_ Int32 Options_GetInt(const char* key, Int32 min, Int32 max, Int32 defValue);
|
||||
NOINLINE_ bool Options_GetBool(const char* key, bool defValue);
|
||||
NOINLINE_ Real32 Options_GetFloat(const char* key, Real32 min, Real32 max, Real32 defValue);
|
||||
NOINLINE_ UInt32 Options_GetEnum(const char* key, UInt32 defValue, const char** names, UInt32 namesCount);
|
||||
|
||||
void Options_SetBool(const char* keyRaw, bool value);
|
||||
void Options_SetInt(const char* keyRaw, Int32 value);
|
||||
void Options_Set(const char* keyRaw, STRING_PURE String* value);
|
||||
void Options_Load(void);
|
||||
void Options_Save(void);
|
||||
NOINLINE_ void Options_SetBool(const char* keyRaw, bool value);
|
||||
NOINLINE_ void Options_SetInt(const char* keyRaw, Int32 value);
|
||||
NOINLINE_ void Options_Set(const char* keyRaw, STRING_PURE String* value);
|
||||
NOINLINE_ void Options_SetString(STRING_PURE String* key, STRING_PURE String* value);
|
||||
NOINLINE_ void Options_Load(void);
|
||||
NOINLINE_ void Options_Save(void);
|
||||
#endif
|
||||
|
@ -73,7 +73,7 @@ ReturnCode ReturnCode_SocketWouldBlock = EWOULDBLOCK;
|
||||
*---------------------------------------------------------Memory----------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void Platform_AllocFailed(const char* place) {
|
||||
char logBuffer[STRING_SIZE + 20];
|
||||
char logBuffer[STRING_SIZE + 20] = { 0 };
|
||||
String log = String_FromArray(logBuffer);
|
||||
String_Format1(&log, "Failed allocating memory for: %c", place);
|
||||
ErrorHandler_Fail(log.buffer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user