Fix bitwise/logical OR problems

Avoid crash on NULL allocation
Fix mismatched parentheses