Runtime Error although it's working in the "running code" section


  • 0
    Y

    Hi,

    I keep getting this runtime error message: member access within misaligned address 0x000000000031 for type 'struct ListNode', which requires 8 byte alignment

    the input that fires the error is,

    [4,5,2,2,9,3,8,9,2]
    [0,7,6,1,6,5,0,6,7]
    

    am I missing something?

    this is the solution I wrote:

    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     struct ListNode *next;
     * };
     */
    struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
        struct ListNode *l = (struct ListNode*) malloc(sizeof(struct ListNode));
        struct ListNode *p = l;
        
        int R = 0;
        while (l1 != NULL || l2 != NULL) {
            int dig1 = 0, dig2 = 0, sum;
            
            if (l1) {
                dig1 = l1->val;
                l1 = l1->next;
            }
            if (l2) {
                dig2 = l2->val;
                l2 = l2->next;
            }
            
            sum = dig1+dig2+R;
            R = sum/10;
            
            p->val = sum%10;
            if (l1 != NULL || l2 != NULL) {
                p->next = (struct ListNode*) malloc(sizeof(struct ListNode));
                p = p->next;
            }
        }
        
        if (R != 0) {
            p->next = (struct ListNode*) malloc(sizeof(struct ListNode));
            p->next->val = R;
        }
    
        return l;
    }
    

  • 0
    E

    @yassineaddi

    i too am noticing issues with Run Code related button and posting in the"Discuss" tab of problems. Any LeetCode support staff there to fix these issues?


  • 0
    Y

    @edaengineer
    Exactly, I had an issue with another problem too, the Two Sum problem to be specific, I contacted the support but they just told me to post about it in the discussion area.


  • 0
    E

    @yassineaddi said in Runtime Error although it's working in the "running code" section:

    @edaengineer
    Exactly, I had an issue with another problem too, the Two Sum problem to be specific, I contacted the support but they just told me to post about it in the discussion area.

    Then I think they are just not doing anything. You contacted Support and they should have looked into it. Contact them again saying no one here seems to respond and others are facing the same issue.

    Where did you send the mail to? Do write a strong mail so they look into it. Too bad they should have looked into it the first time you contacted them.


Log in to reply
 

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