From d03781f45bfc507ca7b2bf948ceed2e898da06f0 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Sat, 16 Nov 2013 03:17:13 +0000 Subject: [PATCH] Fix the $timer() scripting function. This function never worked - function_timer() was creating a string but then never throwing it away and returning a part of the argument instead, which then caused a crash because it couldn't be freed later in the expression parsing. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@472 13b04d17-f746-0410-82c6-800466cd88b0 --- Changelog | 2 ++ source/timer.c | 38 ++++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Changelog b/Changelog index 355b69d..76387e0 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,7 @@ [Changes 1.2c01] +* Fix the $timer() scripting function. (caf) + * Fix the /TKB (timed kickban) command. (caf) * Rewrite termcap/terminfo detection logic in configure and include term.h diff --git a/source/timer.c b/source/timer.c index 881794b..0107fb4 100644 --- a/source/timer.c +++ b/source/timer.c @@ -454,24 +454,26 @@ static TimerList *get_timer (char *ref) char *function_timer(char *n, char *args) { -char *ref; -char *out = NULL; -TimerList *tmp; - ref = next_arg(args, &args); - if (ref && *ref && (tmp = get_timer(ref))) - { - double time_left; - struct timeval current; - char buf[40]; - get_time(¤t); - time_left = BX_time_diff(current, tmp->time); - if (time_left < 0) - time_left = 0.0; - snprintf(buf, sizeof buf, "%0.3f", time_left); - malloc_sprintf(&out, "%s %d %d %d %d %s %s %s", tmp->ref, tmp->server, tmp->window, tmp->interval, tmp->events, buf, tmp->callback? "(internal callback)" : (tmp->command? tmp->command : ""), tmp->whom ? tmp->whom : empty_string ); - return ref; - } - return m_strdup(empty_string); + char *ref = next_arg(args, &args); + TimerList *t = NULL; + double time_left; + struct timeval current; + + if (ref && *ref) + t = get_timer(ref); + + if (!t) + return m_strdup(empty_string); + + get_time(¤t); + time_left = BX_time_diff(current, t->time); + if (time_left < 0) + time_left = 0.0; + + return m_sprintf("%s %d %d %ld %d %0.3f %s%s", t->ref, t->server, + t->window, (long)t->interval, t->events, time_left, + t->callback ? "(internal callback) " : t->command, + t->whom ? t->whom : ""); } /*