as long as you're at it, passing NULL for buffer will crash as well. might want to guard against this