malloc
returns a null pointer on failure. So, if what you received isn't null, then it points to a valid block of memory.
Since NULL
evaluates to false in an if
statement, you can check it in a very straightforward manner:
value = malloc(...);
if(value)
{
// value isn't null
}
else
{
// value is null
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…