section.c (check_cylce): Avoid segfault by checking for bt_size=0.
authorPeter Johnson <peter@tortall.net>
Sun, 4 Feb 2007 00:31:44 +0000 (00:31 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 4 Feb 2007 00:31:44 +0000 (00:31 -0000)
svn path=/trunk/yasm/; revision=1751

libyasm/section.c

index 9945f29161eae64ff59329a702670b30460e3585..7e07f4a7286c2b5b3026d1e5da9b7321d33ff9f3 100644 (file)
@@ -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;
 }