xref: /minix3/crypto/external/bsd/openssl/dist/bugs/dggccbug.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1ebfedea0SLionel Sambuc /* NOCW */
2ebfedea0SLionel Sambuc /* dggccbug.c */
3ebfedea0SLionel Sambuc /* bug found by Eric Young (eay@cryptsoft.com) - May 1995 */
4ebfedea0SLionel Sambuc 
5ebfedea0SLionel Sambuc #include <stdio.h>
6ebfedea0SLionel Sambuc 
7*0a6a1f1dSLionel Sambuc /*
8*0a6a1f1dSLionel Sambuc  * There is a bug in gcc version 2.5.8 (88open OCS/BCS, DG-2.5.8.3, Oct 14
9*0a6a1f1dSLionel Sambuc  * 1994) as shipped with DGUX 5.4R3.10 that can be bypassed by defining
10*0a6a1f1dSLionel Sambuc  * DG_GCC_BUG in my code. The bug manifests itself by the vaule of a pointer
11*0a6a1f1dSLionel Sambuc  * that is used only by reference, not having it's value change when it is
12*0a6a1f1dSLionel Sambuc  * used to check for exiting the loop.  Probably caused by there being 2
13*0a6a1f1dSLionel Sambuc  * copies of the valiable, one in a register and one being an address that is
14*0a6a1f1dSLionel Sambuc  * passed.
15*0a6a1f1dSLionel Sambuc  */
16ebfedea0SLionel Sambuc 
17*0a6a1f1dSLionel Sambuc /*-
18*0a6a1f1dSLionel Sambuc  * compare the out put from
19ebfedea0SLionel Sambuc  * gcc dggccbug.c; ./a.out
20ebfedea0SLionel Sambuc  * and
21ebfedea0SLionel Sambuc  * gcc -O dggccbug.c; ./a.out
22ebfedea0SLionel Sambuc  * compile with -DFIXBUG to remove the bug when optimising.
23ebfedea0SLionel Sambuc  */
24ebfedea0SLionel Sambuc 
inc(a)25ebfedea0SLionel Sambuc void inc(a)
26ebfedea0SLionel Sambuc int *a;
27ebfedea0SLionel Sambuc {
28ebfedea0SLionel Sambuc     (*a)++;
29ebfedea0SLionel Sambuc }
30ebfedea0SLionel Sambuc 
main()31ebfedea0SLionel Sambuc main()
32ebfedea0SLionel Sambuc {
33ebfedea0SLionel Sambuc     int p = 0;
34ebfedea0SLionel Sambuc #ifdef FIXBUG
35ebfedea0SLionel Sambuc     int dummy;
36ebfedea0SLionel Sambuc #endif
37ebfedea0SLionel Sambuc 
38*0a6a1f1dSLionel Sambuc     while (p < 3) {
39ebfedea0SLionel Sambuc         fprintf(stderr, "%08X\n", p);
40ebfedea0SLionel Sambuc         inc(&p);
41ebfedea0SLionel Sambuc #ifdef FIXBUG
42ebfedea0SLionel Sambuc         dummy += p;
43ebfedea0SLionel Sambuc #endif
44ebfedea0SLionel Sambuc     }
45ebfedea0SLionel Sambuc }
46