code:
/**
Note: The returned array must be malloced, assume caller calls free().
/
int twoSum(int* nums, int numsSize, int target, int* returnSize)
{
int i, j;
returnSize = (int *)malloc(sizeof(int) * 3);
for(i = 0; i<numsSize; i++)
{
for(j = 0; j<numsSize; j++)
{
if(nums[i] + nums[j] == target)
{
returnSize[0] = i;
returnSize[1] = j;
return returnSize;
}
}
}
return returnSize;
}
I dont understand why I cant pass the test example input.
Actual
× Runtime Error
× runtime: N/A
× answer:
× stdout: ''
× error: AddressSanitizer: heap-buffer-overflow on address 0x60200000003c at pc 0x0000004050c0 bp 0x7ffdb3ed4010 sp 0x7ffdb3ed4008
× error: =================================================================
==30==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000003c at pc 0x0000004050c0 bp 0x7ffdb3ed4010 sp 0x7ffdb3ed4008
READ of size 4 at 0x60200000003c thread T0
#2 0x7fae1dea72e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
who can tell me why. thank you!