Change
GetMem::GetMem(UINT lenght) {
// up to now, value of size is indeterminate
ptr = calloc(1, size); // undefined behavior using indeterminate value
if (!ptr){
MessageBox(hwnd, "cant alloc", "error", MB_OK);
exit(0);
}
size = lenght;
}
to
GetMem::GetMem(UINT lenght) {
size = lenght; // <- set size first before using it
ptr = calloc(1, size);
if (!ptr){
MessageBox(hwnd, "cant alloc", "error", MB_OK);
exit(0);
}
}