Use of memset_s() function instead memset() will standardized function that will securely overwrites the memory with a specified value.
1#include <string.h>
2#include <stdlib.h>
3
4void insecureUseMemsetNonCompliant() {
5 char *buffer = malloc(1024);
6 // Noncompliant: Use of insecure function.
7 memset(buffer, 0, 512);
8 free(buffer);
9}
1#include <string.h>
2#include <stdlib.h>
3#include <sys/_types/_errno_t.h>
4
5void insecureUseMemsetCompliant() {
6 char *buffer = malloc(1024);
7 // Compliant: Use of secure function.
8 errno_t res = memset_s(buffer, 1024, 0, 1024);
9 free(buffer);
10}