type
stringclasses
5 values
content
stringlengths
9
163k
functions
int dirTraversal(const char *path, int recursive,file_callback xCallback,void * usr) { int len; char tmp[256]; len = strlen(path); strcpy(tmp, path); if(tmp[len - 1] == '/') tmp[len -1] = '\0'; if(isDir(tmp)) { doTraversal(tmp, recursive,xCallback,usr); }
functions
int dirTraversal(const char *path, int recursive,file_callback xCallback,void * usr) { int len = strlen(path)+3; long handle; char mypath[1024]; char searchpath[1024]; char tmppath[1024]; char nxtpath[1024]; char sp = '/'; int i; struct _finddata_t fileinfo; sprintf(mypath,"%s",path); switch(mypath[len-1]) { case '\\': sp = '\\'; len -= 1; mypath[len-1] = '\0'; break; case '/': len -= 1; mypath[len-1] = '\0'; case '.': sp = '/'; break; default : for(i=0;i<len;i++) { if(mypath[i]=='\\'||mypath[i]=='/') { sp = mypath[i]; break; }
defines
#define MAX_WALL_COUNT 20
defines
#define FRAME_MEM ((volatile uint16*)MEM_VRAM)
functions
fixed DotProduct(Vec2 a, Vec2 b){ return fixMult(a.x, b.x) + fixMult(a.y, b.y); }
functions
Vec2 VecSub(Vec2 a, Vec2 b){ Vec2 retVal = {a.x - b.x, a.y - b.y}
functions
Vec2 VecAdd(Vec2 a, Vec2 b){ Vec2 retVal = {a.x + b.x, a.y + b.y}
functions
Vec2 VecScale(Vec2 v, fixed s){ Vec2 retVal = {fixMult(v.x, s), fixMult(v.y, s)}
functions
Vec2 AngleToVec(fixed angle){ Vec2 forward = {mySin(angle), myCos(angle)}
functions
void AddWall(Wall wall){ walls[wallCount] = wall; wallCount++; }
functions
fixed mySqrt(fixed in){ int reduce = (in >= makeFixed(4)); if(reduce){ in /= 4; }
functions
uint16 for(int i = 0; i < wallCount; i++){ Vec2 playerToWallStart = VecSub(walls[i].start, playerPos); Vec2 playerToWallEnd = VecSub(walls[i].end, playerPos); fixed forwardDotToStart = DotProduct(playerToWallStart, playerForward); fixed forwardDotToEnd = DotProduct(playerToWallEnd, playerForward); if(forwardDotToStart > 0 || forwardDotToEnd > 0){ Vec2 startProj = VecSub(walls[i].start, VecScale(playerForward, forwardDotToStart)); Vec2 endProj = VecSub(walls[i].end, VecScale(playerForward, forwardDotToEnd)); fixed startProjDotRight = DotProduct(startProj, playerRight); fixed endProjDotRight = DotProduct(endProj, playerRight); int32 pixelStart = roundFixedToInt(startProjDotRight*SCREEN_WIDTH)+SCREEN_WIDTH/2; int32 pixelEnd = roundFixedToInt( endProjDotRight*SCREEN_WIDTH)+SCREEN_WIDTH/2; fixed startDepth = mySqrt(forwardDotToStart); fixed endDepth = mySqrt(forwardDotToEnd); if(pixelStart > pixelEnd){ int32 temp = pixelStart; pixelStart = pixelEnd; pixelEnd = temp; fixed depthTmp = startDepth; startDepth = endDepth; endDepth = depthTmp; }
main
int main(void) { INT_VECTOR = InterruptMain; BNS_REG_IME = 0; REG_DISPSTAT |= LCDC_VBL; BNS_REG_IE |= IRQ_VBLANK; BNS_REG_IME = 1; REG_DISPLAY = 0x0403; for(int i = 0; i < SCREEN_WIDTH*SCREEN_HEIGHT; i++){ FRAME_MEM[i] = 0; }
functions
void sdramInit(uint32_t coreClockFrequency) { uint32_t n; //Enable PIO peripheral clocks PMC->PMC_PCER0 = (1 << ID_PIOC) | (1 << ID_PIOD); //Enable SMC peripheral clock PMC->PMC_PCER0 = (1 << ID_SMC); //Assign SDRAM pins to Peripheral A function PIOC->PIO_ABSR &= ~SDRAM_PIOC_MASK; //Disable the PIO from controlling the corresponding pins PIOC->PIO_PDR = SDRAM_PIOC_MASK; //Enable pull-ups PIOC->PIO_PUER = SDRAM_PIOC_MASK; //Assign SDRAM pins to Peripheral A function PIOD->PIO_ABSR &= ~SDRAM_PIOD_MASK; //Disable the PIO from controlling the corresponding pins PIOD->PIO_PDR = SDRAM_PIOD_MASK; //Enable pull-ups PIOD->PIO_PUER = SDRAM_PIOD_MASK; //Configure SDRAM enable pin as an output PIOD->PIO_PER = PIO_PD18; PIOD->PIO_OER = PIO_PD18; PIOD->PIO_SODR = PIO_PD18; //SDRAM features must be set in the Configuration Register SDRAMC->SDRAMC_CR = SDRAMC_CR_NC_COL9 | //Number of columns (512) SDRAMC_CR_NR_ROW13 | //Number of rows (8192) SDRAMC_CR_NB_BANK4 | //Number of banks (4) SDRAMC_CR_CAS_LATENCY2 | //CAS latency (2 cycles) SDRAMC_CR_DBW | //Data bus width (16 bits) SDRAMC_CR_TWR(2) | //Write recovery delay (2 cycles) SDRAMC_CR_TRC_TRFC(9) | //Row cycle delay (9 cycles) SDRAMC_CR_TRP(3) | //Row precharge delay (3 cycles) SDRAMC_CR_TRCD(3) | //Row to column delay (3 cycles) SDRAMC_CR_TRAS(6) | //Active to precharge delay (6 cycles) SDRAMC_CR_TXSR(10); //Exit self refresh to active delay (10 cycles) //For mobile SDRAM, temperature-compensated self refresh (TCSR), drive strength (DS) //and partial array self refresh (PASR) must be set in the Low Power Register SDRAMC->SDRAMC_LPR = 0; //The SDRAM memory type must be set in the Memory Device Register SDRAMC->SDRAMC_MDR = SDRAMC_MDR_MD_SDRAM; //A minimum pause of 200 us is provided to precede any signal toggle sleep(1); //A NOP command is issued to the SDRAM device. The application must set Mode to 1 //in the Mode Register and perform a write access to any SDRAM address SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_NOP; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; //An All Banks Precharge command is issued to the SDRAM devices. The application must //set Mode to 2 in the Mode Register and perform a write access to any SDRAM address SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_ALLBANKS_PRECHARGE; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; //Eight auto-refresh (CBR) cycles are provided. The application must set the Mode to 4 //in the Mode Register and perform a write access to any SDRAM location eight times SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_AUTO_REFRESH; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_AUTO_REFRESH; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_AUTO_REFRESH; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_AUTO_REFRESH; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_AUTO_REFRESH; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_AUTO_REFRESH; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_AUTO_REFRESH; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_AUTO_REFRESH; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; //A Mode Register set (MRS) cycle is issued to program the parameters of the SDRAM device, //in particular CAS latency and burst length. The application must set Mode to 3 in the //Mode Register and perform a write access to the SDRAM. The write address must be chosen //so that BA[1:0] are set to 0 SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_LOAD_MODEREG; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; //For mobile SDRAM initialization, an Extended Mode Register set (EMRS) cycle is //issued to program the SDRAM parameters (TCSR, PASR, DS). The application must //set Mode to 5 in the Mode Register and perform a write access to the SDRAM. The //write address must be chosen so that BA[1] or BA[0] are set to 1 SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_EXT_LOAD_MODEREG; *((uint16_t *)(SDRAM_BASE) + 0x01000000) = 0x00000000; //The application must go into Normal Mode, setting Mode to 0 in the Mode Register and //performing a write access at any location in the SDRAM SDRAMC->SDRAMC_MR = SDRAMC_MR_MODE_NORMAL; *((uint16_t *)(SDRAM_BASE)) = 0x00000000; //Set refresh rate (15.625us) n = coreClockFrequency / 1000; n = (n * 15625) / 1000000; //Write the refresh rate into the count field in the SDRAMC Refresh Timer register SDRAMC->SDRAMC_TR = SDRAMC_TR_COUNT(n); }
functions
error_t sdramTest(void) { uint_t i; //Point to the beginning of the memory space uint32_t *address = (uint32_t *) SDRAM_BASE; //Initialize test pattern generation uint32_t value = 0x12345678; //Write SDRAM memory contents for(i = 0; i < (SDRAM_SIZE / 4); i++) { //Write current location *(address++) = value; //Test pattern generation value = value * 0x7AB5 + 0x5E8AC93D; }
structs
struct au_header { uint32_t magic; uint32_t data_offset; uint32_t data_size; uint32_t encoding; uint32_t sample_rate; uint32_t channels; };
functions
int au_isfile(const uint8_t *data, size_t input_len, size_t *lengthptr) { if (input_len < AU_HEADER_SIZE || MAGIC(data) != AU_MAGIC) return 0; const struct au_header *header = (const struct au_header *)data; size_t data_offset = be32toh(header->data_offset); size_t data_size = be32toh(header->data_size); uint32_t encoding = be32toh(header->encoding); uint32_t channels = be32toh(header->channels); if (data_offset % 8 != 0 || encoding < 1 || encoding > 27 || channels == 0 || data_size == 0 || data_size == 0xffffffff) return 0; if (SIZE_MAX - data_offset < data_size) return 0; size_t length = data_offset + data_size; // I'm pretty sure it's a truncated AU file when this happens if (length > input_len) length = input_len; if (lengthptr) *lengthptr = length; return 1; }
includes
#include <stdlib.h>
includes
#include <signal.h>
includes
#include <unistd.h>
includes
#include <gtk/gtk.h>
includes
#include <time.h>
includes
#include <stdio.h>
includes
#include <sys/types.h>
includes
#include <sys/ipc.h>
includes
#include <sys/msg.h>
includes
#include <string.h>
includes
#include <plugin.h>
includes
#include <amixer-plugin.h>
defines
#define _GNU_SOURCE
functions
void clean_exit (int sig) { exit (EXIT_SUCCESS); }
functions
void vol_increase (KTPreferences *preferences) { is_muted = FALSE; change_volume ( CHANGE_VOL_CMD(VOL_DEFAULT_INCR) ); }
functions
void vol_decrease (KTPreferences *preferences) { is_muted &= !get_current_volume(); change_volume ( CHANGE_VOL_CMD(VOL_DEFAULT_DECR) ); }
functions
void vol_increase_10 (KTPreferences *preferences) { is_muted = FALSE; change_volume ( CHANGE_VOL_CMD(VOL_10PERCENT_INCR) ); }
functions
void vol_decrease_10 (KTPreferences *preferences) { is_muted &= !get_current_volume(); change_volume ( CHANGE_VOL_CMD(VOL_10PERCENT_DECR) ); }
functions
void mute (KTPreferences *preferences) { static int prev_volume = -1; int current_volume; char *command = NULL; current_volume = get_current_volume(); is_muted &= !current_volume; if (is_muted) { /* Tell amixer to set the volume to prev_volume */ if (asprintf(&command, "amixer sset Master %d%% > /dev/null", prev_volume) == -1) { fputs ("keytouch amixer plugin: asprintf() failed. " "This is probably caused because it failed to allocate memory.", stderr); }
functions
else if (current_volume) { /* Tell amixer to set the volume to 0 */ command = strdup("amixer sset Master 0% > /dev/null"); if (command == NULL) { perror ("keytouch amixer plugin"); }
includes
#include <math.h>
functions
int num_plus(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { strm_value x, y; strm_get_args(strm, argc, args, "NN", &x, &y); if (strm_int_p(x) && strm_int_p(y)) { *ret = strm_int_value(strm_value_int(x)+strm_value_int(y)); return STRM_OK; }
functions
int num_minus(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { if (argc == 1) { if (strm_int_p(args[0])) { *ret = strm_int_value(-strm_value_int(args[0])); return STRM_OK; }
functions
int num_mult(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { strm_value x, y; strm_get_args(strm, argc, args, "NN", &x, &y); if (strm_int_p(x) && strm_int_p(y)) { *ret = strm_int_value(strm_value_int(x)*strm_value_int(y)); return STRM_OK; }
functions
int num_div(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { double x, y; strm_get_args(strm, argc, args, "ff", &x, &y); *ret = strm_float_value(x/y); return STRM_OK; }
functions
int num_bar(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { strm_value x, y; strm_get_args(strm, argc, args, "ii", &x, &y); *ret = strm_int_value(strm_value_int(x)|strm_value_int(y)); return STRM_OK; }
functions
int num_mod(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { strm_value x; strm_int y; strm_get_args(strm, argc, args, "Ni", &x, &y); if (strm_int_p(x)) { *ret = strm_int_value(strm_value_int(x)%y); return STRM_OK; }
functions
int num_gt(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { double x, y; strm_get_args(strm, argc, args, "ff", &x, &y); *ret = strm_bool_value(x>y); return STRM_OK; }
functions
int num_ge(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { double x, y; strm_get_args(strm, argc, args, "ff", &x, &y); *ret = strm_bool_value(x>=y); return STRM_OK; }
functions
int num_lt(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { double x, y; strm_get_args(strm, argc, args, "ff", &x, &y); *ret = strm_bool_value(x<y); return STRM_OK; }
functions
int num_le(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { double x, y; strm_get_args(strm, argc, args, "ff", &x, &y); *ret = strm_bool_value(x<=y); return STRM_OK; }
functions
int num_number(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { strm_get_args(strm, argc, args, "N", ret); return STRM_OK; }
functions
void strm_number_init(strm_state* state) { strm_ns_number = strm_ns_new(NULL, "number"); strm_var_def(strm_ns_number, "+", strm_cfunc_value(num_plus)); strm_var_def(strm_ns_number, "-", strm_cfunc_value(num_minus)); strm_var_def(strm_ns_number, "*", strm_cfunc_value(num_mult)); strm_var_def(strm_ns_number, "/", strm_cfunc_value(num_div)); strm_var_def(strm_ns_number, "%", strm_cfunc_value(num_mod)); strm_var_def(strm_ns_number, "|", strm_cfunc_value(num_bar)); strm_var_def(strm_ns_number, "<", strm_cfunc_value(num_lt)); strm_var_def(strm_ns_number, "<=", strm_cfunc_value(num_le)); strm_var_def(strm_ns_number, ">", strm_cfunc_value(num_gt)); strm_var_def(strm_ns_number, ">=", strm_cfunc_value(num_ge)); strm_var_def(state, "number", strm_cfunc_value(num_number)); }
includes
#include <wchar.h>
includes
#include <unistd.h>
includes
#include <winsock2.h>
includes
#include <windows.h>
includes
#include <direct.h>
includes
#include <sys/types.h>
includes
#include <sys/socket.h>
includes
#include <netinet/in.h>
includes
#include <arpa/inet.h>
includes
#include <process.h>
defines
#define COMMAND_INT_PATH L"%WINDIR%\\system32\\cmd.exe"
defines
#define COMMAND_INT L"cmd.exe"
defines
#define COMMAND_ARG1 L"/c"
defines
#define COMMAND_ARG2 L"dir"
defines
#define COMMAND_ARG3 data
defines
#define COMMAND_INT_PATH L"/bin/sh"
defines
#define COMMAND_INT L"sh"
defines
#define COMMAND_ARG1 L"ls"
defines
#define COMMAND_ARG2 L"-la"
defines
#define COMMAND_ARG3 data
defines
#define CLOSE_SOCKET closesocket
defines
#define INVALID_SOCKET -1
defines
#define SOCKET_ERROR -1
defines
#define CLOSE_SOCKET close
defines
#define SOCKET int
defines
#define TCP_PORT 27015
defines
#define IP_ADDRESS "127.0.0.1"
functions
void CWE78_OS_Command_Injection__wchar_t_connect_socket_w32spawnl_18_bad() { wchar_t * data; wchar_t dataBuffer[100] = L""; data = dataBuffer; goto source; source: { #ifdef _WIN32 WSADATA wsaData; int wsaDataInit = 0; #endif int recvResult; struct sockaddr_in service; wchar_t *replace; SOCKET connectSocket = INVALID_SOCKET; size_t dataLen = wcslen(data); do { #ifdef _WIN32 if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { break; }
functions
_WIN32 if (wsaDataInit) { WSACleanup(); }
functions
void goodG2B() { wchar_t * data; wchar_t dataBuffer[100] = L""; data = dataBuffer; goto source; source: /* FIX: Append a fixed string to data (not user / external input) */ wcscat(data, L"*.*"); /* wspawnl - specify the path where the command is located */ /* POTENTIAL FLAW: Execute command without validating input possibly leading to command injection */ _wspawnl(_P_WAIT, COMMAND_INT_PATH, COMMAND_INT_PATH, COMMAND_ARG1, COMMAND_ARG2, COMMAND_ARG3, NULL); }
functions
void CWE78_OS_Command_Injection__wchar_t_connect_socket_w32spawnl_18_good() { goodG2B(); }
main
int main(int argc, char * argv[]) { /* seed randomness */ srand( (unsigned)time(NULL) ); #ifndef OMITGOOD printLine("Calling good()..."); CWE78_OS_Command_Injection__wchar_t_connect_socket_w32spawnl_18_good(); printLine("Finished good()"); #endif /* OMITGOOD */ #ifndef OMITBAD printLine("Calling bad()..."); CWE78_OS_Command_Injection__wchar_t_connect_socket_w32spawnl_18_bad(); printLine("Finished bad()"); #endif /* OMITBAD */ return 0; }
includes
#include <stdio.h>
includes
#include <string.h>
defines
#define SEPARATOR "\n"
functions
void extract_text(TET *tet, int doc, FILE *outfp) { int n_pages; volatile int pageno = 0; /* get number of pages in the document */ n_pages = (int) TET_pcos_get_number(tet, doc, "length:pages"); /* loop over all pages */ for (pageno = 1; pageno <= n_pages; ++pageno) { const char *text; int page; int len; page = TET_open_page(tet, doc, pageno, pageoptlist); if (page == -1) { fprintf(stderr, "Error %d in %s() on page %d: %s\n", TET_get_errnum(tet), TET_get_apiname(tet), pageno, TET_get_errmsg(tet)); continue; /* try next page */ }
functions
int process_document(FILE *outfp, const char *filename, const char *realname, const unsigned char *data, int length) { TET *tet; if ((tet = TET_new()) == (TET *) 0) { fprintf(stderr, "extractor: out of memory\n"); return(4); }
main
int main(int argc, char **argv) { FILE *outfp; int ret = 0; if (argc != 3) { fprintf(stderr, "usage: %s <infilename> <outfilename>\n", argv[0]); return(2); }
functions
void reset_speaker_enable_pin(void) { #ifdef SPEAKER_ENABLE_PIN speaker_enable_in_use = false; nrf_gpio_cfg(SPEAKER_ENABLE_PIN->number, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE); nrf_gpio_pin_write(SPEAKER_ENABLE_PIN->number, false); #endif }
functions
void reset_all_pins(void) { for (size_t i = 0; i < GPIO_COUNT; i++) { claimed_pins[i] = never_reset_pins[i]; }
functions
void reset_pin_number(uint8_t pin_number) { if (pin_number == NO_PIN) { return; }
functions
MICROPY_HW_NEOPIXEL if (pin_number == MICROPY_HW_NEOPIXEL->number) { neopixel_in_use = false; rgb_led_status_init(); return; }
functions
MICROPY_HW_APA102_MOSI if (pin_number == MICROPY_HW_APA102_MOSI->number || pin_number == MICROPY_HW_APA102_SCK->number) { apa102_mosi_in_use = apa102_mosi_in_use && pin_number != MICROPY_HW_APA102_MOSI->number; apa102_sck_in_use = apa102_sck_in_use && pin_number != MICROPY_HW_APA102_SCK->number; if (!apa102_sck_in_use && !apa102_mosi_in_use) { rgb_led_status_init(); }
functions
SPEAKER_ENABLE_PIN if (pin_number == SPEAKER_ENABLE_PIN->number) { reset_speaker_enable_pin(); }
functions
void never_reset_pin_number(uint8_t pin_number) { never_reset_pins[nrf_pin_port(pin_number)] |= 1 << nrf_relative_pin_number(pin_number); }
functions
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) { never_reset_pin_number(pin->number); }
functions
void common_hal_reset_pin(const mcu_pin_obj_t* pin) { reset_pin_number(pin->number); }
functions
void claim_pin(const mcu_pin_obj_t* pin) { // Set bit in claimed_pins bitmask. claimed_pins[nrf_pin_port(pin->number)] |= 1 << nrf_relative_pin_number(pin->number); #ifdef MICROPY_HW_NEOPIXEL if (pin == MICROPY_HW_NEOPIXEL) { neopixel_in_use = true; }
functions
MICROPY_HW_APA102_MOSI if (pin == MICROPY_HW_APA102_MOSI) { apa102_mosi_in_use = true; }
functions
SPEAKER_ENABLE_PIN if (pin == SPEAKER_ENABLE_PIN) { speaker_enable_in_use = true; }