runtime error但vs运行正确

问题遇到的现象和发生背景

leetcode 题目

img


在网页上始终是runtime error 无法通过编译
但是在vs2022上能通过编译返回正确结果

char* convert(char* s, int numRows)
{
    int Len = strlen(s);
    int status = 0;                 //0表示正常行间距   1表示特殊行间距
    int index_t = 0;
    int index_s = 0;
    int point = 0;
    char* target = (char*)malloc(Len * sizeof(char));
    memset(target, 1, Len * sizeof(char));

    while (index_t < Len && point < numRows)   //添加point条件控制循环正常结束  同时注意字符串从0开始计数
    {
        while (index_s < Len && point index_t < Len)   //添加循环控制条件,index_t  程序反馈 字符串溢出
        {                                                        //1.当处理最后一行的时候若执行第一个条件语句行间距被处理为0
            target[index_t] = s[index_s];                        //2.添加或与运算符时语序添加错误if (status == 0 || point == 0  && point != numRows - 1)                                                                                  
            index_t++;                                           //上一行的条件语句 只要status为真则不在检测之后的语句 如果为假再检测下一个语句 
            if (point != numRows - 1 && status == 0 || point == 0)   //所以要把与条件放在之前的位置
            {
                index_s += 2 * (numRows - point - 1);     //操作行距变化
                status = 1;
            }
            else
            {
                index_s += 2 * point;
                status = 0;
            }
        }
        status = 0;     //恢复status的值以保证行间距测量正确
        point++;
        index_s = point;    //重置了循环条件导致循环不能正常退出
    }
        
    target[Len - 1] = '\0';
    return target;
}


运行结果及报错内容

img

在malloc代码后面添加

if (target == NULL)
    {
        printf("Allpcate error.\n");
        exit(EXIT_FAILURE);
    }   
保证指针不会指空就行               
```c


```