Skip to content

Commit 85204d2

Browse files
Avoid printf in the recursive routines, so that the intercept of
mempcpy which is called from printf does not mess up the carefully-balanced call-stack overflow checks that this test does on ppc64-linux. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6471
1 parent 20b41c0 commit 85204d2

File tree

1 file changed

+46
-9
lines changed

1 file changed

+46
-9
lines changed

memcheck/tests/wrap8.c

+46-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#include <unistd.h>
22
#include <stdio.h>
33
#include <malloc.h>
44
#include <stdlib.h>
@@ -13,15 +13,15 @@
1313
Hence this test has two expected outcomes:
1414
- on ppc64-linux, a stack overflow is caught, and V aborts.
1515
- on everything else, it runs successfully to completion.
16+
Note, pre() and post() used so as to avoid printf, which messes
17+
up the call stacks on ppc64-linux due to intercept of mempcpy.
1618
*/
17-
1819
typedef
1920
struct _Lard {
2021
struct _Lard* next;
2122
char stuff[999];
2223
}
2324
Lard;
24-
2525
Lard* lard = NULL;
2626
static int ctr = 0;
2727

@@ -35,8 +35,8 @@ void addMoreLard ( void )
3535
lard = p;
3636
}
3737
}
38-
39-
38+
static void post ( char* s, int n, int r );
39+
static void pre ( char* s, int n );
4040
static int fact1 ( int n );
4141
static int fact2 ( int n );
4242

@@ -61,11 +61,11 @@ int I_WRAP_SONAME_FNNAME_ZU(NONE,fact1) ( int n )
6161
int r;
6262
OrigFn fn;
6363
VALGRIND_GET_ORIG_FN(fn);
64-
printf("in wrapper1-pre: fact(%d)\n", n); fflush(stdout);
64+
pre("wrapper1", n);
6565
addMoreLard();
6666
CALL_FN_W_W(r, fn, n);
6767
addMoreLard();
68-
printf("in wrapper1-post: fact(%d) = %d\n", n, r); fflush(stdout);
68+
post("wrapper1", n, r);
6969
if (n >= 3) r += fact2(2);
7070
return r;
7171
}
@@ -75,11 +75,11 @@ int I_WRAP_SONAME_FNNAME_ZU(NONE,fact2) ( int n )
7575
int r;
7676
OrigFn fn;
7777
VALGRIND_GET_ORIG_FN(fn);
78-
printf("in wrapper2-pre: fact(%d)\n", n); fflush(stdout);
78+
pre("wrapper2", n);
7979
addMoreLard();
8080
CALL_FN_W_W(r, fn, n);
8181
addMoreLard();
82-
printf("in wrapper2-post: fact(%d) = %d\n", n, r); fflush(stdout);
82+
post("wrapper2", n, r);
8383
return r;
8484
}
8585

@@ -101,3 +101,40 @@ int main ( void )
101101

102102
return 0;
103103
}
104+
105+
static void send ( char* s )
106+
{
107+
while (*s) {
108+
write(1, s, 1);
109+
s++;
110+
}
111+
}
112+
113+
static void pre ( char* s, int n )
114+
{
115+
char buf[50];
116+
fflush(stdout);
117+
sprintf(buf,"%d", n);
118+
send("in ");
119+
send(s);
120+
send("-pre: fact(");
121+
send(buf);
122+
send(")\n");
123+
fflush(stdout);
124+
}
125+
126+
static void post ( char* s, int n, int r )
127+
{
128+
char buf[50];
129+
fflush(stdout);
130+
sprintf(buf,"%d", n);
131+
send("in ");
132+
send(s);
133+
send("-post: fact(");
134+
send(buf);
135+
send(") = ");
136+
sprintf(buf,"%d", r);
137+
send(buf);
138+
send("\n");
139+
fflush(stdout);
140+
}

0 commit comments

Comments
 (0)