From cbe4f45086d56dae1376ae4e6ece6f97bfb14b47 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 4 Feb 2007 00:31:44 +0000 Subject: [PATCH] section.c (check_cylce): Avoid segfault by checking for bt_size=0. svn path=/trunk/yasm/; revision=1751 --- libyasm/section.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libyasm/section.c b/libyasm/section.c index 9945f291..7e07f4a7 100644 --- a/libyasm/section.c +++ b/libyasm/section.c @@ -1078,8 +1078,9 @@ check_cycle(IntervalTreeNode *node, void *d) */ if (!depspan->backtrace) { depspan->backtrace = yasm_xmalloc((bt_size+2)*sizeof(yasm_span *)); - memcpy(depspan->backtrace, optd->span->backtrace, - bt_size*sizeof(yasm_span *)); + if (bt_size > 0) + memcpy(depspan->backtrace, optd->span->backtrace, + bt_size*sizeof(yasm_span *)); depspan->backtrace[bt_size] = optd->span; depspan->backtrace[bt_size+1] = NULL; return; @@ -1090,8 +1091,9 @@ check_cycle(IntervalTreeNode *node, void *d) depspan->backtrace = yasm_xrealloc(depspan->backtrace, (dep_bt_size+bt_size+2)*sizeof(yasm_span *)); - memcpy(&depspan->backtrace[dep_bt_size], optd->span->backtrace, - (bt_size-1)*sizeof(yasm_span *)); + if (bt_size > 0) + memcpy(&depspan->backtrace[dep_bt_size], optd->span->backtrace, + (bt_size-1)*sizeof(yasm_span *)); depspan->backtrace[dep_bt_size+bt_size] = optd->span; depspan->backtrace[dep_bt_size+bt_size+1] = NULL; } -- 2.40.0