C语言编辑矩阵运算,数据溢出问题

if (td == 0){
float c1 = 2;
float c2 = 2;
float MaxDT = 20;
uint16_t N = 40;//Initialize the individuals in the tribe
uint16_t Nu = 10;
int D = Nu * 2;//Search Space dimension
int stop_index = 0;

    /*v*/
    rand_1 = rand(rand_1);
    rand_result = rand_1 / data2;
    float v_rand1 = -5 + 10 * rand_result;
    //int column1 = Nu * 2;
    Matrix_t mat_v1 = ones(N, Nu * 2);
........

问题出在最后一句mat_v1处,断点运行在倒数第二句mat_v1行列数值都特别大,运行到最后一句就数据溢出了

附上引用ones函数代码:
Matrix_t ones(uint16_t m, uint16_t n){
if (m <= 0 || n <= 0){
    exit(1);
}
Matrix_t mat = create_mat(m, n);
uint16_t i, j;
for (i = 0; i < n; i++){
    for (j = 0; j < m; j++){
        mat.data[i][j] = 1;
    }
}
return mat;
}
附上引用create函数代码:
Matrix_t create_mat(uint16_t row, uint16_t column){
Matrix_t mat;
if (row <= 0||column<=0)
{
    //printf("error, in create_mat: row <= 0||column<=0\n");
    exit(1);
}
if (row > 0 && column > 0)
{
    mat.row = row;
    mat.column = column;
    mat.data = (float **)malloc(row*sizeof(float *));//先指针的指针
    if (mat.data == NULL)
    {
        //printf("error, in create_mat: mat.data==NULL");
        exit(1);
    }
    uint16_t i;
    for (i = 0; i < row; i++)
    {
        *(mat.data + i) = (float *)malloc(column*sizeof(float));//再分配每行的指针
        if (mat.data[i] == NULL)
        {
          //printf("error, in create_mat: mat.data==NULL");
          exit(1);
        }
    }
    clear_mat(&mat);
}
return mat;

}
新人,没有悬赏。。。望路过大神相助!

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!