Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Include this file to get the `erase_from_memory` function that zeros memory. See
#define __ERASE_FROM_MEMORY_H__ 1
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdlib.h>
#include <string.h>
void *erase_from_memory(void *pointer, size_t size_data, size_t size_to_remove) {
#ifdef __STDC_LIB_EXT1__
memset_s(pointer, size_data, 0, size_to_remove);
if(size_to_remove > size_data) size_to_remove = size_data;
volatile unsigned char *p = pointer;
while (size_to_remove--){
*p++ = 0;
return pointer;
#endif // __ERASE_FROM_MEMORY_H__
gcc test_erase.c erase_from_memory.h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "erase_from_memory.h"
int main(){
char a[6] = "hello";
printf("%s\n", a);
erase_from_memory(a, 6, 6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.