static void push(const double value){ if( stack == 0 ){ bailout("push Stack is not initialized"); } if( stack_isfull() == TRUE ){ bailout("push Stack is full"); } stack->esp[stack->actsize] = value; stack->actsize++; }
static double pop(void){ if( stack == 0 ){ bailout("pop Stack is not initialized"); } if( stack_isempty() == TRUE ){ bailout("pop Stack is empty"); } stack->actsize--; return stack->esp[stack->actsize]; }
void valueFlowBeforeConditionTernaryOp() { // bailout: ?: const char *code; bailout("void f(int x) {\n" " y = ((x<0) ? x : ((x==2)?3:4));\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: no simplification of x within ?: expression\n", errout.str()); bailout("int f(int x) {\n" " int r = x ? 1 / x : 0;\n" " if (x == 0) {}\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: no simplification of x within ?: expression\n", errout.str()); code = "void f(int x) {\n" " int a =v x;\n" " a = b ? x/2 : 20/x;\n" " if (x == 123) {}\n" "}"; ASSERT_EQUALS(true, testValueOfX(code, 2U, 123)); code = "void f(int x, int y) {\n" " a = x;\n" " if (y){}\n" " if (x==123){}\n" "}"; ASSERT_EQUALS(true, testValueOfX(code, 2U, 123)); }
void valueFlowBeforeConditionGoto() { // bailout: goto label (TODO: handle gotos more intelligently) bailout("void f(int x) {\n" " if (x == 123) { goto out; }\n" " a=x;\n" // <- x is not 123 "out:" " if (x==123){}\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (debug) ValueFlow bailout: variable x stopping on goto label\n" "[test.cpp:2]: (debug) ValueFlow bailout: variable x. noreturn conditional scope.\n" , errout.str()); // #5721 - FP bailout("static void f(int rc) {\n" " ABC* abc = getabc();\n" " if (!abc) { goto out };\n" "\n" " abc->majortype = 0;\n" " if (FAILED(rc)) {}\n" "\n" "out:\n" " if (abc) {}\n" "}\n"); ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: assignment of abc\n" "[test.cpp:8]: (debug) ValueFlow bailout: variable abc stopping on goto label\n" "[test.cpp:3]: (debug) ValueFlow bailout: variable abc. noreturn conditional scope.\n", errout.str()); }
static struct rotation decode_rotation(const struct http_vars *vars, unsigned int num_seats) { struct rotation rot; unsigned int i; rot.size = num_seats; for (i = 0; i < rot.size; i++) { char varname[strlen("rotation") + sizeof(STRINGIZE(MAX_ELECTORATE_SEATS))]; const char *val; sprintf(varname, "rotation%u", i); val = http_string(vars, varname); rot.rotations[i] = atoi(val); } /* Do sanity checks on input: must be all numbers up to rot.size */ for (i = 0; i < rot.size; i++) { unsigned int j; if (rot.rotations[i] >= rot.size) bailout("Bad rotation #%u: %u\n", i, rot.rotations[i]); for (j = 0; j < rot.size; j++) { if (j != i && rot.rotations[j] == rot.rotations[i]) bailout("Rotations %u & %u == %u\n", j, i, rot.rotations[i]); } } return rot; }
char * check_node(void) { char *buf; int sock, i; struct sockaddr_in name; struct hostent *hostinfo; /* create socket */ sock = socket(PF_INET, SOCK_STREAM, 0); if (sock < 0) bailout(); name.sin_family = AF_INET; name.sin_port = htons(oportnum); hostinfo = gethostbyname(jsd_host); if (hostinfo == NULL) { (void)fprintf(stderr, "Unknown host %s.\n", jsd_host); exit(EXIT_FAILURE); } name.sin_addr = *(struct in_addr *)hostinfo->h_addr; if (connect(sock, (struct sockaddr *)&name, sizeof(name)) < 0) bailout(); i = read_from_client(sock, &buf); /* get a node */ buf[i] = '\0'; if (debug) printf("Got node %s\n", buf); (void)close(sock); return(buf); }
void output_spectrum_record( struct timeval *tv) { int i; char *stamp = NULL, *prefix = NULL; if( !substitute_params( &prefix, tv, CF_output_files, NULL)) bailout( "error in output_files configuration"); if( bound_strcmp( prefix, out_prefix)) { char *filename = NULL; if( out_prefix) free( out_prefix); out_prefix = strdup( prefix); append_sprintf( &filename, "%s/%s", CF_datadir, out_prefix); report( 0, "using output file [%s]", filename); if( sf_fo) fclose( sf_fo); if( (sf_fo = fopen( filename, "a+")) == NULL) bailout( "cannot open [%s], %s", filename, strerror( errno)); if( CF_output_header) { // Header record required. Output a header every time sidc // is started - only way to handle band changes etc struct stat st; if( stat( filename, &st) < 0) bailout( "cannot stat output file %s: %s", filename, strerror( errno)); fputs( "# FREQ ", sf_fo); for( i = cuton; i < cutoff; i++) fprintf( sf_fo, "%.2f ", (i+0.5) * DF); fputs( "\n", sf_fo); } free( filename); } substitute_params( &stamp, tv, CF_timestamp, NULL); fprintf( sf_fo, "%s", stamp); for( i=cuton; i<cutoff; i++) { double e = left.powspec[i]/output_int; if( CF_log_scale) e = CF_offset_db + 10 * log10( e + 1e-9); fputs( " ", sf_fo); fprintf( sf_fo, CF_field_format, e); } fputs( "\n", sf_fo); fflush( sf_fo); free( prefix); free( stamp); }
static void valueFlowForLoopSimplify(Token * const bodyStart, const unsigned int varid, const MathLib::bigint value, TokenList *tokenlist, ErrorLogger *errorLogger, const Settings *settings) { const Token * const bodyEnd = bodyStart->link(); // Is variable modified inside for loop if (isVariableChanged(bodyStart, bodyEnd, varid)) return; for (Token *tok2 = bodyStart->next(); tok2 != bodyEnd; tok2 = tok2->next()) { if (tok2->varId() == varid) { const Token * parent = tok2->astParent(); while (parent) { const Token * const p = parent; parent = parent->astParent(); if (parent && parent->str() == ":") break; if (parent && parent->str() == "?") { if (parent->astOperand2() != p) parent = NULL; break; } } if (parent) { if (settings->debugwarnings) bailout(tokenlist, errorLogger, tok2, "For loop variable " + tok2->str() + " stopping on ?"); continue; } ValueFlow::Value value1(value); value1.varId = tok2->varId(); setTokenValue(tok2, value1); } else if (Token::simpleMatch(tok2, ") {") && Token::findmatch(tok2->link(), "%varid%", tok2, varid)) { if (Token::findmatch(tok2, "continue|break|return", tok2->linkAt(1), varid)) { if (settings->debugwarnings) bailout(tokenlist, errorLogger, tok2, "For loop variable bailout on conditional continue|break|return"); break; } if (settings->debugwarnings) bailout(tokenlist, errorLogger, tok2, "For loop variable skipping conditional scope"); tok2 = tok2->next()->link(); if (Token::simpleMatch(tok2, "} else {")) { if (Token::findmatch(tok2, "continue|break|return", tok2->linkAt(2), varid)) { if (settings->debugwarnings) bailout(tokenlist, errorLogger, tok2, "For loop variable bailout on conditional continue|break|return"); break; } tok2 = tok2->linkAt(2); } } } }
/************************************ Function definitions ***********************************/ static double calculate(char* calculation){ double operand1 = 0.0; double operand2 = 0.0; double result = 0.0; char* hline = calculation; char* endptr = (char*) 0; while( (*hline != '\n') && (*hline != EOF)){ operation = 0; operand1 = strtod(hline, &endptr); errno = 0; if( operand1 == HUGE_VAL && errno != 0 ){ bailout("calculate The given value causes an over- or underflow"); } if( operand1 == 0 && hline == endptr ){ /* * check for space is needed because endptr stops one char before operator * the loop is for ignoring all whitespaces in front of the operator */ while( *endptr == ' ' || *endptr == '\t' ){endptr++;} /* if there were closing whitespaces after last operand there shouldnt be * a wrong operation error, so this if statement breaks the loop */ if( *endptr == '\n' || *endptr == EOF ){ break; } switch(*endptr){ case '+': operation = &add;break; case '-': operation = ⊂ break; case '*': operation = &mul; break; case '/': operation = ÷ break; case 's': operand1 = pop(); push(sin(operand1)); break; case 'c': operand1 = pop(); push(cos(operand1)); break; default: bailout("Not a valid operation"); } if( operation != 0 ){ operand2 = pop(); operand1 = pop(); /*operation is assigned with one of the binary arithmetic operations*/ push(operation(operand1, operand2)); } /* moves pointer from operation sign */ endptr++; }else{ push(operand1); } hline = endptr; } if( stack->actsize > 1 ){ bailout("calculate Too many items on the stack"); } result = pop(); return result; }
/* Appends formatted string to *d while extending allocation */ int append_sprintf( char **d, char *format, ...) { int len; int ret; char *tgt; va_list ap, ap2; va_copy( ap2, ap); va_start( ap, format); len = vsnprintf( NULL, 0, format, ap) + 1; va_end( ap); if (*d) { *d = realloc( *d, strlen( *d) + len); tgt = *d + strlen( *d); } else { tgt = *d = malloc( len); } if (!*d) bailout( "could not allocate memory, %s", strerror( errno)); va_start( ap2, format); ret = vsprintf( tgt, format, ap2); va_end( ap); return ret; }
/* DDS????: Get Ballot Contents */ static struct http_vars *get_ballot_contents(PGconn *conn,unsigned int ecode, struct http_vars *vars) { PGresult *result; unsigned int num_groups,group; result = SQL_query(conn, "SELECT party_index,count(index) FROM candidate " "WHERE electorate_code = %u " "GROUP BY party_index;",ecode); if ( (num_groups = PQntuples(result)) == 0 ) bailout("get_ballot_contents failed. " "No groups found for this electorate.\n"); vars = realloc(vars, sizeof(*vars) * (3 + 1 + num_groups + 1)); vars[3].name = strdup("num_groups"); vars[3].value = sprintf_malloc("%u", num_groups); for (group=0;group<num_groups;group++) { vars[group+4].name = sprintf_malloc("group%s",PQgetvalue( result,group,0)); vars[group+4].value = strdup(PQgetvalue(result,group,1)); } vars[group+4].name = vars[group+4].value = NULL; PQclear(result); return vars; }
void _free_safe(void *ptr,const char *file,unsigned int line) /* Free the memory pointed to by ptr. Remove ptr from allocated list if found. If it is not in the allocated list, then bail! */ { struct allocated **mem_ptr; /* Find the pointer in the allocated memory list */ for (mem_ptr=&head_ptr; *mem_ptr; mem_ptr=&(*mem_ptr)->next) if ((*mem_ptr)->ptr == ptr) { struct allocated *delete = *mem_ptr; /* unlink from the list */ *mem_ptr = (*mem_ptr)->next; free(delete); /* Free list item */ free(ptr); /* and the memory it pointed to */ return; } /* If we got here then the ptr was not found in the list - bail! */ bailout("free_safe failed.\n" "Not found in allocated list. (%s at line %u)\n",file,line); }
void valueFlowBeforeConditionIfElse() { // bailout: if/else/etc const char *code; code = "void f(X * x) {\n" " a = x;\n" " if ((x != NULL) &&\n" " (a(x->name, html)) &&\n" " (a(x->name, body))) {}\n" " if (x != NULL) { }\n" "}"; ASSERT_EQUALS(true, testValueOfX(code, 2U, 0)); ASSERT_EQUALS(true, testValueOfX(code, 3U, 0)); ASSERT_EQUALS(false, testValueOfX(code, 4U, 0)); ASSERT_EQUALS(false, testValueOfX(code, 5U, 0)); bailout("void f(int x) {\n" " if (x != 123) { b = x; }\n" " if (x == 123) {}\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: variable x stopping on }\n", errout.str()); code = "void f(int x) {\n" " a = x;\n" " if (abc) { x = 1; }\n" // <- condition must be false if x is 7 in next line " if (x == 7) { }\n" "}"; ASSERT_EQUALS(true, testValueOfX(code, 2U, 7)); }
int Compilation::compile_java_method() { assert(!method()->is_native(), "should not reach here"); if (BailoutOnExceptionHandlers) { if (method()->has_exception_handlers()) { bailout("linear scan can't handle exception handlers"); } } CHECK_BAILOUT_(no_frame_size); { PhaseTraceTime timeit(_t_buildIR); build_hir(); } if (BailoutAfterHIR) { BAILOUT_("Bailing out because of -XX:+BailoutAfterHIR", no_frame_size); } { PhaseTraceTime timeit(_t_emit_lir); _frame_map = new FrameMap(method(), hir()->number_of_locks(), MAX2(4, hir()->max_stack())); emit_lir(); } CHECK_BAILOUT_(no_frame_size); { PhaseTraceTime timeit(_t_codeemit); return emit_code_body(); } }
void Compilation::emit_lir() { CHECK_BAILOUT(); LIRGenerator gen(this, method()); { PhaseTraceTime timeit(_t_lirGeneration); hir()->iterate_linear_scan_order(&gen); } CHECK_BAILOUT(); { PhaseTraceTime timeit(_t_linearScan); LinearScan* allocator = new LinearScan(hir(), &gen, frame_map()); set_allocator(allocator); // Assign physical registers to LIR operands using a linear scan algorithm. allocator->do_linear_scan(); CHECK_BAILOUT(); _max_spills = allocator->max_spills(); } if (BailoutAfterLIR) { if (PrintLIR && !bailed_out()) { print_LIR(hir()->code()); } bailout("Bailing out because of -XX:+BailoutAfterLIR"); } }
int main(int argc, char **argv) { int fd, i, n; unsigned char vvv[256], * scout; int rs232_fd; struct termios ios; /* Create the socket */ rs232_fd = open("/dev/ttyUSB1", O_WRONLY); if(rs232_fd < 0) bailout("socket"); memset(&ios, 0, sizeof(ios)); ios.c_cflag=B115200|CLOCAL|CREAD|CS8; ios.c_cc[VMIN]=1; tcsetattr(rs232_fd, TCSANOW, &ios); for(i = 0; i < 256; i++) vvv[i] = i; i = 0; for(;;){ if((n = write(rs232_fd, (vvv + i), 1)) > 0) fprintf(stderr, "%02x ", *(vvv + i)); i++; if(i == 100){ // usleep(500); i = 0; } } close(rs232_fd); }
void valueFlowBeforeConditionAssignIncDec() { // assignment / increment const char *code; code = "void f(int x) {\n" " x = 2 + x;\n" " if (x == 65);\n" "}"; ASSERT_EQUALS(false, testValueOfX(code, 2U, 65)); code = "void f(int x) {\n" " x = y = 2 + x;\n" " if (x == 65);\n" "}"; ASSERT_EQUALS(false, testValueOfX(code, 2U, 65)); code = "void f(int x) {\n" " a[x++] = 0;\n" " if (x == 5);\n" "}"; ASSERT_EQUALS(false, testValueOfX(code, 2U, 5)); code = "void f(int x) {\n" " a = x;\n" " x++;\n" " if (x == 4);\n" "}"; ASSERT_EQUALS(true, testValueOfX(code, 2U, 3)); // bailout: assignment bailout("void f(int x) {\n" " x = y;\n" " if (x == 123) {}\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: assignment of x\n", errout.str()); }
void valueFlowBeforeConditionMacro() { // bailout: condition is a expanded macro bailout("void f(int x) {\n" " a = x;\n" " $if ($x==$123){}\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x, condition is defined in macro\n", errout.str()); }
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * function : syminsertLexem * description : inserts the given lexem (string) at the head of the * list of symentries of the given symtab and passes * back a ptr to the new entry via entryptr * returns : OK, ERROR * input : symbol table, lexem, ptr in which to store a ptr to * new symentry * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ int syminsertLexem(symtab *sym, char *lexem, symentry **entryptr) { symentry *tmpptr = NULL; /* ptr to new symtab entry */ /* sanity check: check if sym == NULL */ if (sym == NULL) { bailout("syminsertLexem: sym == NULL"); } sym->lastid++; /* we need a new higher id value */ /* reserve some space for new symbol table entry */ tmpptr = my_malloc(sizeof(symentry)); if (tmpptr == NULL) { bailout("syminsertLexem: could not malloc"); } /* initialize new symbol table entry with reasonable values */ tmpptr->id = sym->lastid; tmpptr->declared = FALSE; tmpptr->type = symtype_unknown; tmpptr->lexemptr = NULL; tmpptr->nextptr = NULL; /* reserve some space for tmpptr->lexemptr */ tmpptr->lexemptr = my_malloc((size_t)(strlen(lexem) + 1)); /* lexem + '\0' */ if (tmpptr->lexemptr == NULL) { bailout("syminsertLexem: could not malloc"); } /* copy lexem into tmpptr->lexemptr */ strcpy(tmpptr->lexemptr, lexem); /* now we are ready to insert the new symtab entry into the symtab list. Here we simply insert it into the head of the list. */ if (sym->symstart == NULL) { sym->symstart = tmpptr; } else { tmpptr->nextptr = sym->symstart; sym->symstart = tmpptr; } *entryptr = tmpptr; return OK; }
void setup_hamming_window( void) { int i; if( (hamwin = malloc( sizeof( double) * FFTWID)) == NULL) bailout( "not enough memory for hamming window"); for( i=0; i<FFTWID; i++) hamwin[i] = sin( i * M_PI/FFTWID); }
void config_band( char *ident, char *start, char *end, char *side) { struct BAND *b = bands + nbands++; if( nbands == MAXBANDS) bailout( "too many bands specified in config file"); b->ident = strdup( ident); b->start = atoi( start); b->end = atoi( end); if( !strcasecmp( side, "left")) b->side = &left; else if( !strcasecmp( side, "right")) b->side = &right; else bailout( "must specify left or right side for band %s", ident); b->fo = NULL; }
void valueFlowBeforeConditionGoto() { // bailout: goto label (TODO: handle gotos more intelligently) bailout("void f(int x) {\n" " if (x == 123) { goto out; }\n" " a=x;\n" // <- x is not 123 "out:" " if (x==123){}\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x stopping on goto label\n", errout.str()); }
/* ** Name: int pencode(char *s); ** Function: Decode a symbolic name (facility/priority) ** to a numeric value. */ int pencode(char *s) { char *save; int fac, lev; for (save = s; *s && *s != '.'; ++s); if (*s) { *s = '\0'; fac = decode(save, FacNames); if (fac < 0) bailout("unknown facility name:", save); *s++ = '.'; } else { fac = 0; s = save; } lev = decode(s, PriNames); if (lev < 0) bailout("unknown priority name:", save); return((lev & LOG_PRIMASK) | (fac & LOG_FACMASK)); }
void valueFlowBeforeConditionSwitch() { // bailout: switch // TODO : handle switch/goto more intelligently bailout("void f(int x, int y) {\n" " switch (y) {\n" " case 1: a=x; break;\n" " case 2: if (x==5) {} break;\n" " };\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x stopping on break\n", errout.str()); bailout("void f(int x, int y) {\n" " switch (y) {\n" " case 1: a=x; return 1;\n" " case 2: if (x==5) {} break;\n" " };\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x stopping on return\n", errout.str()); }
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * function : syminit * description : initializes the given symbol table * returns : OK, ERROR * input : symbol table * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ int syminit(symtab *sym) { /* sanity check: check if sym == NULL */ if (sym == NULL) { bailout("syminit: sym == NULL"); } sym->symstart = NULL; return OK; }
// -------------------------------------------------------------------------- // send a message periodically void Client::timerEvent(QTimerEvent* event) { static int i = 0; static const char* messages[] = {"Hello", "Nice to meet you", "good bye"}; const int msg_count = sizeof messages / sizeof messages[0]; if (event->timerId() != m_timerId) { // spurious? return; } if (!m_sock) { emit bailout(); } else if (i < msg_count) { QByteArray message; message.append(QString("%1\n").arg(messages[i])); m_sock->write(message); ++i; } #if 0 // this is not necessary. else if (msg_count == i) { QByteArray message; message.append("bye\n"); m_sock->write(message); ++i; } #endif else { killTimer(m_timerId); m_sock->disconnectFromHost(); m_sock->close(); m_sock->deleteLater(); //QCoreApplication* parent = dynamic_cast<QCoreApplication* > (this->parent()); //if (parent) parent->quit(); emit bailout(); } }
int _closedir_safe(DIR *dir,const char *file,unsigned int line) /* Close the directory. Bailout on failure. */ { int ret; if ((ret = closedir(dir)) != 0) bailout("Cannot close directory \n%s (%s at line %u)\n",strerror(errno),file,line); return(ret); }
void make_daemon( void) { int childpid, fd; pid_t sid; long open_max = OPEN_MAX; if( (childpid = fork()) < 0) bailout( "cannot fork: %s", strerror( errno)); else if( childpid > 0) exit( 0); umask(022); sid = setsid(); if( sid < 0) bailout("cannot get unique sid"); if( chdir("/") < 0) bailout("cannot change working dir"); #ifdef TIOCNOTTY if( (fd = open( "/dev/tty", O_RDWR)) >= 0) { ioctl( fd, TIOCNOTTY, 0); close( fd); } #endif /* TIOCNOTTY */ if( (childpid = fork()) < 0) bailout( "cannot fork: %s", strerror( errno)); else if( childpid > 0) exit( 0); for( fd = 0; fd < open_max; fd++) close( fd); background = 2; FILE *fp; if (( fp = fopen(pid_file, "w")) != NULL) { fprintf(fp, "%ld\n", (long)getpid()); fclose(fp); } else { report( 0, "PID file %s not writable (permissions?), skipping", pid_file); } }
int _close_safe(int fd,const char *file,unsigned int line) /* Try to close file. Bailout on error. */ { int ret; if ((ret = close(fd)) != 0) bailout("Close failed on file.\n%s (%s at line %u)\n", strerror(errno),file,line); return(ret); }
static void free_ressources(void){ if(src_file != (FILE *) 0){ if( fclose(src_file) == EOF ){ src_file = (FILE *) 0; bailout("free_ressources Cannot close file stream"); } src_file = (FILE *) 0; } if( stack != (Stack *) 0 ){ destroy_stack(); } }