void garbageCode33() { // #6613 ASSERT_THROW(checkCode("main(()B{});"), InternalError); checkCode("f::y:y : <x::"); checkCode("\xe2u."); }
void garbageCode35() { // ticket #2599 segmentation fault checkCode("sizeof"); // ticket #2604 segmentation fault checkCode("sizeof <= A"); }
void garbageAST() { checkCode("--"); // don't crash checkCode("N 1024 float a[N], b[N + 3], c[N]; void N; (void) i;\n" "int #define for (i = avx_test i < c[i]; i++)\n" "b[i + 3] = a[i] * {}"); // Don't hang (#5787) checkCode("START_SECTION([EXTRA](bool isValid(const String &filename)))"); // Don't crash (#5991) }
void wrong_syntax_if_macro() { // #2518 #4171 ASSERT_THROW(checkCode("void f() { if MACRO(); }"), InternalError); // #4668 - note there is no semicolon after MACRO() ASSERT_THROW(checkCode("void f() { if (x) MACRO() {} }"), InternalError); // #4810 - note there is no semicolon after MACRO() ASSERT_THROW(checkCode("void f() { if (x) MACRO() else ; }"), InternalError); }
void garbageCode8() { // #5604 ASSERT_THROW(checkCode("{ enum struct : };"), InternalError); ASSERT_THROW(checkCode("int ScopedEnum{ template<typename T> { { e = T::error }; };\n" "ScopedEnum1<int> se1; { enum class E : T { e = 0 = e ScopedEnum2<void*> struct UnscopedEnum3 { T{ e = 4 }; };\n" "arr[(int) E::e]; }; UnscopedEnum3<int> e2 = f()\n" "{ { e = e1; T::error } int test1 ue2; g() { enum class E { e = T::error }; return E::e; } int test2 = } \n" "namespace UnscopedEnum { template<typename T> struct UnscopedEnum1 { E{ e = T::error }; }; UnscopedEnum1<int> { enum E : { e = 0 }; };\n" "UnscopedEnum2<void*> ue3; template<typename T> struct UnscopedEnum3 { enum { }; }; int arr[E::e]; };\n" "UnscopedEnum3<int> namespace template<typename T> int f() { enum E { e }; T::error }; return (int) E(); } int test1 int g() { enum E { e = E };\n" "E::e; } int test2 = g<int>(); }"), InternalError); }
void garbageSymbolDatabase() { checkCode("void f( { u = 1 ; } ) { }"); checkCode("{ }; void namespace A::f; { g() { int } }"); ASSERT_THROW(checkCode("class Foo {}; class Bar : public Foo"), InternalError); checkCode("YY_DECL { switch (yy_act) {\n" " case 65: YY_BREAK\n" " case YY_STATE_EOF(block):\n" " yyterminate(); \n" "} }"); // #5663 }
void garbageCode22() { // Ticket #3480 - Don't crash garbage code ASSERT_THROW(checkCode("int f()\n" "{\n" " return if\n" "}"), InternalError); }
void FloatParameter::set(Component *comp,char c, const char *s){ checkCode(c); float v = atof(s); if(v<minVal || v>maxVal) throw SE_PARAMOUTOFRANGE; comp->paramVals[idx].d.f = v; }
bool CDMRTrellis::decode(const unsigned char* data, unsigned char* payload) { assert(data != NULL); assert(payload != NULL); signed char dibits[98U]; deinterleave(data, dibits); unsigned char points[49U]; dibitsToPoints(dibits, points); // Check the original code unsigned char tribits[49U]; unsigned int failPos = checkCode(points, tribits); if (failPos == 999U) { tribitsToBits(tribits, payload); return true; } unsigned char savePoints[49U]; for (unsigned int i = 0U; i < 49U; i++) savePoints[i] = points[i]; bool ret = fixCode(points, failPos, payload); if (ret) return true; if (failPos == 0U) return false; // Backtrack one place for a last go return fixCode(savePoints, failPos - 1U, payload); }
void EnumParameter::set(Component *comp,char c, const char *s){ checkCode(c); int v = atoi(s); if(v<0 || v>=count) throw SE_PARAMOUTOFRANGE; comp->paramVals[idx].d.i = v; }
// Bug #6626 crash: Token::astOperand2() const ( do while ) void garbageCode34() { checkCode("void foo(void) {\n" " do\n" " while (0);\n" "}"); ASSERT_EQUALS("", errout.str()); }
/* Compute an attractor previously allocated by newAttractor */ void computeAttractor (struct attractor *a, char *code) { struct timeval t1, t2; if (code == NULL || checkCode (code)) { explore (a); } else { strncpy (a->code, code, a->polynom->length * a->dimension + 3); applyCode (a->polynom, code); if (!isAttractorConverging (a)) fprintf (stderr, "Bad code - attractor not converging\n"); } a->polynom->sum = getPolynomSum (a->polynom); displayPolynom (a->polynom); fprintf (stdout, "Lyapunov exponent: %.6f\n", a->lyapunov->ly); gettimeofday (&t1, NULL); iterateMap (a); gettimeofday (&t2, NULL); diffTime ("Map iteration", &t1, &t2); a->r = getRadius (a); centerAttractor (a); computeDimension (a); fprintf (stdout, "Correlation dimension: %.6f\n", a->correlationDimension); fprintf (stdout, "Code: %s\n", a->code); }
void garbageCode28() { // 5702 checkCode("struct R1 {\n" " int a;\n" " R1 () : a { }\n" "};\n"); }
void EnvelopeParameter::set(Component *comp,char c, const char *s){ // the data is in the form l,t,l,t,...,l,t; // where l and t are level and time checkCode(c); Envelope &e = comp->paramVals[idx].d.env; const char *p = s; char buf[1024]; float arr[ENVSIZE*2]; int n=0; while(*s){ if(n==ENVSIZE*2)break; if(*s==',' || *s==';'){ bool ex=*s==';'; s++; strncpy(buf,p,s-p); buf[s-p]=0; arr[n++]=atof(buf); p=s; if(ex)break; } s++; } for(int i=n;i<ENVSIZE*2;i++)arr[i]=0; n=0; for(int i=0;i<ENVSIZE;i++){ e.times[i]=arr[n++]; e.levels[i]=arr[n++]; printf("Env %d: %f at time %f\n",i,e.levels[i],e.times[i]); } }
bool CDMRTrellis::fixCode(unsigned char* points, unsigned int failPos, unsigned char* payload) const { for (unsigned j = 0U; j < 20U; j++) { unsigned int bestPos = 0U; unsigned int bestVal = 0U; for (unsigned int i = 0U; i < 16U; i++) { points[failPos] = i; unsigned char tribits[49U]; unsigned int pos = checkCode(points, tribits); if (pos == 999U) { tribitsToBits(tribits, payload); return true; } if (pos > bestPos) { bestPos = pos; bestVal = i; } } points[failPos] = bestVal; failPos = bestPos; } return false; }
void garbageCode25() { // Ticket #2386 - Segmentation fault upon strange syntax ASSERT_THROW(checkCode("void f() {\n" " switch ( x ) {\n" " case struct Tree : break;\n" " }\n" "}"), InternalError); }
void garbageCode23() { //garbage code : don't crash (#3481) checkCode("{\n" " if (1) = x\n" " else abort s[2]\n" "}"); ASSERT_EQUALS("", errout.str()); }
void wrong_syntax1() { { const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))"; ASSERT_EQUALS("TR ( kvmpio , PROTO ( int rw ) , ARGS ( rw ) , TP_ ( aa . rw ; ) )", checkCode(code)); ASSERT_EQUALS("", errout.str()); } { const char code[] ="struct A { template<int> struct { }; };"; ASSERT_THROW(checkCode(code), InternalError); } { const char code[] ="enum ABC { A,B, typedef enum { C } };"; ASSERT_THROW(checkCode(code), InternalError); } }
int myhpss_statfs(const char *path, struct afs_statfs *buf) #endif { #ifdef FAKE_HPSS char myPath[HPSS_MAX_AFS_PATH_NAME]; char *p; sprintf(myPath, "%s", ourPath); p = strchr(&myPath[1], '/'); /* end at 2nd slash */ if (p) *p = 0; #if defined(AFS_HAVE_STATVFS) || defined(AFS_HAVE_STATVFS64) return statvfs(myPath, buf); #else return statfs(myPath, buf); #endif #else /* FAKE_HPSS */ int code, i; hpss_statfs_t hb; #if defined(AFS_HAVE_STATVFS) || defined(AFS_HAVE_STATVFS64) memset(buf, 0, sizeof(struct afs_statvfs)); #else memset(buf, 0, sizeof(struct afs_statfs)); #endif for (i=0; i<MAXCOS && info[i].cosId != 0; i++) { addHPSStransaction(); code = hpss_Statfs(info[i].cosId, &hb); removeHPSStransaction(); checkCode(code); if (!code) { #if defined(AFS_HAVE_STATVFS) || defined(AFS_HAVE_STATVFS64) if (buf->f_frsize && buf->f_frsize != hb.f_bsize) break; buf->f_frsize = hb.f_bsize; #else if (buf->f_bsize && buf->f_bsize != hb.f_bsize) break; buf->f_bsize = hb.f_bsize; #endif buf->f_blocks += hb.f_blocks; buf->f_bfree += hb.f_bfree; buf->f_files += hb.f_files; buf->f_ffree += hb.f_ffree; } if (!code && ((100 * hb.f_bfree)/hb.f_blocks) < 10) { /* Let caller see that this file system is nearly full */ buf->f_blocks = hb.f_blocks; buf->f_bfree = hb.f_bfree; buf->f_files = hb.f_files; buf->f_ffree = hb.f_ffree; break; } } if (code) return -1; return 0; #endif /* FAKE_HPSS */ }
void garbageCode26() { // See tickets #2518 #2555 #4171 ASSERT_THROW(checkCode("void f() {\n" " switch MAKEWORD(1)\n" " {\n" " case 0:\n" " return;\n" " }\n" "}"), InternalError); }
void garbageCode21() { // Ticket #3486 - Don't crash garbage code checkCode("void f()\n" "{\n" " (\n" " x;\n" " int a, a2, a2*x; if () ;\n" " )\n" "}"); }
void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n" "{\n" " (foo(s, , 2, , , 5, , 7)) abort()\n" "}\n"; checkCode(code); // #6106 code = " f { int i ; b2 , [ ] ( for ( i = 0 ; ; ) ) }"; checkCode(code); // 6122 survive garbage code code = "; { int i ; for ( i = 0 ; = 123 ; ) - ; }"; checkCode(code); code = "void f1() { for (int n = 0 n < 10 n++); }"; checkCode(code); }
ssize_t myhpss_Ftruncate(int fd, afs_foff_t pos) { afs_int32 code; int myfd = fd - FDOFFSET; code = hpss_Ftruncate(myfd, pos); checkCode(code); return code; }
void garbageCode24() { // don't crash (example from #6361) checkCode("float buffer[64];\n" "main (void)\n" "{\n" " char *cptr;\n" " cptr = (char *)buffer;\n" " cptr += (-(long int) buffer & (16 * sizeof (float) - 1));\n" "}\n"); }
void wrong_syntax2() { // #3504 const char code[] = "void f() {\n" " X<int> x;\n" " Y<int, int, int, int, int, char> y;\n" "}\n" "\n" "void G( template <typename T> class (j) ) {}"; // don't segfault.. checkCode(code); }
void BoolParameter::set(Component *comp,char c, const char *s){ checkCode(c); bool v; switch(*s){ case 'y':v=true;break; case 'n':v=false;break; default: throw SE_PARAMOUTOFRANGE; break; } comp->paramVals[idx].d.b = v; }
bool OnGossipSelectCode( Player *player, Creature *_Creature, uint32 sender, uint32 action, const char* sCode ) { if(sender == GOSSIP_SENDER_MAIN) { if(action == GOSSIP_ACTION_INFO_DEF+1) { checkCode(player, _Creature, sCode); player->CLOSE_GOSSIP_MENU(); return true; } } return false; }
int myhpss_Close(int fd) { afs_int32 code = 0; int myfd = fd - FDOFFSET; if (myfd >= 0) { code = hpss_Close(myfd); removeHPSStransaction(); } checkCode(code); return code; }
int myhpss_stat_tapecopies(const char *path, afs_int32 *level, afs_sfsize_t *size) { #ifndef AFS_AIX53_ENV afs_int32 code, i; int on_disk = 0; int on_tape = 0; afs_uint32 Flags = API_GET_STATS_FOR_ALL_LEVELS; afs_uint32 StorageLevel = 0; hpss_xfileattr_t AttrOut; bf_sc_attrib_t *scattr_ptr; bf_vv_attrib_t *vvattr_ptr; *size = 0; *level = 0; char myPath[HPSS_MAX_AFS_PATH_NAME]; if (path[0] == '/') /* absolute path */ sprintf(myPath, "%s", path); else sprintf(myPath, "%s/%s", ourPath, path); addHPSStransaction(); code = hpss_FileGetXAttributes(myPath, Flags, StorageLevel, &AttrOut); removeHPSStransaction(); checkCode(code); if (code) return EIO; for(i=0; i<HPSS_MAX_STORAGE_LEVELS; i++) { scattr_ptr = &AttrOut.SCAttrib[i]; if (scattr_ptr->Flags & BFS_BFATTRS_DATAEXISTS_AT_LEVEL) { if (scattr_ptr->Flags & BFS_BFATTRS_LEVEL_IS_DISK) { on_disk = 1; if (*size == 0) *size = scattr_ptr->BytesAtLevel; } if (scattr_ptr->Flags & BFS_BFATTRS_LEVEL_IS_TAPE) { on_tape = 1; *size = scattr_ptr->BytesAtLevel; } } } if (on_disk & on_tape) *level = 'p'; else if (on_tape) *level = 'm'; else *level = 'r'; #endif return 0; }
int myhpss_stat64(const char *path, struct stat64 *buf) { #ifdef FAKE_HPSS struct stat64 hs; #else hpss_stat_t hs; #endif int code; char myPath[HPSS_MAX_AFS_PATH_NAME]; if (path[0] == '/') /* absolute path */ sprintf(myPath, "%s", path); else sprintf(myPath, "%s/%s", ourPath, path); addHPSStransaction(); code = hpss_Stat(myPath, &hs); removeHPSStransaction(); checkCode(code); if (code) return code; #ifdef FAKE_HPSS memcpy(buf, &hs, sizeof(struct stat64)); #else /* FAKE_HPSS */ memset(buf, 0, sizeof(struct stat64)); buf->st_dev = hs.st_dev; #if !defined(_LP64) buf->st_ino = (((afs_int64)hs.st_ino.high) << 32) + hs.st_ino.low; #else buf->st_ino = hs.st_ino; #endif buf->st_nlink = hs.st_nlink; buf->st_mode = hs.st_mode; buf->st_uid = hs.st_uid; buf->st_gid = hs.st_gid; buf->st_rdev = hs.st_rdev; #if !defined(_LP64) buf->st_size = (((afs_int64)hs.st_size.high) << 32) + hs.st_size.low; #else buf->st_size = hs.st_size; #endif buf->st_blksize = hs.st_blksize; buf->st_blocks = hs.st_blocks; buf->st_atime = hs.hpss_st_atime; buf->st_mtime = hs.hpss_st_mtime; buf->st_ctime = hs.hpss_st_ctime; #endif /* FAKE_HPSS */ return 0; }