Check for config->options == NULL

This commit is contained in:
Vftdan 2024-08-19 11:21:51 +02:00
parent f19732d364
commit 7cdbcaf25e
8 changed files with 45 additions and 24 deletions

View File

@ -58,6 +58,7 @@ create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEn
has_payload = false; has_payload = false;
const config_setting_t *setting; const config_setting_t *setting;
if (config->options) {
if ((setting = config_setting_get_member(config->options, "namespace"))) { if ((setting = config_setting_get_member(config->options, "namespace"))) {
has_ns = true; has_ns = true;
source.code.ns = env_resolve_constant(env, setting); source.code.ns = env_resolve_constant(env, setting);
@ -74,6 +75,17 @@ create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEn
has_payload = true; has_payload = true;
source.payload = env_resolve_constant(env, setting); source.payload = env_resolve_constant(env, setting);
} }
} else {
// Prevent warning for uninitialized variable
source = (EventData) {
.code = {
.ns = 0,
.major = 0,
.minor = 0,
},
.payload = 0,
};
}
*node = (AssignGraphNode) { *node = (AssignGraphNode) {
.as_GraphNode = { .as_GraphNode = {

View File

@ -42,7 +42,6 @@ create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEn
int64_t initial = 0; int64_t initial = 0;
if (config->options) { if (config->options) {
// FIXME check config->options for NULL in all node types
initial = env_resolve_constant(env, config_setting_get_member(config->options, "initial")); initial = env_resolve_constant(env, config_setting_get_member(config->options, "initial"));
} }

View File

@ -77,7 +77,7 @@ create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEn
} }
const char *filename = NULL; const char *filename = NULL;
bool should_grab = false; bool should_grab = false;
if (config) { if (config->options) {
node->namespace = env_resolve_constant(env, config_setting_get_member(config->options, "namespace")); node->namespace = env_resolve_constant(env, config_setting_get_member(config->options, "namespace"));
should_grab = env_resolve_constant(env, config_setting_get_member(config->options, "grab")) != 0; should_grab = env_resolve_constant(env, config_setting_get_member(config->options, "grab")) != 0;
config_setting_lookup_string(config->options, "file", &filename); config_setting_lookup_string(config->options, "file", &filename);

View File

@ -70,7 +70,7 @@ create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEn
.handle_io = handle_io, .handle_io = handle_io,
.enabled = true, .enabled = true,
}, },
.namespace = env_resolve_constant(env, config_setting_get_member(config->options, "namespace")), .namespace = config->options ? env_resolve_constant(env, config_setting_get_member(config->options, "namespace")) : 0,
}; };
return &node->as_GraphNode; return &node->as_GraphNode;
} }

View File

@ -30,8 +30,10 @@ handle_event(EventPositionBase * self, EventNode * event)
static GraphNode * static GraphNode *
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env) create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
{ {
(void) config; if (!config->options) {
(void) env; return NULL;
}
ModifiersGraphNode * node = T_ALLOC(1, ModifiersGraphNode); ModifiersGraphNode * node = T_ALLOC(1, ModifiersGraphNode);
if (!node) { if (!node) {
return NULL; return NULL;

View File

@ -50,8 +50,10 @@ handle_event(EventPositionBase * self, EventNode * event)
static GraphNode * static GraphNode *
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env) create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
{ {
(void) config; if (!config->options) {
(void) env; return NULL;
}
ModifyPredicateGraphNode * node = T_ALLOC(1, ModifyPredicateGraphNode); ModifyPredicateGraphNode * node = T_ALLOC(1, ModifyPredicateGraphNode);
if (!node) { if (!node) {
return NULL; return NULL;

View File

@ -28,8 +28,10 @@ handle_event(EventPositionBase * self, EventNode * event)
static GraphNode * static GraphNode *
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env) create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
{ {
(void) config; if (!config->options) {
(void) env; return NULL;
}
RouterGraphNode * node = T_ALLOC(1, RouterGraphNode); RouterGraphNode * node = T_ALLOC(1, RouterGraphNode);
if (!node) { if (!node) {
return NULL; return NULL;

View File

@ -78,6 +78,10 @@ handle_event(EventPositionBase * self, EventNode * event)
static GraphNode * static GraphNode *
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env) create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
{ {
if (!config->options) {
return NULL;
}
UinputGraphNode * node = T_ALLOC(1, UinputGraphNode); UinputGraphNode * node = T_ALLOC(1, UinputGraphNode);
if (!node) { if (!node) {
return NULL; return NULL;