File: test_zapmem.c

package info (click to toggle)
fetchmail 6.5.6-2
  • links: PTS
  • area: main
  • in suites: forky
  • size: 7,596 kB
  • sloc: ansic: 19,190; sh: 7,108; python: 2,395; perl: 564; yacc: 447; lex: 286; makefile: 260; awk: 124; lisp: 84; exp: 43; sed: 17
file content (32 lines) | stat: -rw-r--r-- 780 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "fetchmail.h"

#define TESTSTRING "TESTBUFFER"

#define CHECK_BUF(buf) do { \
	size_t i;  \
	size_t len = sizeof(TESTSTRING); \
	for (i = 0; i < len; i++) { \
		if ((buf)[i]) exit(EXIT_FAILURE); \
	} \
} while(0)

static char buf2[] = TESTSTRING;

int main(void) {
	char *bufp1;
	char *bufp2;
	char *bufp3;
	static char buf1[] = TESTSTRING;
	char buf3[] = TESTSTRING;
	bufp1 = buf1; /* deliberately alias to incentivize optimization */
	bufp2 = buf2; /* deliberately alias to incentivize optimization */
	bufp3 = buf3; /* deliberately alias to incentivize optimization */

	fm_safe_clearmem(buf1, sizeof(buf1));
	fm_safe_clearmem(buf2, sizeof(buf2));
	fm_safe_clearmem(buf3, sizeof(buf3));
	CHECK_BUF(bufp1);
	CHECK_BUF(bufp2);
	CHECK_BUF(bufp3);
	return EXIT_SUCCESS;
}