0
  1. how can I find the bus error 10 for the initiation process of my skip list???
    struct leapList *initSkipList(struct leapList *skipList[]) {
        int i;
        for (i=0;i<maximum_level;i++) {

               //this is likely to be the bus error, the breakpointbut how
               //can we find the error
                
                struct leapList* newHead = (struct leapList*)malloc(sizeof(struct leapList));
                if (NULL == newHead) {
                        printf(" Fail to applicate on the tail node\n");
                        return NULL;
                }
                newHead->data = -1-i;
                newHead->down = NULL;
                newHead->up = NULL;
                newHead->next = NULL;
                newHead->last = NULL;

                skipList[i] = newHead;
        }
        return *skipList;
}
जलजनक
  • 3,072
  • 2
  • 24
  • 30
JamesL_22
  • 11
  • 2
  • 2
    Of the code presented, the only thing that should/could trip a bus error would be `skipList[i] = newHead;`. That, assuming you're properly including `stdlib.h`, which we don't know because we don't have a proper [mcve]. It wouldn't hurt to [stop unnecessarily casting `malloc` in C programs](https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc) just to be safe. – WhozCraig Apr 07 '22 at 21:14
  • @WhozCraig I think some Apple platforms can get `SIGBUS` instead of `SIGSEV` when they access a memory address that isn't mapped - such as when running on a 64-bit platform with `#include ` omitted so the return value from `malloc()` is truncated to a 32-bit `int` value, and then the truncation is hidden from warnings or other compiler messages because an explicit cast was unneccesarily used.... – Andrew Henle Apr 08 '22 at 00:41
  • @AndrewHenle Yeah, either way, twas the reason I mentioned "That, assuming you're properly including stdlib.h, which we don't know". – WhozCraig Apr 08 '22 at 00:46

0 Answers0