Changeset 331 for EcnlProtoTool/trunk/tcc-0.9.27/tests/boundtest.c
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/tcc-0.9.27
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/tcc-0.9.27/tests/boundtest.c
r321 r331 1 1 #include <stdlib.h> 2 2 #include <stdio.h> 3 #include <string.h> 3 4 4 5 #define NB_ITS 1000000 … … 50 51 int *tab4; 51 52 53 fprintf(stderr, "%s start\n", __FUNCTION__); 54 52 55 tab4 = malloc(20 * sizeof(int)); 53 56 for(i=0;i<20;i++) { … … 56 59 free(tab4); 57 60 61 fprintf(stderr, "%s end\n", __FUNCTION__); 58 62 return sum; 59 63 } … … 64 68 int i, sum = 0; 65 69 int *tab4; 70 71 fprintf(stderr, "%s start\n", __FUNCTION__); 66 72 67 73 tab4 = malloc(20 * sizeof(int)); … … 71 77 free(tab4); 72 78 79 fprintf(stderr, "%s end\n", __FUNCTION__); 73 80 return sum; 74 81 } … … 187 194 } 188 195 196 /* ok */ 197 int test16() 198 { 199 char *demo = "This is only a test."; 200 char *p; 201 202 fprintf(stderr, "%s start\n", __FUNCTION__); 203 204 p = alloca(16); 205 strcpy(p,"12345678901234"); 206 printf("alloca: p is %s\n", p); 207 208 /* Test alloca embedded in a larger expression */ 209 printf("alloca: %s\n", strcpy(alloca(strlen(demo)+1),demo) ); 210 211 fprintf(stderr, "%s end\n", __FUNCTION__); 212 } 213 214 /* error */ 215 int test17() 216 { 217 char *demo = "This is only a test."; 218 char *p; 219 220 fprintf(stderr, "%s start\n", __FUNCTION__); 221 222 p = alloca(16); 223 strcpy(p,"12345678901234"); 224 printf("alloca: p is %s\n", p); 225 226 /* Test alloca embedded in a larger expression */ 227 printf("alloca: %s\n", strcpy(alloca(strlen(demo)),demo) ); 228 229 fprintf(stderr, "%s end\n", __FUNCTION__); 230 } 231 189 232 int (*table_test[])(void) = { 190 test1,191 233 test1, 192 234 test2, … … 204 246 test14, 205 247 test15, 248 test16, 249 test17, 206 250 }; 207 251 … … 210 254 int index; 211 255 int (*ftest)(void); 256 int index_max = sizeof(table_test)/sizeof(table_test[0]); 212 257 213 258 if (argc < 2) { 214 printf("usage: boundtest n\n" 215 "test TCC bound checking system\n" 216 ); 259 printf( 260 "test TCC bound checking system\n" 261 "usage: boundtest N\n" 262 " 1 <= N <= %d\n", index_max); 217 263 exit(1); 218 264 } … … 220 266 index = 0; 221 267 if (argc >= 2) 222 index = atoi(argv[1]); 268 index = atoi(argv[1]) - 1; 269 270 if ((index < 0) || (index >= index_max)) { 271 printf("N is outside of the valid range (%d)\n", index); 272 exit(2); 273 } 274 223 275 /* well, we also use bounds on this ! */ 224 276 ftest = table_test[index];
Note:
See TracChangeset
for help on using the changeset viewer.