On anything other than trivial examples it is an impossible problem. Given the gigabyte of code on iphones (and android) it's even more impossible. Best you can do is put an emphasis on quickly fixing any issues found and to practice security hardening. It seems iphone is failing on this pretty hard currently since they didn't fix these errors that were handed to them on a silver platter.