mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
fix(command): fixed infinite cleanup bug caused by ignorant usage of references by yours truly
This commit is contained in:
parent
d25d3653bb
commit
e9df378771
4 changed files with 39 additions and 29 deletions
|
|
@ -395,15 +395,13 @@ int32_t SCmdRegisterArgument(uint32_t flags, uint32_t id, const char* name, void
|
|||
STORM_VALIDATE((STORM_COMMAND_GET_TYPE(flags) != STORM_COMMAND_TYPE_BOOL) || (!variableptr) || (variablebytes == sizeof(uint32_t)), ERROR_INVALID_PARAMETER, 0);
|
||||
|
||||
// If argument is flagged, it goes in the flag list
|
||||
auto& cmdlist = s_arglist;
|
||||
auto listptr = &s_arglist;
|
||||
if (STORM_COMMAND_GET_ARG(flags) == STORM_COMMAND_ARG_FLAGGED) {
|
||||
cmdlist = s_flaglist;
|
||||
listptr = &s_flaglist;
|
||||
}
|
||||
|
||||
auto cmd = cmdlist.NewNode(2, 0, 0);
|
||||
auto cmd = listptr->NewNode(2, 0, 0);
|
||||
|
||||
SStrCopy(cmd->name, name, sizeof(cmd->name));
|
||||
|
||||
cmd->id = id;
|
||||
cmd->namelength = namelength;
|
||||
cmd->variableptr = variableptr;
|
||||
|
|
@ -412,7 +410,6 @@ int32_t SCmdRegisterArgument(uint32_t flags, uint32_t id, const char* name, void
|
|||
cmd->setvalue = setvalue;
|
||||
cmd->setmask = setmask;
|
||||
cmd->callback = callback;
|
||||
|
||||
if ((STORM_COMMAND_GET_TYPE(flags) == STORM_COMMAND_TYPE_BOOL) && (STORM_COMMAND_GET_BOOL(flags) == STORM_COMMAND_BOOL_CLEAR)) {
|
||||
cmd->currvalue = setvalue;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,6 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
#define STORM_COMMAND_ERROR_BAD_ARGUMENT 0x85100065
|
||||
#define STORM_COMMAND_ERROR_NOT_ENOUGH_ARGUMENTS 0x8510006D
|
||||
#define STORM_COMMAND_ERROR_OPEN_FAILED 0x6E
|
||||
|
||||
#define STORM_COMMAND_WHITESPACE_CHARS " ,;\"\t\n\r\x1A"
|
||||
|
||||
#define STORM_COMMAND_EXTRA_CASE_SENSITIVE (1 << 8)
|
||||
|
|
@ -45,17 +41,17 @@ class CMDERROR;
|
|||
class CMDPARAMS;
|
||||
|
||||
// Callback types
|
||||
typedef int32_t (*CMDEXTRACALLBACKFCN)(const char*);
|
||||
typedef int32_t (*CMDERRORCALLBACKFCN)(CMDERROR*);
|
||||
typedef int32_t (*CMDPARAMSCALLBACKFCN)(CMDPARAMS*, const char*);
|
||||
typedef int32_t (*CMDEXTRACALLBACK)(const char*);
|
||||
typedef int32_t (*CMDERRORCALLBACK)(CMDERROR*);
|
||||
typedef int32_t (*CMDPARAMSCALLBACK)(CMDPARAMS*, const char*);
|
||||
|
||||
// Details a command line argument
|
||||
class ARGLIST {
|
||||
public:
|
||||
uint32_t flags;
|
||||
uint32_t id;
|
||||
const char* name;
|
||||
CMDPARAMSCALLBACKFCN callback;
|
||||
uint32_t flags;
|
||||
uint32_t id;
|
||||
const char* name;
|
||||
CMDPARAMSCALLBACK callback;
|
||||
};
|
||||
|
||||
// Parameters passed to argument callback
|
||||
|
|
@ -78,19 +74,19 @@ class CMDPARAMS {
|
|||
// Command definitions
|
||||
class CMDDEF : public TSLinkedNode<CMDDEF> {
|
||||
public:
|
||||
uint32_t flags;
|
||||
uint32_t id;
|
||||
char name[16];
|
||||
int32_t namelength;
|
||||
uint32_t setvalue;
|
||||
uint32_t setmask;
|
||||
void* variableptr;
|
||||
uint32_t variablebytes;
|
||||
CMDPARAMSCALLBACKFCN callback;
|
||||
int32_t found;
|
||||
uint32_t flags;
|
||||
uint32_t id;
|
||||
char name[16];
|
||||
int32_t namelength;
|
||||
uint32_t setvalue;
|
||||
uint32_t setmask;
|
||||
void* variableptr;
|
||||
uint32_t variablebytes;
|
||||
CMDPARAMSCALLBACK callback;
|
||||
int32_t found;
|
||||
union {
|
||||
uint32_t currvalue;
|
||||
char* currvaluestr;
|
||||
uint32_t currvalue;
|
||||
char* currvaluestr;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -13,4 +13,8 @@
|
|||
|
||||
#define STORM_ERROR_APPLICATION_FATAL STORM_ERROR(0x84)
|
||||
|
||||
#define STORM_COMMAND_ERROR_BAD_ARGUMENT STORM_ERROR(0x65)
|
||||
#define STORM_COMMAND_ERROR_NOT_ENOUGH_ARGUMENTS STORM_ERROR(0x6D)
|
||||
#define STORM_COMMAND_ERROR_OPEN_FAILED 0x6E
|
||||
|
||||
#endif
|
||||
|
|
|
|||
13
test/Command.cpp
Normal file
13
test/Command.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include "storm/Command.hpp"
|
||||
#include "test/Test.hpp"
|
||||
|
||||
TEST_CASE("SCmdRegisterArgList", "[command]") {
|
||||
SECTION("register an argument list normally") {
|
||||
ARGLIST argList[] = {
|
||||
{ 0x0, 1, "one", nullptr },
|
||||
{ 0x0, 2, "two", nullptr }
|
||||
};
|
||||
|
||||
SCmdRegisterArgList(argList, sizeof(argList) / sizeof(ARGLIST));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue