Guest User

memcpy Crash

a guest
Apr 22nd, 2011
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.99 KB | None | 0 0
  1. stock QSortAssoc(numbers[][], sort_index, left, right, pivot[], len)
  2. {
  3.     new
  4. //      pivot   = numbers[left],
  5.         l_hold  = left  ,
  6.         r_hold  = right ;
  7.  
  8.     memcpy(pivot, numbers[left], 0, len * 4, len);
  9.     // A print tells me it crashes here; this is consistent
  10.    
  11.    
  12.     while (left < right)
  13.     {
  14.         while ((numbers[right][sort_index] >= pivot[sort_index]) && (left < right)) right--;
  15.         if (left != right)
  16.         {
  17.             memcpy(numbers[left], numbers[right], 0, len * 4, len);
  18.             left++;
  19.         }
  20.         while ((numbers[left][sort_index] <= pivot[sort_index]) && (left < right)) left++;
  21.         if (left != right)
  22.         {
  23.             memcpy(numbers[right], numbers[left], 0, len * 4, len);
  24.             right--;
  25.         }
  26.     }
  27.    
  28.     memcpy(numbers[left], pivot, 0, len * 4, len);
  29.    
  30.     pivot[sort_index] = left;
  31.    
  32.     left    = l_hold;
  33.     right   = r_hold;
  34.    
  35.     if (left < pivot[sort_index]) QSortAssoc(numbers, sort_index, left, pivot[sort_index] - 1, pivot, len);
  36.     if (right > pivot[sort_index]) QSortAssoc(numbers, sort_index, pivot[sort_index] + 1, right, pivot, len);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment