diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index 3cb63a275..0676c883b 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -157,7 +157,7 @@ static int tcl_new_connection(struct connection *connection) connection->priv = tclc; - struct target *target = get_current_target(connection->cmd_ctx); + struct target *target = get_current_target_or_null(connection->cmd_ctx); if (target != NULL) tclc->tc_laststate = target->state; diff --git a/src/target/target.c b/src/target/target.c index 871588393..74b332df5 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -517,9 +517,7 @@ struct target *get_target_by_num(int num) struct target *get_current_target(struct command_context *cmd_ctx) { - struct target *target = cmd_ctx->current_target_override - ? cmd_ctx->current_target_override - : cmd_ctx->current_target; + struct target *target = get_current_target_or_null(cmd_ctx); if (target == NULL) { LOG_ERROR("BUG: current_target out of bounds"); @@ -529,6 +527,13 @@ struct target *get_current_target(struct command_context *cmd_ctx) return target; } +struct target *get_current_target_or_null(struct command_context *cmd_ctx) +{ + return cmd_ctx->current_target_override + ? cmd_ctx->current_target_override + : cmd_ctx->current_target; +} + int target_poll(struct target *target) { int retval; diff --git a/src/target/target.h b/src/target/target.h index d79613138..fb9d71465 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -396,6 +396,7 @@ int target_call_timer_callbacks_now(void); struct target *get_target_by_num(int num); struct target *get_current_target(struct command_context *cmd_ctx); +struct target *get_current_target_or_null(struct command_context *cmd_ctx); struct target *get_target(const char *id); /**