00001
00002
00003
00004 #include "cddefines.h"
00005 #include "parse.h"
00006
00007 #ifdef _MSC_VER
00008 #pragma warning( disable : 4700 )
00009 #endif
00010 #ifdef __INTEL_COMPILER
00011 #pragma warning( disable : 592 )
00012 #endif
00013
00014 #ifdef _MSC_VER
00015 #pragma warning( disable : 4756 )
00016 #endif
00017
00018 #define ARR_SIZE 10
00019
00020 static double ar2[ARR_SIZE];
00021
00022 void ParseCrashDo(char *chCard)
00023 {
00024 float ar1, br1;
00025 long int i;
00026
00027 bool lgCrash = false;
00028
00029 if( nMatch("ZERO",chCard) )
00030 {
00031 fprintf(ioQQQ," I will now div by 0 to get crash. Hold on.\n");
00032 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong ....\" then there are problems.\n");
00033 fflush(ioQQQ);
00034 ar1 = (float)(1. / ZeroNum);
00035 fprintf(ioQQQ," I am still alive - something is wrong, result is %e\n",
00036 ar1);
00037 lgCrash = true;
00038 }
00039
00040
00041 else if( nMatch("UNDE",chCard) )
00042 {
00043 if( nMatch("STAT",chCard) )
00044 {
00045 fprintf(ioQQQ," Now I will now use an undefined static variable. Hold on.\n");
00046 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong ....\" then there are problems.\n");
00047 fflush(ioQQQ);
00048
00049 ar2[0] *= 1e-10;
00050
00051
00052 fprintf(ioQQQ," I am still alive - something is wrong, the result of the multiplication of undefined by 1e-10 is %e\n", ar2[0] );
00053 fflush(ioQQQ);
00054 }
00055 else if( nMatch("STAC",chCard) || nMatch("AUTO",chCard) )
00056 {
00057 float A_variable_which_SHOULD_be_used_uninitialized;
00058 fprintf(ioQQQ," Now I will now use an undefined variable off the stack. Hold on.\n");
00059 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong ....\" then there are problems.\n");
00060 fflush(ioQQQ);
00061
00062 A_variable_which_SHOULD_be_used_uninitialized *= 1e-10f;
00063
00064
00065 fprintf(ioQQQ," I am still alive - something is wrong, the result of the multiplication of undefined by 1e-10 is %e\n", A_variable_which_SHOULD_be_used_uninitialized );
00066 fflush(ioQQQ);
00067 }
00068 else
00069 {
00070
00071 float *aa = (float*)MALLOC(3*sizeof(float));
00072 fprintf(ioQQQ," I will now use an undefined variable off the heap obtained with malloc. Hold on.\n");
00073
00074 if( MyIsnan( aa[1] ) )
00075 fprintf(ioQQQ," The malloc'ed memory was set to NaN.\n" );
00076 else
00077 fprintf(ioQQQ," The malloc'ed memory was NOT initialized by MyMalloc.\n" );
00078 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong ....\" then there are problems.\n");
00079 fflush(ioQQQ);
00080
00081 aa[1] *= 1e-10f;
00082
00083 fprintf(ioQQQ," I am still alive - something is wrong, the result of the multiplication of undefined by 1e-10 is %e\n", aa[1] );
00084 fflush(ioQQQ);
00085 free( aa );
00086 }
00087 lgCrash = true;
00088 }
00089
00090
00091 else if( nMatch("OVER",chCard) && nMatch("LONG",chCard) )
00092 {
00093 long lng;
00094 fprintf(ioQQQ," I will now make long overflow to get crash. Hold on.\n");
00095 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong ....\" then there are problems.\n");
00096 fflush(ioQQQ);
00097 lng = (long)(LONG_MAX*sqrt(1e6) );
00098 fprintf(ioQQQ," I am still alive - something is wrong, the result was %li\n",
00099 lng);
00100 lgCrash = true;
00101 }
00102
00103
00104 else if( nMatch("OVER",chCard) )
00105 {
00106 ar1 = 1e-20f;
00107 fprintf(ioQQQ," I will now make float overflow to get crash. Hold on.\n");
00108 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong ....\" then there are problems.\n");
00109 fflush(ioQQQ);
00110 br1 = (float)(DBL_MAX / ar1);
00111 fprintf(ioQQQ," I am still alive - something is wrong, the result was %e\n",
00112 br1);
00113 lgCrash = true;
00114 }
00115
00116
00117 else if( nMatch("ASSE",chCard) )
00118 {
00119 fprintf(ioQQQ," I will now assert that a false statement is true to get a crash.\n\n");
00120 fprintf(ioQQQ," The correct behavior is for the statement \"DISASTER An assert has been thrown, this is bad\" to be printed.\n\n");
00121 fprintf(ioQQQ," If the next line says \"I am still alive - the assert macro is not working ....\" then there are problems.\n\n");
00122 fflush(ioQQQ);
00123 ASSERT( DBL_MAX < ZeroNum );
00124 fprintf(ioQQQ," I am still alive - the assert macro is not working in this executable.\n");
00125 lgCrash = true;
00126 }
00127
00128
00129 else if( nMatch(" NAN",chCard) )
00130 {
00131 ar1 = 0.;
00132 fprintf(ioQQQ," I will now make invalid operation (div 0 by 0) to get crash. Hold on.\n");
00133 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong ....\" then there are problems.\n");
00134 fflush(ioQQQ);
00135 br1 = (float)(ar1 / ZeroNum);
00136 fprintf(ioQQQ," I am still alive - something is wrong, the result was %e\n",
00137 br1);
00138 lgCrash = true;
00139 }
00140
00141
00142 else if( nMatch("SETN",chCard) && nMatch("FLOA",chCard) )
00143 {
00144 float f;
00145 fprintf(ioQQQ," I will now initialize a float to a signaling NaN. This should never crash!\n");
00146 set_nanf(f);
00147 fprintf(ioQQQ," Initialization finished. I will now perform an operation on this variable. Hold on.\n");
00148 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong ....\" then there are problems.\n");
00149 fflush(ioQQQ);
00150 f *= 2.f;
00151 fprintf(ioQQQ," I am still alive - something is wrong, the result was %e\n",
00152 f);
00153 lgCrash = true;
00154 }
00155
00156
00157 else if( nMatch("SETN",chCard) )
00158 {
00159 double d;
00160 fprintf(ioQQQ," I will now initialize a double to a signaling NaN. This should never crash!\n");
00161 set_nan(d);
00162 fprintf(ioQQQ," Initialization finished. I will now perform an operation on this variable. Hold on.\n");
00163 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong ....\" then there are problems.\n");
00164 fflush(ioQQQ);
00165 d *= 2.;
00166 fprintf(ioQQQ," I am still alive - something is wrong, the result was %e\n",
00167 d);
00168 lgCrash = true;
00169 }
00170
00171
00172 else if( nMatch("BOUN",chCard) )
00173 {
00174 bool lgEOL;
00175 double x;
00176 i = 5;
00177
00178
00179 x = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
00180 if( lgEOL && nMatch(" LOW", chCard ) )
00181 x = -2.;
00182 if( lgEOL && nMatch("HIGH", chCard ) )
00183 x = 2.;
00184
00185
00186
00187 i = ( x >= 0. ) ? (long)(x+0.5) + ARR_SIZE : (long)(x-0.5);
00188
00189
00190
00191
00192 if( nMatch("STAT",chCard) )
00193 {
00194 fprintf(ioQQQ," I will now access static array element ar2[%ld]. Hold on.\n", i );
00195 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong\" then there are problems.\n");
00196 fflush(ioQQQ);
00197 ar2[i] = 1e-10;
00198
00199 fprintf(ioQQQ," I am still alive - something is wrong\n" );
00200 fflush(ioQQQ);
00201 }
00202 else if( nMatch("STAC",chCard) || nMatch("AUTO",chCard) )
00203 {
00204 float a[ARR_SIZE];
00205 fprintf(ioQQQ," I will now access automatic array element a[%ld]. Hold on.\n", i );
00206 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong\" then there are problems.\n");
00207 fflush(ioQQQ);
00208 a[i] = 1e-10f;
00209
00210 fprintf(ioQQQ," I am still alive - something is wrong, return value was %.2e\n", a[i] );
00211 fflush(ioQQQ);
00212 }
00213 else if( nMatch("HEAP",chCard) )
00214 {
00215 int *ibound;
00216 ibound = ((int *)MALLOC( ARR_SIZE*sizeof(int) ));
00217 fprintf(ioQQQ," I will now access malloced heap array element ibound[%ld]. Hold on.\n", i );
00218 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong\" then there are problems.\n");
00219 fflush(ioQQQ);
00220 ibound[i] = 1;
00221 fprintf(ioQQQ," I am still alive - something is wrong, return value is %i\n" , ibound[i] );
00222 fflush(ioQQQ);
00223 free(ibound);
00224 }
00225 else
00226 {
00227 fprintf(ioQQQ," The CRASH BOUNDS command has three different tests. One must be specified\n" );
00228 fprintf(ioQQQ," The HEAP option tests a malloc/'d array - this tests valgrind or purify.\n");
00229 fprintf(ioQQQ," The STATIC option tests a static declared array, and the STACK or AUTO option tests an automatic array - these test pgcc.\n");
00230 fprintf(ioQQQ," All have a number as an optional argument, the array element to be accessed.\n");
00231 fflush(ioQQQ);
00232 }
00233
00234
00235 lgCrash = true;
00236 }
00237
00238
00239 else if( nMatch("ISNA",chCard) )
00240 {
00241 if( nMatch("FLOA",chCard) )
00242 {
00243 float ff;
00244 fprintf(ioQQQ," I will now set a float to SNaN\n" );
00245 set_nanf( ff );
00246 fprintf(ioQQQ," I will now test this variable with the isnan function\n" );
00247 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong\" then there are problems.\n");
00248 ASSERT( !isnan( ff ) );
00249 fprintf(ioQQQ," I am still alive - something is wrong, value is %e\n", ff );
00250 }
00251 else
00252 {
00253 double dd;
00254 fprintf(ioQQQ," I will now set a double to SNaN\n" );
00255 set_nan( dd );
00256 fprintf(ioQQQ," I will now test this variable with the isnan function\n" );
00257 fprintf(ioQQQ," If the next line says \"I am still alive - something is wrong\" then there are problems.\n");
00258 ASSERT( !isnan( dd ) );
00259 fprintf(ioQQQ," I am still alive - something is wrong, value is %e\n", dd );
00260 }
00261 }
00262
00263 else
00264 {
00265 fprintf(ioQQQ,
00266 " crash options are ZERO, UNDEfined, OVERflow, ASSErt, _NAN, SETNan, BOUNds, and ISNAn.\n");
00267 lgCrash = true;
00268 }
00269
00270 if( lgCrash )
00271 {
00272 puts( "[Stop in ParseCrashDo]" );
00273 cdEXIT(EXIT_FAILURE);
00274 }
00275 }
00276
00277 #ifdef _MSC_VER
00278 #pragma warning( default : 4700 )
00279 #endif