Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: code cleanup

...

Code Block
bgColor#FFcccc
langc
char *secret;
const int SECRET_MAX = /* ... */
/* Initialize secret to a null-terminated byte string, 
   of less than SECRET_MAX chars */

char *new_secret;
size_t size = strlen(secret);
if (size >== SIZESECRET_MAX) {

  /* Handle error */
}

char *new_secret;
new_secret = (char *)malloc(size+1);
if (!new_secret) {
  /* Handle error */
}
strcpy(new_secret, secret);

/* Process new_secret... */

free(new_secret);
new_secret = NULL;

...

Code Block
bgColor#ccccff
langc
charhar *secret;

const int SECRET_MAX = /* ... */
/* Initialize secret to a null-terminated byte string, 
   of less than SECRET_MAX chars */

char *new_secret;
size_t size = strlen(secret);
if (size =>= SIZESECRET_MAX) {
  /* Handle error */
}

char *new_secret;
/* Use calloc() to zero-out allocated space */
new_secret = (char *)calloc(size+1, sizeof(char));
if (!new_secret) {
  /* Handle error */
}
strcpy(new_secret, secret);

/* Process new_secret... */

/* Sanitize memory  */
memset_s(new_secret, '\0', size);
free(new_secret);
new_secret = NULL;

...