I'm passing an array into this function and it's taking the item at index 0 and replacing the rest of the array with it. Any idea where this is going wrong?

Code:
void generic_sort (void *arg, size_t num, size_t size, int (*cmpfnc) (const void *, const void *)) {
   for (int i = 1; i < (int)num; ++i) {
      int j = i;
      char *tmp_address = malloc (sizeof (arg));
      tmp_address = (char *)arg + j * size;
      for (; j > 0; --j) {
         int cmp = cmpfnc (tmp_address, (char *)arg + (j - 1) * size);
         if (cmp > 0) 
            break;
         memcpy ((char *)arg + j * size, (char *)arg + (j - 1) * size, size);
      }
      memcpy ((char *)arg + j * size, tmp_address, size);
   }
}