memsafe-c/examples/ll.c
2026-08-02 07:34:05 -04:00

28 lines
No EOL
455 B
C

#include <stdio.h>
#include <stdlib.h>
#define MEMSAFE_PLEASE
#include "memsafe.h"
typedef struct LLNode {
int dat;
struct LLNode *next;
} LLNode;
int main(void) {
memsafe_pushhist;
LLNode *root = safemalloc(sizeof(LLNode));
root->dat = 0;
LLNode *curr = root;
for (int i = 1; i < 1000; ++i) {
LLNode *next = safemalloc(sizeof(LLNode));
curr->next = next;
next->dat = i;
curr = next;
}
root = NULL;
memsafe_pophist;
return 0;
}