1 2 /* Check for correct handling of nested scopes in a zero-biased 3 executable. */ 4 5 /* Relevant compile flags are: 6 7 -Wall -g -I$prefix/include/valgrind 8 9 eg -Wall -g -I`pwd`/Inst/include/valgrind 10 */ 11 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <assert.h> 15 #include "memcheck/memcheck.h" 16 17 /* Cause memcheck to complain about the address "a" and so to print 18 its best guess as to what "a" actually is. a must be 19 addressible. */ 20 21 void croak ( void* aV ) 22 { 23 char* a = (char*)aV; 24 char* undefp = malloc(1); 25 char saved = *a; 26 assert(undefp); 27 *a = *undefp; 28 (void) VALGRIND_CHECK_MEM_IS_DEFINED(a, 1); 29 *a = saved; 30 free(undefp); 31 } 32 33 #include <stdio.h> 34 35 void foo ( void ) 36 { 37 int var; 38 var = 1; 39 { char var[10]; 40 var[6] = 4; 41 croak( &var[7] ); 42 { struct { double foo; float bar; } var; 43 croak ( 2 + (char*)&var.bar ); 44 } 45 } 46 croak( 1 + (char*)&var ); 47 } 48 49 int main ( void ) 50 { 51 foo(); 52 return 0; 53 } 54