• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /* Check some aspects of the use of the
3    VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE and
4    VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE macros. */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 #include "../memcheck.h"
10 
main(void)11 int main ( void )
12 {
13   volatile int* volatile mem
14      = (volatile int* volatile)malloc(1000 * sizeof(int));
15   free((void*)mem);
16 
17   // Check that we get an invalid access complaint
18   fprintf(stderr, "\nDoing invalid access.  Expect complaint.\n\n");
19   mem[123] = 0;
20 
21   // Now disable error reporting in the range
22   fprintf(stderr, "\nDisabling address error reporting for the range.\n\n");
23   VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(mem, 1000 * sizeof(int));
24 
25   // Check that we get an invalid access complaint
26   fprintf(stderr, "\nDoing invalid another access.  Expect no complaint.\n\n");
27   mem[456] = 0;
28 
29   // Re-enable reporting on the first byte of one word from the ignore range
30   fprintf(stderr, "\nPartially reenabling address error reporting.\n\n");
31   VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(&mem[789], 1);
32 
33   // Check that we get an invalid access complaint
34   fprintf(stderr, "\nDoing a third access.  Expect complaint.\n\n");
35   mem[789] = 0;
36 
37   // And now quit and expect to see a warning about two remaining ranges
38   fprintf(stderr, "\nExiting.  Expect warnings of 2 remaining ranges.\n\n");
39 
40   return 0;
41 }
42