Why does this show a warning for dereferencing nullptr in C
Level1Tilemap->Map = (int*)((malloc(Level1Columns * sizeof(int))));
for (int i = 0; i < Level1Columns; i++)
{
Level1Tilemap->Map[i] = malloc(Level1Rows * sizeof(int));
for (int j = 0; j < Level1Rows; j++)
{
Level1Tilemap->Map[i][j] = Level1MapStaticArray[i][j];
}
}
I am using malloc to create a 2D array of ints
But the editor shows warning and Level1Tilemap->Map has the memory address of nullptr
And the defination int** Map;
malloccan return a null pointer and you should check for thatsizeof(int)but you probably wantsizeof(int*)(int*)((malloc(Level1Columns * sizeof(int))));->(int*)((malloc(Level1Columns * sizeof(int*))));NULL, and if it does, useperror()to print it.Level1Tilemapproperly set to something? And is itLevel1Tilemap->Map = (int**)malloc...you want?