Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

size_t size = strlen(secret);
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
char *secret;

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

size_t size = strlen(secret);
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;

...