From 65df86acaede608cb416c10f575ff0053dd674e8 Mon Sep 17 00:00:00 2001 From: zogodo <742782908@qq.com> Date: Thu, 26 Dec 2019 23:47:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E7=BE=8E!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TC1/timed_task/timed_task.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/TC1/timed_task/timed_task.c b/TC1/timed_task/timed_task.c index dba6c67..8fd7451 100644 --- a/TC1/timed_task/timed_task.c +++ b/TC1/timed_task/timed_task.c @@ -93,16 +93,11 @@ bool DelTask(int time) char* GetTaskStr() { - if (task_top == NULL) - { - char* str = (char*)malloc(sizeof(char)*3); - sprintf(str, "%s", "[]"); - return str; - } - char* str = (char*)malloc(sizeof(char)*task_count * 60); + char* str = (char*)malloc(sizeof(char)*(task_count*60+2)); pTimedTask tmp_tsk = task_top; char* tmp_str = str; tmp_str[0] = '['; + tmp_str[2] = 0; tmp_str++; while (tmp_tsk) { @@ -116,6 +111,7 @@ char* GetTaskStr() tmp_str += strlen(tmp_str); tmp_tsk = tmp_tsk->next; } - *(--tmp_str) = ']'; + if (task_count > 0) --tmp_str; + *tmp_str = ']'; return str; }