Runtime error "reference binding to misaligned address 0x00000001ddb1"


  • 0
    H

    Does anyone know what C++ compiler is used in the backend? The system cannot pass my solution. It has the following error:
    Runtime Error Message:
    reference binding to misaligned address 0x00000001ddb1 for type 'const int', which requires 4 byte alignment
    Last executed input:
    [1,8]
    [0]

    But I can run my solution successfully within my own laptop. I am using GCC 4.8.5. Does anyone know why I have this error? My solution is as follows:

    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
            if(!l1 && !l2)
                return NULL;
            
            ListNode *p, *q;
            p = l1;
            q = l2;
            
            ListNode * head = (ListNode*)malloc(sizeof(ListNode));
            ListNode *curr = head;
            int carry = 0;
            int x, y, temp, sum;
            while(p!=NULL || q!=NULL)
            {
                x = (p!=NULL) ? p->val : 0;
                y = (q!=NULL) ? q->val : 0;
                sum = x + y + carry;
                temp = sum % 10;
                curr->val = temp;
                carry = sum/10;
                if((p && p->next) || (q && q->next) )
                {
                    ListNode *new_node = (ListNode*)malloc(sizeof(ListNode));
                    curr->next = new_node;
                    curr = curr->next;
                }          
                
                p = (p != NULL) ? p->next : NULL;
                q = (q != NULL) ? q->next : NULL;
            }
            if(carry == 1)
            {
                curr = (ListNode*)malloc(sizeof(ListNode));
                curr->val = 1;
            }
            
            curr = head;
            return curr;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.