Note that you *must* compare with nil for NULL-pointer checks. If you coerce cdata to boolean type (e.g. by if-condition), you always get <true>. Example: local v = ffi.new'char *' if v == nil then print "this is working as intended" end -- this probably doesn't do what you think it does. -- Even NULL-pointer cdata (which compares equal to nil, see above), -- satisfies an if-condition (-> surprise segfault in this case): if v then print "surprise segfault!" nullptr[0] = 0 end --Wolfgang