Skip to content

Instantly share code, notes, and snippets.

Created September 6, 2012 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3650840 to your computer and use it in GitHub Desktop.
Save anonymous/3650840 to your computer and use it in GitHub Desktop.
a bad code
malloc(103+aString.size()+4);
//Allocate a little space to hold a record composed of various fields
//103 = sum of field sizes, including the max length (externally specified) of string fields but not their null terminators when represented as C-strings
//aString.size() - but only the actual length of this string, for some reason.
//4 = space for a null terminator for each string field
//Original didn't have these explanatory comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment