float revcst(float x[], float y[], int iorder[], int ncity, int n[]) { float xx[5],yy[5],de; int j,ii; n[3]=1 + ((n[1]+ncity-2) % ncity); n[4]=1 + (n[2] % ncity); for (j=1;j<=4;j++) { ii=iorder[n[j]]; xx[j]=x[ii]; yy[j]=y[ii]; } de = -ALEN(xx[1],xx[3],yy[1],yy[3]); de -= ALEN(xx[2],xx[4],yy[2],yy[4]); de += ALEN(xx[1],xx[4],yy[1],yy[4]); de += ALEN(xx[2],xx[3],yy[2],yy[3]); return de; }
int main(int argc, char* argv[]) { gid_t groups[1024]; int num_groups = getgroups(ALEN(groups), groups); int i; atomic_printf("User %d belongs to %d groups:\n ", geteuid(), num_groups); for (i = 0; i < num_groups; ++i) { atomic_printf("%d,", groups[i]); } atomic_puts(""); atomic_puts("EXIT-SUCCESS"); return 0; }
static int is_seccomp_bpf_available() { struct sock_filter noop[] = { ALLOW_PROCESS }; struct sock_fprog prog = { .len = (unsigned short)ALEN(noop), .filter = noop }; /* NB: if the SET_NO_NEW_PRIVS succeeds, it will prevent us * from doing things like recording setuid programs. Bad * thing? */ return (0 == prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) && 0 == prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)); } static void print_usage() { fputs( "Usage: rr (record|replay) [OPTION]... [ARG]...\n" "\n" "Syntax for `record'\n" " rr record [OPTION]... <exe> [exe-args]...\n" " -b, --force-syscall-buffer force the syscall buffer preload library\n" " to be used, even if that's probably a bad\n" " idea\n" " -c, --num-cpu-ticks=<NUM> maximum number of 'CPU ticks' (currently \n" " retired conditional branches) to allow a \n" " task to run before interrupting it\n" " -e, --num-events=<NUM> maximum number of events (syscall \n" " enter/exit, signal, CPU interrupt, ...) \n" " to allow a task before descheduling it\n" " -n, --no-syscall-buffer disable the syscall buffer preload library\n" " even if it would otherwise be used" "\n" "Syntax for `replay'\n" " rr replay [OPTION]... <trace-dir>\n" " -a, --autopilot replay without debugger server\n" " -c, --checksum={on-syscalls,on-all-events}|FROM_TIME\n" " verify checksums either on all syscalls, all\n" " events, or starting from global timepoint\n" " FROM_TIME\n" " -d, --dump-on=<SYSCALL_NUM|-SIGNAL_NUM>\n" " dump memory at SYSCALL or SIGNAL during replay\n" " -p, --dbgport=PORT bind the debugger server to PORT\n" " -q, --no-redirect-output don't replay writes to stdout/stderr\n" " -t, --dump-at=TIME dump memory at global timepoint TIME\n" , stderr); }
int main(void) { gid_t groups[32]; int ngroups; gid_t this_group, other_group; int fd; this_group = getegid(); atomic_printf("Current group is %d\n", this_group); ngroups = getgroups(ALEN(groups), groups); test_assert(ngroups > 0); other_group = groups[0]; if (this_group == other_group && ngroups > 1) { other_group = groups[1]; } if (this_group == other_group) { atomic_puts("WARNING: unable to properly test chown()"); } fd = creat(DUMMY_FILENAME, 0600); test_assert(fd >= 0); atomic_printf("Group owner of %s is %d\n", DUMMY_FILENAME, get_gid(fd)); test_assert(this_group == get_gid(fd)); change_group(DUMMY_FILENAME, other_group); atomic_printf(" ... now owner is %d\n", get_gid(fd)); test_assert(other_group == get_gid(fd)); change_group_fd(fd, this_group); atomic_printf(" ... now back to original owner %d\n", get_gid(fd)); test_assert(this_group == get_gid(fd)); change_group_at(DUMMY_FILENAME, other_group); atomic_printf(" ... now owner is %d\n", get_gid(fd)); test_assert(other_group == get_gid(fd)); unlink(DUMMY_FILENAME); atomic_puts("EXIT-SUCCESS"); return 0; }
static int eval(int token, int prec, int *res, int *err, yystypepp * yylvalpp) { int i, val; Symbol *s; if (token == CPP_IDENTIFIER) { if (yylvalpp->sc_ident == definedAtom) { int needclose = 0; token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (token == '(') { needclose = 1; token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); } if (token != CPP_IDENTIFIER) goto error; *res = (s = LookUpSymbol(macros, yylvalpp->sc_ident)) ? !s->details.mac.undef : 0; token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (needclose) { if (token != ')') goto error; token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); } } else if (MacroExpand(yylvalpp->sc_ident, yylvalpp)) { token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); return eval(token, prec, res, err, yylvalpp); } else { goto error; } } else if (token == CPP_INTCONSTANT) { *res = yylvalpp->sc_int; token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); } else if (token == '(') { token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); token = eval(token, MIN_PREC, res, err, yylvalpp); if (!*err) { if (token != ')') goto error; token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); } } else { for (i = ALEN(unop) - 1; i >= 0; i--) { if (unop[i].token == token) break; } if (i >= 0) { token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); token = eval(token, UNARY, res, err, yylvalpp); *res = unop[i].op(*res); } else { goto error; } } while (!*err) { if (token == ')' || token == '\n') break; for (i = ALEN(binop) - 1; i >= 0; i--) { if (binop[i].token == token) break; } if (i < 0 || binop[i].prec <= prec) break; val = *res; token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); token = eval(token, binop[i].prec, res, err, yylvalpp); if (binop[i].op == op_div || binop[i].op == op_mod) { if (*res == 0) { CPPErrorToInfoLog("preprocessor divide or modulo by zero"); *err = 1; return token; } } *res = binop[i].op(val, *res); } return token; error: CPPErrorToInfoLog("incorrect preprocessor directive"); *err = 1; *res = 0; return token; } // eval
void anneal(float x[], float y[], int iorder[], int ncity) { int irbit1(unsigned long *iseed); int metrop(float de, float t); float ran3(long *idum); float revcst(float x[], float y[], int iorder[], int ncity, int n[]); void reverse(int iorder[], int ncity, int n[]); float trncst(float x[], float y[], int iorder[], int ncity, int n[]); void trnspt(int iorder[], int ncity, int n[]); int ans,nover,nlimit,i1,i2; int i,j,k,nsucc,nn,idec; static int n[7]; long idum; unsigned long iseed; float path,de,t; nover=100*ncity; nlimit=10*ncity; path=0.0; t=0.5; for (i=1;i<ncity;i++) { i1=iorder[i]; i2=iorder[i+1]; path += ALEN(x[i1],x[i2],y[i1],y[i2]); } i1=iorder[ncity]; i2=iorder[1]; path += ALEN(x[i1],x[i2],y[i1],y[i2]); idum = -1; iseed=111; for (j=1;j<=100;j++) { nsucc=0; for (k=1;k<=nover;k++) { do { n[1]=1+(int) (ncity*ran3(&idum)); n[2]=1+(int) ((ncity-1)*ran3(&idum)); if (n[2] >= n[1]) ++n[2]; nn=1+((n[1]-n[2]+ncity-1) % ncity); } while (nn<3); idec=irbit1(&iseed); if (idec == 0) { n[3]=n[2]+(int) (abs(nn-2)*ran3(&idum))+1; n[3]=1+((n[3]-1) % ncity); de=trncst(x,y,iorder,ncity,n); ans=metrop(de,t); if (ans) { ++nsucc; path += de; trnspt(iorder,ncity,n); } } else { de=revcst(x,y,iorder,ncity,n); ans=metrop(de,t); if (ans) { ++nsucc; path += de; reverse(iorder,ncity,n); } } if (nsucc >= nlimit) break; } printf("\n %s %10.6f %s %12.6f \n","T =",t, " Path Length =",path); printf("Successful Moves: %6d\n",nsucc); t *= TFACTR; if (nsucc == 0) return; } }
int TPpContext::eval(int token, int prec, int *res, int *err, TPpToken * yylvalpp) { int i, val; Symbol *s; if (token == CPP_IDENTIFIER) { if (yylvalpp->atom == definedAtom) { bool needclose = 0; token = currentInput->scan(this, currentInput, yylvalpp); if (token == '(') { needclose = true; token = currentInput->scan(this, currentInput, yylvalpp); } if (token != CPP_IDENTIFIER) { parseContext.error(yylvalpp->loc, "incorrect directive, expected identifier", "preprocessor", ""); *err = 1; *res = 0; return token; } *res = (s = LookUpSymbol(macros, yylvalpp->atom)) ? !s->details.mac.undef : 0; token = currentInput->scan(this, currentInput, yylvalpp); if (needclose) { if (token != ')') { parseContext.error(yylvalpp->loc, "#else after #else", "", ""); *err = 1; *res = 0; return token; } token = currentInput->scan(this, currentInput, yylvalpp); } } else { int macroReturn = MacroExpand(yylvalpp->atom, yylvalpp, 1); if (macroReturn == 0) { parseContext.error(yylvalpp->loc, "can't evaluate expression", "preprocessor", ""); *err = 1; *res = 0; return token; } else { if (macroReturn == -1) { if (parseContext.profile == EEsProfile) { if (parseContext.messages & EShMsgRelaxedErrors) parseContext.warn(yylvalpp->loc, "undefined macro in expression not allowed in es profile", "preprocessor", ""); else { parseContext.error(yylvalpp->loc, "undefined macro in expression", "preprocessor", ""); *err = 1; } } } token = currentInput->scan(this, currentInput, yylvalpp); return eval(token, prec, res, err, yylvalpp); } } } else if (token == CPP_INTCONSTANT) { *res = yylvalpp->ival; token = currentInput->scan(this, currentInput, yylvalpp); } else if (token == '(') { token = currentInput->scan(this, currentInput, yylvalpp); token = eval(token, MIN_PREC, res, err, yylvalpp); if (!*err) { if (token != ')') { parseContext.error(yylvalpp->loc, "expected ')'", "preprocessor", ""); *err = 1; *res = 0; return token; } token = currentInput->scan(this, currentInput, yylvalpp); } } else { for (i = ALEN(unop) - 1; i >= 0; i--) { if (unop[i].token == token) break; } if (i >= 0) { token = currentInput->scan(this, currentInput, yylvalpp); token = eval(token, UNARY, res, err, yylvalpp); *res = unop[i].op(*res); } else { parseContext.error(yylvalpp->loc, "", "bad expression", ""); *err = 1; *res = 0; return token; } } while (!*err) { if (token == ')' || token == '\n') break; for (i = ALEN(binop) - 1; i >= 0; i--) { if (binop[i].token == token) break; } if (i < 0 || binop[i].prec <= prec) break; val = *res; token = currentInput->scan(this, currentInput, yylvalpp); token = eval(token, binop[i].prec, res, err, yylvalpp); *res = binop[i].op(val, *res); } return token; } // eval
void lieske_e2x3_init(void) { /* code */ assert(ALEN(sat_i_long_ampl) == ALEN(sat_i_long_params)); assert(ALEN(sat_ii_long_ampl) == ALEN(sat_ii_long_params)); assert(ALEN(sat_iii_long_ampl) == ALEN(sat_iii_long_params)); assert(ALEN(sat_iv_long_ampl) == ALEN(sat_iv_long_params)); assert(ALEN(sat_i_lat_ampl) == ALEN(sat_i_lat_params)); assert(ALEN(sat_ii_lat_ampl) == ALEN(sat_ii_lat_params)); assert(ALEN(sat_iii_lat_ampl) == ALEN(sat_iii_lat_params)); assert(ALEN(sat_iv_lat_ampl) == ALEN(sat_iv_lat_params)); assert(ALEN(sat_i_rad_ampl) == ALEN(sat_i_rad_params)); assert(ALEN(sat_ii_rad_ampl) == ALEN(sat_ii_rad_params)); assert(ALEN(sat_iii_rad_ampl) == ALEN(sat_iii_rad_params)); assert(ALEN(sat_iv_rad_ampl) == ALEN(sat_iv_rad_params)); cm_register_orbital_model(&lieske_model); }
}; #define ALEN(a) sizeof(a)/sizeof(typeof(a[0])) typedef struct { int n_long_terms; int n_lat_terms; int n_rad_terms; const sat_amps_t *amps; const sat_args_t *args; double longitude; double mean_dist; } sat_t; sat_t sats[] = { {.n_long_terms = ALEN(sat_i_long_ampl), .n_lat_terms = ALEN(sat_i_lat_ampl), .n_rad_terms = ALEN(sat_i_rad_ampl), .amps = &sat_i_amps, .args = &sat_i_params, .mean_dist = 5.90730}, {.n_long_terms = ALEN(sat_ii_long_ampl), .n_lat_terms = ALEN(sat_ii_lat_ampl), .n_rad_terms = ALEN(sat_ii_rad_ampl), .amps = &sat_ii_amps, .args = &sat_ii_params, .mean_dist = 9.39912}, {.n_long_terms = ALEN(sat_iii_long_ampl), .n_lat_terms = ALEN(sat_iii_lat_ampl), .n_rad_terms = ALEN(sat_iii_rad_ampl), .amps = &sat_iii_amps, .args = &sat_iii_params, .mean_dist = 14.99240}, {.n_long_terms = ALEN(sat_iv_long_ampl), .n_lat_terms = ALEN(sat_iv_lat_ampl),
int tr_httpRequestType( const char * data, int len, char ** method, char ** uri ) { const char * words[6]; int ii, ret; const char * end; /* find the end of the line */ for( end = data; data + len > end; end++ ) { if( NL( *data) ) { break; } } /* find the first three "words" in the line */ for( ii = 0; ALEN( words ) > ii && data < end; ii++ ) { /* find the next space or non-space */ while( data < end && ( ii % 2 ? !SP( *data ) : SP( *data ) ) ) { data++; } /* save the beginning of the word */ words[ii] = data; } /* check for missing words */ if( ALEN( words) > ii ) { return -1; } /* parse HTTP version */ ret = -1; if( 8 <= words[5] - words[4] ) { if( 0 == tr_strncasecmp( words[4], "HTTP/1.1", 8 ) ) { ret = 11; } else if( 0 == tr_strncasecmp( words[4], "HTTP/1.0", 8 ) ) { ret = 10; } } /* copy the method */ if( 0 <= ret && NULL != method ) { *method = tr_dupstr( words[0], words[1] - words[0] ); if( NULL == *method ) { ret = -1; } } /* copy uri */ if( 0 <= ret && NULL != uri ) { *uri = tr_dupstr( words[2], words[3] - words[2] ); if( NULL == *uri ) { free( *method ); ret = -1; } } return ret; }