- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
char *SomeGlobalPointer {};
void foo()
{
SomeGlobalPointer = new char[1024];
}
int main()
{
foo();
if (!SomeGlobalPointer)
{
delete[] SomeGlobalPointer;
}
return 0;
}
Вызывает подозрение строка двенадцать
delete[] на 0 это ж краш?
If expression evaluates to a null pointer value, no destructors are called, and the deallocation function may or may not be called (it's unspecified), but the default deallocation functions are guaranteed to do nothing when passed a null pointer.
https://en.cppreference.com/w/cpp/language/delete
Т. е. зависит от типа. Встроенные деаллокаторы обещают с нулём ничего не делать.
Алсо, тут vlaue инициализатор "{}" который явно закажет туда nullptr
https://govnokod.ru/24560
Насчет крестоговна - не уверен.