Fix use-after-free complained by coverity

It's not really use-after-use, because the pointer is not dereferenced
Avoid assignment inside the macro call

This causes multiple assignments, which has undefined sequences
Check pointer against NULL

Reported by coverity
Correct integer type of a var

Or coverity complains:
CID 54796: Macro compares unsigned to 0 (NO_EFFECT)
unsigned_compare: This greater-than-or-equal-to-zero comparison of an unsigned value is always true. code >= 0U.
Merge branch 'atronix' into coverity_scan