[Cryptography] GnuTLS -- time to look at the diff.

James A. Donald jamesd at echeque.com
Fri Mar 7 20:28:37 EST 2014


On 2014-03-08 03:22, Nico Williams wrote:
> Consider some alternatives:
>
>      ret = func(...);
>      if (ret != success) {
>          /* cleanup */
>          ...
>      }
>
>      ret = ...
>      if (ret != success) {
>          /* cleanup */
>          /* oops!  I'd better not forget to check that this does
> everything that needed to be done, plus any additional cleanup work
> needed since the previous cleanup section! */
>          ...
>      }
>
> Yuck.   Really, that's what you want?  You don't think that's error-prone?  Or:
>
>      if ((ret = ...) != success ||
>          (ret = ...) != success ||
>          ...) {
>          /* single cleanup section; look ma'!  no gotos in sight!  no
> needless repetition either */
>          ...
>      }

C++ can and always should automate clean up.  You make everything that 
needs to be cleaned up a variable with the appropriate clean up rules, 
and the compiler generates the cleanup code invisibly and correctly.

C++ memory management is actually better than python or Java in this 
regard.  It is worse than python or Java, in that it is optional, and 
not everyone exercises the option, and in that the ability to set the 
rules means the ability to set them wrong.




More information about the cryptography mailing list