file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/122016207.c
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #define OPTION(s) strcmp(argv[i],s) == 0 char *getpath(char *path) { char *p = path + strlen(path); for(;p!=path&&*p!='/'&&*p!='\\';p--); p++; *p=0; return path; } char *getpure(char *path) { char *p = path + strlen(path); for(;p!=path&&*p!='/'&&*p!='\\';p--); return p; } void execute_cmd(char *cmd, char *name, int enlog, FILE *logfp) { char **stdout_d = NULL; int stdout_n = 0; char stdout_b[1024]; int i; int child_ret = -2017; if(enlog) fprintf(logfp,"%s Stage\nCommand line : %s\n>>>>BEGIN\n",name,cmd); FILE *fp = popen(cmd,"r"); while(fp && fgets(stdout_b,1024,fp)) { stdout_d = (char **)realloc(stdout_d, sizeof(char *) * (stdout_n + 1)); stdout_d[stdout_n] = strdup(stdout_b); if(enlog) fputs(stdout_d[stdout_n],logfp); stdout_n++; } if(!fp || (child_ret = pclose(fp)) != 0) { if(child_ret != -2017) fprintf(stderr,"%s Returned %d\n",name,child_ret); else fprintf(stderr,"%s execute failed\n",name); fprintf(stderr,"%s execute stage failed.\n",name); fprintf(stderr,"stdout :\n"); for(i = 0; i < stdout_n; i++) printf(stdout_d[i]); if(enlog) { fprintf(logfp,"%s Returned %d\n",name,child_ret); fprintf(logfp,">>>>END(FAILED)\n\n"); fclose(logfp); } exit(-1); } if(enlog) fprintf(logfp,">>>>END\n\n"); } int main(int argc, char *argv[], char *envp[]) { char cc1[4096]; char cpp[4096]; char as[4096]; char binname[2048]; char logname[2048] = ""; char sz[512]; char option_format[64] = "-flat"; int i; int next = 0; int ret; int ptr = 0; int enlog = 0; char argvpath[2048]; readlink("/proc/self/exe", argvpath, sizeof(argvpath)-1); char *dumppath = strdup(argvpath); char *path = getpath(dumppath); sprintf(as, "%s/../as/as ",path); sprintf(cc1,"%s/../cc1/cc1 ",path); sprintf(cpp, "%s/../cpp/cpp ",path); if(argc < 3) { printf("usage : %s [option] source output\n",argv[0]); puts("Error : too few argments"); return 3; } for(i = 1; i < argc; i++) { if(next == 1) { strcat(cpp,argv[i]); strcat(cpp," "); next = 0; continue; } if(next == 2) { strcpy(logname,argv[i]); next = 0; continue; } if( OPTION("-I") || OPTION("-J") ) { strcat(cpp,argv[i]); strcat(cpp," "); next = 1; } else if( OPTION("-C") || OPTION("-s") || OPTION("-l") || OPTION("-CC") || OPTION("-a") || OPTION("-na") || OPTION("-V") || OPTION("-u") || OPTION("-X") || OPTION("-c90") || OPTION("-w") || OPTION("-zl") || OPTION("-M") || OPTION("-D") || OPTION("-U") || OPTION("-A") || OPTION("-B") || OPTION("-Y") || OPTION("-Z") || OPTION("-d") || OPTION("-e") || OPTION("-v") || OPTION("-h") ) { strcat(cpp,argv[i]); strcat(cpp," "); } else if( OPTION("-flat") || OPTION("-coff") ) { strcpy(option_format,argv[i]); } else if( OPTION("-log") ) { next = 2; enlog = 1; } else if( OPTION("-help") ) { puts("micro portable cc `UCC` by kagura1050"); puts("Version : git"); printf("usage : %s [option] source output\n",argv[0]); return 1; } else { if(ptr < 2) { if(ptr) { strcpy(binname,argv[i]); } if(!ptr) { strcat(cpp,argv[i]); strcat(cpp," "); } } else { puts("Error : too many filename"); return 1; } ptr++; } } if(ptr < 2) { puts("Error : unable to get output filename"); return 2; } if(logname[0] == 0 && enlog) { puts("Error : log file is not specified"); return 4; } int tmp = time(NULL); char *allname = strdup(binname); char *purename = getpure(allname); sprintf(sz,"_ucc_%08x_%s_asm.tmp %s %s",tmp,purename,binname,option_format); strcat(as,sz); sprintf(sz,"-o _ucc_%08x_%s_cxx.tmp",tmp,purename); strcat(cpp,sz); sprintf(sz,"_ucc_%08x_%s_cxx.tmp _ucc_%08x_%s_asm.tmp",tmp,purename,tmp,purename); strcat(cc1,sz); int child_ret = -2017; FILE *fp; FILE *logfp; if(enlog) { logfp = fopen(logname,"wt"); } execute_cmd(cpp,"Preprocessor",enlog,logfp); execute_cmd(cc1,"Compiler",enlog,logfp); execute_cmd(as,"Assembler",enlog,logfp); if(enlog) fclose(logfp); return 0; }
the_stack_data/82205.c
//Experiment-1 => d) Priority CPU Scheduling Algoritm #include<stdio.h> int main() { int p[20],bt[20],pri[20], wt[20],tat[20],i, k, n, temp; float wtavg, tatavg; printf("Enter the number of processes: "); scanf("%d",&n); for(i=0;i<n;i++){ p[i] = i; printf("Enter the Burst Time & Priority of Process %d: ",i); scanf("%d %d",&bt[i], &pri[i]); } for(i=0;i<n;i++) for(k=i+1;k<n;k++) if(pri[i] > pri[k]){ temp=p[i]; p[i]=p[k]; p[k]=temp; temp=bt[i]; bt[i]=bt[k]; bt[k]=temp; temp=pri[i]; pri[i]=pri[k]; pri[k]=temp; } wtavg = wt[0] = 0; tatavg = tat[0] = bt[0]; for(i=1;i<n;i++){ wt[i] = wt[i-1] + bt[i-1]; tat[i] = tat[i-1] + bt[i]; wtavg = wtavg + wt[i]; tatavg = tatavg + tat[i]; } printf("\nPROCESS\t\tPRIORITY\tBURST TIME\tWAITING TIME\tTURNAROUND TIME"); for(i=0;i<n;i++) printf("\n%d \t\t %d \t\t %d \t\t %d \t\t %d ",p[i],pri[i],bt[i],wt[i],tat[i]); printf("\n\nAverage Waiting Time is: %f",wtavg/n); printf("\nAverage Turnaround Time is: %f\n",tatavg/n); return 0; }
the_stack_data/232955818.c
int f(int m, int n) { int r; int x; x = 0; r = 0; if (m > 0 && n == 0) { r = f(m - 1, 1); } else { if (m == 1) { r = n + 1; } else { x = f(m, n - 1); r = f(m - 1, x); }} return r; }
the_stack_data/126701768.c
/* * @Description: 循环队列(顺序表示) * @version: 1.0 * @Author: Chandler Lu * @Date: 2019-09-02 17:46:08 * @LastEditTime: 2019-09-02 18:13:12 */ #include <stdio.h> #include <stdlib.h> #define MAXSIZE 15 #define OK 1 #define ERROR 0 #define TRUE 1 #define FALSE 0 typedef struct SqQueue { int front, rear; int data[MAXSIZE]; } SqQueue; void InitQueue(SqQueue *); int QueueEmpty(SqQueue *); int EnQueue(SqQueue *, int); int DeQueue(SqQueue *, int *); int DeQueue(SqQueue *, int *); void GetHead(SqQueue *, int *); int main(int argc, char *argv[]) { SqQueue *q = (SqQueue *)malloc(sizeof(SqQueue)); InitQueue(q); int num; GetHead(q, &num); for (int i = 0; i < MAXSIZE - 1; i++) { EnQueue(q, i); } printf("队头为:%d\n队列为:", num); for (int i = 0; i < MAXSIZE - 1; i++) { DeQueue(q, &num); printf("%d", num); if (i != MAXSIZE - 2) { printf(" "); } } free(q); } void InitQueue(SqQueue *q) { q->front = 0; q->rear = 0; } int QueueEmpty(SqQueue *q) { if (q->rear == q->front) { return TRUE; } return FALSE; } int EnQueue(SqQueue *q, int data) { if ((q->rear + 1) % MAXSIZE == q->front) { return ERROR; } q->data[q->rear] = data; q->rear = (q->rear + 1) % MAXSIZE; return OK; } int DeQueue(SqQueue *q, int *data) { if (q->rear == q->front) { return ERROR; } *data = q->data[q->front]; q->front = (q->front + 1) % MAXSIZE; return OK; } void GetHead(SqQueue *q, int *data) { *data = q->data[q->front]; }
the_stack_data/62743.c
// Write a menu driven program of circular queue using arrays having menu with options enqueue , dequeue , display and exit. #include <stdio.h> #define size 5 typedef struct Queue { int queue[size]; int front; int rear; } q; void enqueue(q *q1) { int new1; printf("\nEnter element\n"); scanf("%d", &new1); if (q1->front == -1 && q1->rear == -1) { q1->queue[++q1->rear] = new1; q1->front = 0; return; } if ((q1->front == 0 && q1->rear == size - 1) || q1->front == q1->rear + 1) printf("Queue full\n"); else { q1->rear = (q1->rear + 1) % size; q1->queue[q1->rear] = new1; } return; } void dequeue(q *q1) { if (q1->rear == -1 && q1->front == -1) { printf("Queue empty"); return; } printf("Element deleted = %d", q1->queue[q1->front]); q1->front = (q1->front + 1) % size; if (q1->front == (q1->rear + 1) % size) { q1->front = -1; q1->rear = -1; } return; } void display(q *q1) { int temp; if (q1->front == -1 && q1->rear == -1) { printf("Queue empty"); return; } temp = q1->front; while (temp != q1->rear) { printf("%d\n", q1->queue[temp]); temp = (temp + 1) % size; } printf("%d\n", q1->queue[q1->rear]); return; } void main() { int choice; q q1; q1.front = -1; q1.rear = -1; do { printf("\n1.Enqueue\n2.Dequeue\n3.Display\n4.Exit\n"); scanf("%d", &choice); switch (choice) { case 1: { enqueue(&q1); break; } case 2: { dequeue(&q1); break; } case 3: { display(&q1); break; } case 4: break; default: printf("Invalid choiceoice"); } } while (choice != 4); }
the_stack_data/104827484.c
/* Test error handling of optimization pragmas. */ /* Radar 3124235 */ /* LLVM LOCAL disable pragma opt -- whole file */ /* { dg-do compile { xfail { *-*-* } } } */ #include <stdio.h>
the_stack_data/45005.c
/* * xbanish * Copyright (c) 2013-2021 joshua stein <[email protected]> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <err.h> #include <signal.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <X11/X.h> #include <X11/Xlib.h> #include <X11/Intrinsic.h> #include <X11/extensions/sync.h> #include <X11/extensions/Xfixes.h> #include <X11/extensions/XInput.h> #include <X11/extensions/XInput2.h> void hide_cursor(void); void show_cursor(void); void snoop_root(void); int snoop_xinput(Window); void snoop_legacy(Window); void set_alarm(XSyncAlarm *, XSyncTestType); void usage(char *); int swallow_error(Display *, XErrorEvent *); /* xinput event type ids to be filled in later */ static int button_press_type = -1; static int button_release_type = -1; static int key_press_type = -1; static int key_release_type = -1; static int motion_type = -1; static int device_change_type = -1; static long last_device_change = -1; static Display *dpy; static int hiding = 0, legacy = 0, always_hide = 0, ignore_scroll = 0; static unsigned timeout = 0; static unsigned char ignored; static XSyncCounter idler_counter = 0; static XSyncAlarm idle_alarm = None; static int debug = 0; #define DPRINTF(x) { if (debug) { printf x; } }; static int move = 0, move_x, move_y; enum move_types { MOVE_NW = 1, MOVE_NE, MOVE_SW, MOVE_SE, MOVE_WIN_NW, MOVE_WIN_NE, MOVE_WIN_SW, MOVE_WIN_SE, }; int main(int argc, char *argv[]) { int ch, i; XEvent e; XSyncAlarmNotifyEvent *alarm_e; XGenericEventCookie *cookie; XSyncSystemCounter *counters; int sync_event, error; int major, minor, ncounters; struct mod_lookup { char *name; int mask; } mods[] = { {"shift", ShiftMask}, {"lock", LockMask}, {"control", ControlMask}, {"mod1", Mod1Mask}, {"mod2", Mod2Mask}, {"mod3", Mod3Mask}, {"mod4", Mod4Mask}, {"mod5", Mod5Mask}, {"all", -1}, }; while ((ch = getopt(argc, argv, "adi:m:t:s")) != -1) switch (ch) { case 'a': always_hide = 1; break; case 'd': debug = 1; break; case 'i': for (i = 0; i < sizeof(mods) / sizeof(struct mod_lookup); i++) if (strcasecmp(optarg, mods[i].name) == 0) ignored |= mods[i].mask; break; case 'm': if (strcmp(optarg, "nw") == 0) move = MOVE_NW; else if (strcmp(optarg, "ne") == 0) move = MOVE_NE; else if (strcmp(optarg, "sw") == 0) move = MOVE_SW; else if (strcmp(optarg, "se") == 0) move = MOVE_SE; else if (strcmp(optarg, "wnw") == 0) move = MOVE_WIN_NW; else if (strcmp(optarg, "wne") == 0) move = MOVE_WIN_NE; else if (strcmp(optarg, "wsw") == 0) move = MOVE_WIN_SW; else if (strcmp(optarg, "wse") == 0) move = MOVE_WIN_SE; else { warnx("invalid '-m' argument"); usage(argv[0]); } break; case 't': timeout = strtoul(optarg, NULL, 0); case 's': ignore_scroll = 1; break; default: usage(argv[0]); } argc -= optind; argv += optind; if (!(dpy = XOpenDisplay(NULL))) errx(1, "can't open display %s", XDisplayName(NULL)); #ifdef __OpenBSD__ if (pledge("stdio", NULL) == -1) err(1, "pledge"); #endif XSetErrorHandler(swallow_error); snoop_root(); if (always_hide) hide_cursor(); /* required setup for the xsync alarms used by timeout */ if (timeout) { if (XSyncQueryExtension(dpy, &sync_event, &error) != True) errx(1, "no sync extension available"); XSyncInitialize(dpy, &major, &minor); counters = XSyncListSystemCounters(dpy, &ncounters); for (i = 0; i < ncounters; i++) { if (!strcmp(counters[i].name, "IDLETIME")) { idler_counter = counters[i].counter; break; } } XSyncFreeSystemCounterList(counters); if (!idler_counter) errx(1, "no idle counter"); } for (;;) { cookie = &e.xcookie; XNextEvent(dpy, &e); int etype = e.type; if (e.type == motion_type) etype = MotionNotify; else if (e.type == key_press_type || e.type == key_release_type) etype = KeyRelease; else if (e.type == button_press_type || e.type == button_release_type) etype = ButtonRelease; else if (e.type == device_change_type) { XDevicePresenceNotifyEvent *xdpe = (XDevicePresenceNotifyEvent *)&e; if (last_device_change == xdpe->serial) continue; snoop_root(); last_device_change = xdpe->serial; continue; } switch (etype) { case KeyRelease: if (ignored) { unsigned int state = 0; /* masks are only set on key release, if * ignore is set we must throw out non-release * events here */ if (e.type == key_press_type) { break; } /* extract modifier state */ if (e.type == key_release_type) { /* xinput device event */ XDeviceKeyEvent *key = (XDeviceKeyEvent *) &e; state = key->state; } else if (e.type == KeyRelease) { /* legacy event */ state = e.xkey.state; } if (state & ignored) { DPRINTF(("ignoring key %d\n", state)); break; } } hide_cursor(); break; case ButtonRelease: case MotionNotify: if (!always_hide) show_cursor(); break; case CreateNotify: if (legacy) { DPRINTF(("new window, snooping on it\n")); /* not sure why snooping directly on the window * doesn't work, so snoop on all windows from * its parent (probably root) */ snoop_legacy(e.xcreatewindow.parent); } break; case GenericEvent: /* xi2 raw event */ XGetEventData(dpy, cookie); XIDeviceEvent *xie = (XIDeviceEvent *)cookie->data; switch (xie->evtype) { case XI_RawMotion: case XI_RawButtonPress: if (ignore_scroll && ((xie->detail >= 4 && xie->detail <= 7) || xie->event_x == xie->event_y)) break; if (!always_hide) show_cursor(); break; case XI_RawButtonRelease: break; default: DPRINTF(("unknown XI event type %d\n", xie->evtype)); } XFreeEventData(dpy, cookie); break; default: if (!timeout || e.type != (sync_event + XSyncAlarmNotify)) { DPRINTF(("unknown event type %d\n", e.type)); break; } alarm_e = (XSyncAlarmNotifyEvent *)&e; if (alarm_e->alarm == idle_alarm) { DPRINTF(("idle counter reached %dms, hiding " "cursor\n", XSyncValueLow32(alarm_e->counter_value))); hide_cursor(); } } } } void hide_cursor(void) { Window win; XWindowAttributes attrs; int x, y, h, w, junk; unsigned int ujunk; DPRINTF(("keystroke, %shiding cursor\n", (hiding ? "already " : ""))); if (hiding) return; if (move) { if (XQueryPointer(dpy, DefaultRootWindow(dpy), &win, &win, &x, &y, &junk, &junk, &ujunk)) { move_x = x; move_y = y; XGetWindowAttributes(dpy, win, &attrs); h = XHeightOfScreen(DefaultScreenOfDisplay(dpy)); w = XWidthOfScreen(DefaultScreenOfDisplay(dpy)); switch (move) { case MOVE_NW: x = 0; y = 0; break; case MOVE_NE: x = w; y = 0; break; case MOVE_SW: x = 0; y = h; break; case MOVE_SE: x = w; y = h; break; case MOVE_WIN_NW: x = attrs.x; y = attrs.y; break; case MOVE_WIN_NE: x = attrs.x + attrs.width; y = attrs.y; break; case MOVE_WIN_SW: x = attrs.x; y = attrs.x + attrs.height; break; case MOVE_WIN_SE: x = attrs.x + attrs.width; y = attrs.x + attrs.height; break; } XWarpPointer(dpy, None, DefaultRootWindow(dpy), 0, 0, 0, 0, x, y); } else { move_x = -1; move_y = -1; warn("failed finding cursor coordinates"); } } XFixesHideCursor(dpy, DefaultRootWindow(dpy)); hiding = 1; } void show_cursor(void) { DPRINTF(("mouse moved, %sunhiding cursor\n", (hiding ? "" : "already "))); if (timeout) { DPRINTF(("(re)setting timeout of %us\n", timeout)); set_alarm(&idle_alarm, XSyncPositiveComparison); } if (!hiding) return; if (move && move_x != -1 && move_y != -1) XWarpPointer(dpy, None, DefaultRootWindow(dpy), 0, 0, 0, 0, move_x, move_y); XFixesShowCursor(dpy, DefaultRootWindow(dpy)); hiding = 0; } void snoop_root(void) { if (snoop_xinput(DefaultRootWindow(dpy)) == 0) { DPRINTF(("no XInput devices found, using legacy snooping")); legacy = 1; snoop_legacy(DefaultRootWindow(dpy)); } } int snoop_xinput(Window win) { int opcode, event, error, numdevs, i, j; int major, minor, rc, rawmotion = 0; int ev = 0; unsigned char mask[(XI_LASTEVENT + 7)/8]; XDeviceInfo *devinfo = NULL; XInputClassInfo *ici; XDevice *device; XIEventMask evmasks[1]; XEventClass class_presence; if (!XQueryExtension(dpy, "XInputExtension", &opcode, &event, &error)) { DPRINTF(("XInput extension not available")); return 0; } /* * If we support xinput 2, use that for raw motion and button events to * get pointer data when the cursor is over a Chromium window. We * could also use this to get raw key input and avoid the other XInput * stuff, but we may need to be able to examine the key value later to * filter out ignored keys. */ major = minor = 2; rc = XIQueryVersion(dpy, &major, &minor); if (rc != BadRequest) { memset(mask, 0, sizeof(mask)); XISetMask(mask, XI_RawMotion); XISetMask(mask, XI_RawButtonPress); evmasks[0].deviceid = XIAllMasterDevices; evmasks[0].mask_len = sizeof(mask); evmasks[0].mask = mask; XISelectEvents(dpy, win, evmasks, 1); XFlush(dpy); rawmotion = 1; DPRINTF(("using xinput2 raw motion events\n")); } devinfo = XListInputDevices(dpy, &numdevs); XEventClass event_list[numdevs * 2]; for (i = 0; i < numdevs; i++) { if (devinfo[i].use != IsXExtensionKeyboard && devinfo[i].use != IsXExtensionPointer) continue; if (!(device = XOpenDevice(dpy, devinfo[i].id))) break; for (ici = device->classes, j = 0; j < devinfo[i].num_classes; ici++, j++) { switch (ici->input_class) { case KeyClass: DPRINTF(("attaching to keyboard device %s " "(use %d)\n", devinfo[i].name, devinfo[i].use)); DeviceKeyPress(device, key_press_type, event_list[ev]); ev++; DeviceKeyRelease(device, key_release_type, event_list[ev]); ev++; break; case ButtonClass: if (rawmotion) continue; DPRINTF(("attaching to buttoned device %s " "(use %d)\n", devinfo[i].name, devinfo[i].use)); DeviceButtonPress(device, button_press_type, event_list[ev]); ev++; DeviceButtonRelease(device, button_release_type, event_list[ev]); ev++; break; case ValuatorClass: if (rawmotion) continue; DPRINTF(("attaching to pointing device %s " "(use %d)\n", devinfo[i].name, devinfo[i].use)); DeviceMotionNotify(device, motion_type, event_list[ev]); ev++; break; } } XCloseDevice(dpy, device); if (XSelectExtensionEvent(dpy, win, event_list, ev)) { warn("error selecting extension events"); ev = 0; goto done; } } DevicePresence(dpy, device_change_type, class_presence); if (XSelectExtensionEvent(dpy, win, &class_presence, 1)) { warn("error selecting extension events"); ev = 0; goto done; } done: if (devinfo != NULL) XFreeDeviceList(devinfo); return ev; } void snoop_legacy(Window win) { Window parent, root, *kids = NULL; XSetWindowAttributes sattrs; unsigned int nkids = 0, i; /* * Firefox stops responding to keys when KeyPressMask is used, so * settle for KeyReleaseMask */ int type = PointerMotionMask | KeyReleaseMask | Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask | ButtonMotionMask; if (XQueryTree(dpy, win, &root, &parent, &kids, &nkids) == FALSE) { warn("can't query window tree\n"); goto done; } XSelectInput(dpy, root, type); /* listen for newly mapped windows */ sattrs.event_mask = SubstructureNotifyMask; XChangeWindowAttributes(dpy, root, CWEventMask, &sattrs); for (i = 0; i < nkids; i++) { XSelectInput(dpy, kids[i], type); snoop_legacy(kids[i]); } done: if (kids != NULL) XFree(kids); /* hide yo kids */ } void set_alarm(XSyncAlarm *alarm, XSyncTestType test) { XSyncAlarmAttributes attr; XSyncValue value; unsigned int flags; XSyncQueryCounter(dpy, idler_counter, &value); attr.trigger.counter = idler_counter; attr.trigger.test_type = test; attr.trigger.value_type = XSyncRelative; XSyncIntsToValue(&attr.trigger.wait_value, timeout * 1000, (unsigned long)(timeout * 1000) >> 32); XSyncIntToValue(&attr.delta, 0); flags = XSyncCACounter | XSyncCATestType | XSyncCAValue | XSyncCADelta; if (*alarm) XSyncDestroyAlarm(dpy, *alarm); *alarm = XSyncCreateAlarm(dpy, flags, &attr); } void usage(char *progname) { fprintf(stderr, "usage: %s [-a] [-d] [-i mod] [-m [w]nw|ne|sw|se] " "[-t seconds] [-s]\n", progname); exit(1); } int swallow_error(Display *d, XErrorEvent *e) { if (e->error_code == BadWindow) /* no biggie */ return 0; if (e->error_code & FirstExtensionError) /* error requesting input on a particular xinput device */ return 0; errx(1, "got X error %d", e->error_code); }
the_stack_data/90763960.c
// // Created by Matthew Zimmer on 2019-03-08. // #include <stdio.h> #include <stdlib.h> int main() { /** * All of a program's memory is deallocated automatically when it exits, so a program * only needs to use free() during execution if it is important for the program to recycle * its memory while it runs -- typically because it uses a lot of memory or because it * runs for a long time. The pointer passed to free() must be exactly the pointer which * was originally returned by malloc() or realloc(), not just a pointer into somewhere * within the heap block. */ return 0; }
the_stack_data/193892745.c
#include <stdio.h> #include <math.h> #include <stdbool.h> /* * Simple lunar lander program. * By: <lyh> */ int main() { double altitude = 100; /* Meters */ double velocity = 0; /* Meters per second */ double fuel = 100; /* Kilograms */ double power = 1.5; /* Acceleration per pound of fuel */ double g = -1.63; /* Moon gravity in m/s^2 */ double burn; /* Amount of fuel to burn */ int i = 0; bool valid; /* Valid data entry flag */ printf("Lunar Lander - (c) 2012, by <lyh>\n"); while(altitude > 0 ) { if(fuel>0){ printf("Altitude: %.2f\n", altitude); printf("Velocity: %.2f\n", velocity); printf("You have %.1f kilograms of fuel\n", fuel); } if(fuel > 0){ do { valid = false; /* Assume invalid until we know otherwise */ printf("How much fuel would you like to burn: "); scanf("%lf", &burn); if(burn < 0) { printf("You can't burn negative fuel\n"); } else if(burn > 5) { printf("You can't burn more than 5 kilograms per second\n"); } else if(burn > fuel) { printf("You can't burn fuel you don't have\n"); } else { printf("Burning %.1f kilograms of fuel\n", burn); valid = true; } } while(!valid); }else{ burn = 0; } velocity = velocity + g + power * burn; altitude += velocity; fuel -= burn; i++; } if(fuel == 0) printf("You have 0 kilograms of fuel and you are falling...\n"); printf("You landed with a velocity of %.2f\n", velocity); if(fabs(velocity) > 3) { printf("Your next of kin have been notified\n"); }else{ printf("Congratulation! Your are landing successfully and safely!"); printf("Your remaining fuel is %lf, all time is :%d seconds", fuel, i); } }
the_stack_data/54825411.c
// RUN: %clang_cc1 %s -fsyntax-only -verify void __attribute__((annotate("foo"))) foo(float *a) { __attribute__((annotate("bar"))) int x; __attribute__((annotate(1))) int y; // expected-error {{'annotate' attribute requires a string}} __attribute__((annotate("bar", 1))) int z; // expected-error {{'annotate' attribute takes one argument}} int u = __builtin_annotation(z, (char*) 0); // expected-error {{second argument to __builtin_annotation must be a non-wide string constant}} int v = __builtin_annotation(z, (char*) L"bar"); // expected-error {{second argument to __builtin_annotation must be a non-wide string constant}} int w = __builtin_annotation(z, "foo"); float b = __builtin_annotation(*a, "foo"); // expected-error {{first argument to __builtin_annotation must be an integer}} }
the_stack_data/29824693.c
#include <stdio.h> #include <unistd.h> #include <termios.h> int main() { struct termios old_tio, new_tio; unsigned char c; /* get the terminal settings for stdin */ tcgetattr(STDIN_FILENO,&old_tio); /* we want to keep the old setting to restore them a the end */ new_tio=old_tio; /* disable canonical mode (buffered i/o) and local echo */ new_tio.c_lflag &=(~ICANON & ~ECHO); /* set the new settings immediately */ tcsetattr(STDIN_FILENO,TCSANOW,&new_tio); do { c=getchar(); printf("%d ",c); } while(c!='q'); /* restore the former settings */ tcsetattr(STDIN_FILENO,TCSANOW,&old_tio); return 0; }
the_stack_data/12638679.c
#include <stdio.h> #include <string.h> #define SIZE 32 int main(int argc, char const *argv[]) { char name[SIZE]; char buffer[2*SIZE]; char last[] = "passed the challenge!\n"; char c; int i = 0; //fetch input from the user //1. prompt the user to typu their name puts("Please enter your name: "); //2. Write a loop to process single character input storing it in a buffer called name[] while( (c=getchar()) != '\n' ) { name[i] = c; i++; if (i == SIZE -1) break; } name[i] = '\0'; //process input and string literal to generate a phrase strcpy(buffer, name); strcat(buffer, " "); strcat(buffer,last); //output the phrase i = 0; while( putchar(buffer[i++]) ); return 0; }
the_stack_data/153770.c
/** * @license Apache-2.0 * * Copyright (c) 2018 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Benchmark `fibonacci`. */ #include <stdlib.h> #include <stdio.h> #include <math.h> #include <sys/time.h> #define NAME "fibonacci::naive_recursion" #define ITERATIONS 100 #define REPEATS 3 /** * Prints the TAP version. */ void print_version() { printf( "TAP version 13\n" ); } /** * Prints the TAP summary. * * @param total total number of tests * @param passing total number of passing tests */ void print_summary( int total, int passing ) { printf( "#\n" ); printf( "1..%d\n", total ); // TAP plan printf( "# total %d\n", total ); printf( "# pass %d\n", passing ); printf( "#\n" ); printf( "# ok\n" ); } /** * Prints benchmarks results. * * @param elapsed elapsed time in seconds */ void print_results( double elapsed ) { double rate = (double)ITERATIONS / elapsed; printf( " ---\n" ); printf( " iterations: %d\n", ITERATIONS ); printf( " elapsed: %0.9f\n", elapsed ); printf( " rate: %0.9f\n", rate ); printf( " ...\n" ); } /** * Returns a clock time. * * @return clock time */ double tic() { struct timeval now; gettimeofday( &now, NULL ); return (double)now.tv_sec + (double)now.tv_usec/1.0e6; } /** * Generates a random double on the interval [0,1]. * * @return random double */ double rand_double() { int r = rand(); return (double)r / ( (double)RAND_MAX + 1.0 ); } /** * Computes the nth Fibonacci number. * * @param n Fibonacci number to compute * @return Fibonacci number */ int fibonacci( int n ) { if ( n < 2 ) { return n; } return fibonacci( n-1 ) + fibonacci( n-2 ); } /** * Runs a benchmark. * * @return elapsed time in seconds */ double benchmark() { double elapsed; double t; int x; int y; int i; t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { x = (int)floor( 40.0*rand_double() ); y = fibonacci( x ); if ( y < 0 ) { printf( "should return a nonnegative integer\n" ); break; } } elapsed = tic() - t; if ( y < 0 ) { printf( "should return a nonnegative integer\n" ); } return elapsed; } /** * Main execution sequence. */ int main( void ) { double elapsed; int i; // Use the current time to seed the random number generator: srand( time( NULL ) ); print_version(); for ( i = 0; i < REPEATS; i++ ) { printf( "# c::%s\n", NAME ); elapsed = benchmark(); print_results( elapsed ); printf( "ok %d benchmark finished\n", i+1 ); } print_summary( REPEATS, REPEATS ); }
the_stack_data/75136882.c
#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <stdlib.h> //cc -o clientCount clientCount.c int main() { int sock,bytes_recv; socklen_t sin_size; struct sockaddr_in server_addr; struct hostent *host; char send_data[1024],recv_data[1024]; host= (struct hostent *) gethostbyname((char *)"127.0.0.1"); if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { perror("socket"); exit(1); } server_addr.sin_family = AF_INET; server_addr.sin_port = htons(5000); server_addr.sin_addr = *((struct in_addr *)host->h_addr); memset(&(server_addr.sin_zero),0,sizeof(server_addr.sin_zero)); sin_size = sizeof(struct sockaddr); while (1) { printf("Type Something (q or Q to quit):"); gets(send_data); if ((strcmp(send_data , "q") == 0) || strcmp(send_data , "Q") == 0) break; else sendto(sock, send_data, strlen(send_data), 0, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)); } }
the_stack_data/54824799.c
#include <stdio.h> void printPattern (int); void printWhitespaces (int); int main () { int totalLines; printf("How many lines to be printed? -- "); fflush(stdout); scanf("%d", &totalLines); printf("\nYour pattern looks like this:\n"); printf("\n"); printPattern (totalLines); printf("\n"); return 0; } void printPattern (int totalLines) { int whiteSpace, printNumber, counter = totalLines; for (int i = 1; i <= totalLines; i++) { whiteSpace = (totalLines - i); printWhitespaces (whiteSpace); printNumber = ((2 * i) - 1); for (int j = 1; j <= printNumber; j++) { printf ("%2d ", counter); } counter--; printf("\n"); } } void printWhitespaces (int total) { for (int i = 1; i <= total; i++) { printf(" "); } }
the_stack_data/57950161.c
__attribute__((__visibility__("default"))) void fun() { }
the_stack_data/969317.c
#define __FP_SIGNBIT 0x0200 int __signbitf (float x) { unsigned short sw; __asm__ ("fxam; fstsw %%ax;" : "=a" (sw) : "t" (x) ); return (sw & __FP_SIGNBIT) != 0; } int __attribute__ ((alias ("__signbitf"))) signbitf (float);
the_stack_data/70450466.c
#include <stdlib.h> int b = 100; //extern b
the_stack_data/33883.c
/* Ввести и напечатать в обратном порядке последовательность чисел, количество которых заранее неизвестно. Количество значений определяется пользователем. Динамический массив задаётся с использованием функции malloc. */ #include <stdio.h> #include <stdlib.h> #include <locale.h> // установка русской локали (нужна для ОС Windows) int main() { setlocale(LC_ALL, "RUS"); int i, count; float *array; printf("Введите количество чисел: "); scanf("%d", &count); // динамически выделяем блок памяти под n элементов типа float array = (float *) malloc(count * sizeof(float)); printf("Введите %d чисел\n", count); for (i = 0; i < count; i++) { printf("число номер %d = ", i + 1); scanf("%f", &array[i]); } printf("\nОбратный порядок:\n"); for (i = count-1; i >= 0; i--) { printf("число номер %d = %f\n", i + 1, array[i]); } free(array); // освобождение динамически выделенной памяти return 0; }
the_stack_data/150141818.c
#include <stdio.h> int invert(unsigned int, unsigned int, unsigned int); int main() { printf("%d\n", invert(256, 0, 4)); } int invert(unsigned int x, unsigned int p, unsigned int n) { unsigned int a = ~(~0 << n) << p; return x ^ a; }
the_stack_data/87637957.c
const unsigned int romfs_img_len = 0x0001d800;
the_stack_data/43887059.c
// #include "AS1108.h" // #include <util/delay.h> // // void initSPI(void) { // SPI_SS_DDR |= (1 << SPI_SS); /* set SS output */ // SPI_SS_PORT |= (1 << SPI_SS); /* start off not selected (high) */ // // SPI_MOSI_DDR |= (1 << SPI_MOSI); /* output on MOSI */ // SPI_MISO_PORT |= (1 << SPI_MISO); /* pullup on MISO */ // SPI_SCK_DDR |= (1 << SPI_SCK); /* output on SCK */ // // /* Don't have to set phase, polarity b/c // * default works with 25LCxxx chips */ // SPCR |= (1 << SPR1); /* div 16, safer for breadboards */ // SPCR |= (1 << MSTR); /* clockmaster */ // SPCR |= (1 << SPE); /* enable */ // } // // void SPI_tradeByte(uint8_t byte) { // SPDR = byte; /* SPI starts sending immediately */ // loop_until_bit_is_set(SPSR, SPIF); /* wait until done */ // /* SPDR now contains the received byte */ // } // // void DISPLAY_writeByte(uint8_t address, uint8_t byte) { // SLAVE_SELECT; // SPI_tradeByte(address); // SPI_tradeByte(byte); // SLAVE_DESELECT; // } // // void DISPLAY_writeChar(uint8_t address, char val) { // uint8_t byteVal = DISPLAY_byteForChar(val); // DISPLAY_writeByte(address, byteVal); // } // // void DISPLAY_setupNormalOperation() { // DISPLAY_writeByte(SHUTDOWN_ADDRESS, 0xFF); // } // // void DISPLAY_test() { // // Note: these data byte values just come straight from the AS1108 datasheet. // DISPLAY_writeByte(DISPLAY_TEST_ADDRESS, 0xFF); // } // // void DISPLAY_setNoDecodeMode() { // DISPLAY_writeByte(DECODE_MODE_ADDRESS, 0x00); // } // // void DISPLAY_setDecodeAllMode() { // DISPLAY_writeByte(DECODE_MODE_ADDRESS, 0x0F); // } // // void DISPLAY_setScanLimit(uint8_t byte) { // DISPLAY_writeByte(SCAN_LIMIT_ADDRESS, byte); // } // // // MARK: Intensity control register // void DISPLAY_setBrightness(uint8_t byte) { // DISPLAY_writeByte(INTENSITY_CONTROL_ADDRESS, byte); // } // // // MARK: Feature Register controls // // /* Note: The feature register is byte initialized to 0 on power // up so I have a global to prevent overwriting existing values // when using the functions below */ // uint8_t featureData = 0x00; // // void DISPLAY_setCodeBMode() { // // bit-wise trick to set 0 at feature decode select bit without changing other bites // featureData &= ~(1 << FEATURE_DECODE_SELECT); // DISPLAY_writeByte(FEATURE_ADDRESS, featureData); // } // // void DISPLAY_setHexDecodeMode() { // featureData |= (1 << FEATURE_DECODE_SELECT); // DISPLAY_writeByte(FEATURE_ADDRESS, featureData); // } // // void DISPLAY_setSPIEnable() { // featureData |= (1 << FEATURE_SPI_ENABLE); // DISPLAY_writeByte(FEATURE_ADDRESS, featureData); // } // // void DISPLAY_enableBlinking() { // featureData |= (1 << FEATURE_BLINK_ENABLE); // DISPLAY_writeByte(FEATURE_ADDRESS, featureData); // } // // void DISPLAY_disableBlinking() { // featureData &= ~(1 << FEATURE_BLINK_ENABLE); // DISPLAY_writeByte(FEATURE_ADDRESS, featureData); // } // // void DISPLAY_setLowBlinkFrequency() { // featureData |= (1 << FEATURE_BLINK_FREQ_SELECT); // DISPLAY_writeByte(FEATURE_ADDRESS, featureData); // } // // void DISPLAY_setHighBlinkFrequency() { // featureData &= ~(1 << FEATURE_BLINK_FREQ_SELECT); // DISPLAY_writeByte(FEATURE_ADDRESS, featureData); // } // // void DISPLAY_reset() { // featureData |= (1 << FEATURE_CONTROL_REGISTER_RESET); // DISPLAY_writeByte(FEATURE_ADDRESS, featureData); // } // // void DISPLAY_setExternalClock() { // featureData |= (1 << FEATURE_CLOCK_ENABLE); // DISPLAY_writeByte(FEATURE_ADDRESS, featureData); // } // // void DISPLAY_setInternalClock() { // featureData &= ~(1 << FEATURE_CLOCK_ENABLE); // DISPLAY_writeByte(FEATURE_ADDRESS, featureData); // } // // void DISPLAY_defaultConfig() { // DISPLAY_setupNormalOperation(); // DISPLAY_setScanLimit(3); // DISPLAY_setBrightness(0xCC); // DISPLAY_setNoDecodeMode(); // } // // void DISPLAY_defaultTest() { // for (int j = 0; j < 9; j++) { // DISPLAY_writeByte(DIGIT_0_ADDRESS, 1 << j); // DISPLAY_writeByte(DIGIT_1_ADDRESS, 1 << j); // DISPLAY_writeByte(DIGIT_2_ADDRESS, 1 << j); // DISPLAY_writeByte(DIGIT_3_ADDRESS, 1 << j); // _delay_ms(240); // } // } // // // MARK: No-decode digit and other values byte representations // uint8_t DISPLAY_byteForChar(char val) { // switch (val) // { // case 'a': // return 0b01111101; // case 'A': // return 0b01110111; // case 'b': // return 0b00011111; // case 'B': // return 0b01111111; // case 'c': // return 0b00001101; // case 'C': // return 0b01001110; // case 'd': // return 0b00111101; // case 'e': // return 0b01101111; // case 'E': // return 0b01001111; // case 'f': // case 'F': // return 0b01000111; // case 'g': // return 0b01111011; // case 'G': // return 0b01011110; // case 'o': // return 0b00011101; // case 'D': // case 'O': // case '0': // return 0b01111110; // case '1': // return 0b00110000; // case '2': // return 0b01101101; // case '3': // return 0b01111001; // case '4': // return 0b00110011; // case '5': // return 0b01011011; // case '6': // return 0b01011111; // case '7': // return 0b01110000; // case '8': // return 0b01111111; // case '9': // return 0b01110011; // case '-': // return 0b00000001; // default: // return 0; // } // }
the_stack_data/52770.c
#include <stdio.h> #include <stdbool.h> // a b xor // 0 0 0 // 0 1 1 // 1 0 1 // 1 1 0 void reverseArray(int a[], int len); void printArr(int arr[], int len); int main() { int arrEven[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; int arrOdd[] = {1, 2, 3, 4, 5, 6, 7}; printArr(arrEven, 10); reverseArray(arrEven, 10); printArr(arrEven, 10); printArr(arrOdd, 7); reverseArray(arrOdd, 7); printArr(arrOdd, 7); return 0; } void printArr(int arr[], int len) { printf("[ "); for (int i = 0; i < len; ++i) { printf("%d ", arr[i]); } printf("]\n"); } bool isEven(int num) { return (num % 2) == 0 ? true : false; } void inplaceSwap(int *x, int *y) { // x y // 0101 1001 *y = *x ^ *y;// 1100 *x = *x ^ *y;// 1001 *y = *x ^ *y;// 0101 } void reverseArray(int a[], int len) { int first, last; for (first = 0, last = len - 1; first < last; ++first, --last) { inplaceSwap(&a[first], &a[last]); } }
the_stack_data/75036.c
#include<stdio.h> #include<math.h> int main (){ double ab,r,pi=3.1418; printf("Insira o valor da base do cilindro\n"); scanf("%lf",&ab); r = sqrt(ab/pi); printf("O valor do raio %lf",r); return 0; }
the_stack_data/179831173.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFSIZE 4096 #define SLEN 81 void append(FILE * source, FILE * dest); int main(int argc, char * argv[]){ FILE * fa, * fs; //fa 指向目标文件,fs 指向源文件 int files = 0; //附加的文件数量 char file_app[SLEN]; //目标文件名 char file_src[SLEN]; //源文件名 int ch; int i; if(argc <=3){ printf("Uasge: %s[source][dest...]\n",argv[0]); exit(EXIT_FAILURE); } files = argc - 2; if((fa = fopen(argv[1],"a+")) == NULL){ fprintf(stderr,"Can't open %s\n",argv[1]); exit(EXIT_FAILURE); } if(setvbuf(fa,NULL,_IOFBF,BUFSIZE) != 0){ fputs("Can't create input buff\n",stderr); exit(EXIT_FAILURE); } for(i=0; i < argc -2; i++){ if(strcmp(argv[1],argv[i+2]) ==0) fputs("Can't append file to itself\n",stderr); else if((fs =fopen(argv[i+2],"r")) == NULL) fprintf(stderr,"Can't open %s",argv[i+2]); else{ if(setvbuf(fs,NULL,_IOFBF,BUFSIZE)!=0){ fputs("Can't create input buff\n",stderr); continue; } append(fs,fa); if(ferror(fs)!=0) fprintf(stderr,"Error in reading file %s\n",argv[1]); if(ferror(fa)!=0) fprintf(stderr,"Error in writing file %s\n",argv[i+2]); fclose(fs); printf("File %s appended.\n",argv[1]); printf("Next file is %s\n",argv[i+3]); } } printf("Done appending %d files appended.\n",files); rewind(fa); printf("%s contents:\n",argv[1]); while((ch = getc(fa))!= EOF) putchar(ch); puts("Done displaying."); fclose(fa); return 0; } void append(FILE * source,FILE * dest){ size_t bytes; static char temp[BUFSIZE]; while((bytes = fread(temp,sizeof(char),BUFSIZE,source))>0) fwrite(temp,sizeof(char),bytes,dest); }
the_stack_data/218894222.c
/* * Copyright (c) 1996, 1998 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. */ /* * Portions Copyright (c) 1995 by International Business Machines, Inc. * * International Business Machines, Inc. (hereinafter called IBM) grants * permission under its copyrights to use, copy, modify, and distribute this * Software with or without fee, provided that the above copyright notice and * all paragraphs of this notice appear in all copies, and that the name of IBM * not be used in connection with the marketing of any product incorporating * the Software or modifications thereof, without specific, written prior * permission. * * To the extent it has a right to do so, IBM grants an immunity from suit * under its patents, if any, for the use, sale or manufacture of products to * the extent that such products are used for performing Domain Name System * dynamic updates in TCP/IP networks by means of the Software. No immunity is * granted for any product per se or for any other function of any product. * * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. */ #include <sys/cdefs.h> #include <sys/types.h> #include <sys/types.h> #include <sys/param.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> #include <ctype.h> #include <resolv.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define Assert(Cond) if (!(Cond)) abort() static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char Pad64 = '='; /* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) The following encoding technique is taken from RFC 1521 by Borenstein and Freed. It is reproduced here in a slightly edited form for convenience. A 65-character subset of US-ASCII is used, enabling 6 bits to be represented per printable character. (The extra 65th character, "=", is used to signify a special processing function.) The encoding process represents 24-bit groups of input bits as output strings of 4 encoded characters. Proceeding from left to right, a 24-bit input group is formed by concatenating 3 8-bit input groups. These 24 bits are then treated as 4 concatenated 6-bit groups, each of which is translated into a single digit in the base64 alphabet. Each 6-bit group is used as an index into an array of 64 printable characters. The character referenced by the index is placed in the output string. Table 1: The Base64 Alphabet Value Encoding Value Encoding Value Encoding Value Encoding 0 A 17 R 34 i 51 z 1 B 18 S 35 j 52 0 2 C 19 T 36 k 53 1 3 D 20 U 37 l 54 2 4 E 21 V 38 m 55 3 5 F 22 W 39 n 56 4 6 G 23 X 40 o 57 5 7 H 24 Y 41 p 58 6 8 I 25 Z 42 q 59 7 9 J 26 a 43 r 60 8 10 K 27 b 44 s 61 9 11 L 28 c 45 t 62 + 12 M 29 d 46 u 63 / 13 N 30 e 47 v 14 O 31 f 48 w (pad) = 15 P 32 g 49 x 16 Q 33 h 50 y Special processing is performed if fewer than 24 bits are available at the end of the data being encoded. A full encoding quantum is always completed at the end of a quantity. When fewer than 24 input bits are available in an input group, zero bits are added (on the right) to form an integral number of 6-bit groups. Padding at the end of the data is performed using the '=' character. Since all base64 input is an integral number of octets, only the ------------------------------------------------- following cases can arise: (1) the final quantum of encoding input is an integral multiple of 24 bits; here, the final unit of encoded output will be an integral multiple of 4 characters with no "=" padding, (2) the final quantum of encoding input is exactly 8 bits; here, the final unit of encoded output will be two characters followed by two "=" padding characters, or (3) the final quantum of encoding input is exactly 16 bits; here, the final unit of encoded output will be three characters followed by one "=" padding character. */ int b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) { size_t datalength = 0; u_char input[3]; u_char output[4]; size_t i; while (2 < srclength) { input[0] = *src++; input[1] = *src++; input[2] = *src++; srclength -= 3; output[0] = input[0] >> 2; output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); output[3] = input[2] & 0x3f; Assert(output[0] < 64); Assert(output[1] < 64); Assert(output[2] < 64); Assert(output[3] < 64); if (datalength + 4 > targsize) return (-1); target[datalength++] = Base64[output[0]]; target[datalength++] = Base64[output[1]]; target[datalength++] = Base64[output[2]]; target[datalength++] = Base64[output[3]]; } /* Now we worry about padding. */ if (0 != srclength) { /* Get what's left. */ input[0] = input[1] = input[2] = '\0'; for (i = 0; i < srclength; i++) input[i] = *src++; output[0] = input[0] >> 2; output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); Assert(output[0] < 64); Assert(output[1] < 64); Assert(output[2] < 64); if (datalength + 4 > targsize) return (-1); target[datalength++] = Base64[output[0]]; target[datalength++] = Base64[output[1]]; if (srclength == 1) target[datalength++] = Pad64; else target[datalength++] = Base64[output[2]]; target[datalength++] = Pad64; } if (datalength >= targsize) return (-1); target[datalength] = '\0'; /* Returned value doesn't count \0. */ return (datalength); } /* skips all whitespace anywhere. converts characters, four at a time, starting at (or after) src from base - 64 numbers into three 8 bit bytes in the target area. it returns the number of data bytes stored at the target, or -1 on error. */ int b64_pton(src, target, targsize) char const *src; u_char *target; size_t targsize; { int tarindex, state, ch; char *pos; state = 0; tarindex = 0; while ((ch = *src++) != '\0') { if (isspace((unsigned char)ch)) /* Skip whitespace anywhere. */ continue; if (ch == Pad64) break; pos = strchr(Base64, ch); if (pos == 0) /* A non-base64 character. */ return (-1); switch (state) { case 0: if (target) { if ((size_t)tarindex >= targsize) return (-1); target[tarindex] = (pos - Base64) << 2; } state = 1; break; case 1: if (target) { if ((size_t)tarindex + 1 >= targsize) return (-1); target[tarindex] |= (pos - Base64) >> 4; target[tarindex+1] = ((pos - Base64) & 0x0f) << 4 ; } tarindex++; state = 2; break; case 2: if (target) { if ((size_t)tarindex + 1 >= targsize) return (-1); target[tarindex] |= (pos - Base64) >> 2; target[tarindex+1] = ((pos - Base64) & 0x03) << 6; } tarindex++; state = 3; break; case 3: if (target) { if ((size_t)tarindex >= targsize) return (-1); target[tarindex] |= (pos - Base64); } tarindex++; state = 0; break; default: abort(); } } /* * We are done decoding Base-64 chars. Let's see if we ended * on a byte boundary, and/or with erroneous trailing characters. */ if (ch == Pad64) { /* We got a pad char. */ ch = *src++; /* Skip it, get next. */ switch (state) { case 0: /* Invalid = in first position */ case 1: /* Invalid = in second position */ return (-1); case 2: /* Valid, means one byte of info */ /* Skip any number of spaces. */ for ((void)NULL; ch != '\0'; ch = *src++) if (!isspace((unsigned char)ch)) break; /* Make sure there is another trailing = sign. */ if (ch != Pad64) return (-1); ch = *src++; /* Skip the = */ /* Fall through to "single trailing =" case. */ /* FALLTHROUGH */ case 3: /* Valid, means two bytes of info */ /* * We know this char is an =. Is there anything but * whitespace after it? */ for ((void)NULL; ch != '\0'; ch = *src++) if (!isspace((unsigned char)ch)) return (-1); /* * Now make sure for cases 2 and 3 that the "extra" * bits that slopped past the last full byte were * zeros. If we don't check them, they become a * subliminal channel. */ if (target && target[tarindex] != 0) return (-1); } } else { /* * We ended by seeing the end of the string. Make sure we * have no partial bytes lying around. */ if (state != 0) return (-1); } return (tarindex); }
the_stack_data/68888074.c
void pasm ( void ) { //set pindirs, 1 set_pindirs(1); //; Set pin to output //again: label("again"); //set pins, 1 [30] ; Drive pin high and then delay for one cycle set_pins(1,30); //set pins, 0 [29]; Drive pin low set_pins(0,29); //jmp again ; Set PC to label `again` jmp("again"); }
the_stack_data/161080132.c
#include <stdio.h> void sort (int m[][2], int row){ int sorted_id=0; for(int i=0;i<row-1;i++,sorted_id++){ int max_id=sorted_id; for(int j=sorted_id+1;j<row;j++){ if(m[j][0]>m[max_id][0])max_id=j; else if(m[j][0]==m[max_id][0] && m[j][1]>m[max_id][1])max_id=j; } if(max_id!=sorted_id){ int temp[]={m[max_id][0],m[max_id][1]}; m[max_id][0] = m[sorted_id][0]; m[max_id][1] = m[sorted_id][1]; m[sorted_id][0] = temp[0]; m[sorted_id][1] = temp[1]; } } } int main(){ puts("Enter the number of value-pairs:"); int n; scanf("%d",&n); //3 int a[n][2]; for(int i=0;i<n;i++){ printf("Input value-pair:"); scanf("%d%d",&a[i][0],&a[i][1]);// 4 2 /*Input value-pair: 1 7 Input value-paer:4 5 */ } sort(a,n); puts("The sorted result is"); printf("{"); for(int i=0;i<n;i++){ printf("{%d, %d}", a[i][0], a[i][1]); if(i!=n-1)printf(", "); } printf("}\n"); }
the_stack_data/220455351.c
#include<stdio.h> #include<stdlib.h> int main (){ int x,y,z=1,i; scanf("%d",&x); for (i = 1; i <=x; i++) { printf("%.d ",i); printf("%.d ",i*i); printf("%.d\n",i*i*i); } return 0; }
the_stack_data/132883.c
#include <stdio.h> #include <stdlib.h> typedef struct Node { int data; struct Node * next; }Node; Node * removeDuplicates( Node * head ) { if ( !head ) { return; } Node * tmp = head; while ( tmp ) { while ( tmp->next && tmp->data == tmp->next->data ) { tmp->next = tmp->next->next; } tmp = tmp->next; } return head; } Node * insert( Node * head, int data ) { Node *p = (Node *) malloc( sizeof(Node) ); p->data = data; p->next = NULL; if ( head == NULL ) { head = p; } else if( head->next == NULL ) { head->next = p; } else { Node * start = head; while ( start->next != NULL ) { start = start->next; } start->next = p; } return head; } void display( Node * head ) { Node * start = head; while ( start ) { printf("%d ", start->data); start = start->next; } } int main() { int T, data; scanf("%d", &T); Node * head = NULL; while ( T-- ) { scanf("%d", &data); head = insert( head, data ); } head = removeDuplicates( head ); display( head ); return 0; }
the_stack_data/95570.c
// RUN: %clang_cc1 -fprofile-instrument=clang -emit-llvm %s -o - | FileCheck %s // RUN: echo "fun:test1" > %t-func.list // RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-func.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC // RUN: echo "src:%s" | sed -e 's/\\/\\\\/g' > %t-file.list // RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-file.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FILE // RUN: echo -e "[clang]\nfun:test1\n[llvm]\nfun:test2" > %t-section.list // RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t-section.list -emit-llvm %s -o - | FileCheck %s --check-prefix=SECTION // RUN: echo -e "fun:test*\n!fun:test1" > %t-exclude.list // RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-exclude.list -emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE // RUN: echo "!fun:test1" > %t-exclude-only.list // RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE unsigned i; // CHECK-NOT: noprofile // CHECK: @test1 // FUNC-NOT: noprofile // FUNC: @test1 // FILE-NOT: noprofile // FILE: @test1 // SECTION: noprofile // SECTION: @test1 // EXCLUDE: noprofile // EXCLUDE: @test1 unsigned test1() { // CHECK: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0) // FUNC: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0) // FILE: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0) // SECTION-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0) // EXCLUDE-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test1, i64 0, i64 0) return i + 1; } // CHECK-NOT: noprofile // CHECK: @test2 // FUNC: noprofile // FUNC: @test2 // FILE-NOT: noprofile // FILE: @test2 // SECTION-NOT: noprofile // SECTION: @test2 // EXCLUDE-NOT: noprofile // EXCLUDE: @test2 unsigned test2() { // CHECK: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test2, i64 0, i64 0) // FUNC-NOT: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test2, i64 0, i64 0) // FILE: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test2, i64 0, i64 0) // SECTION: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test2, i64 0, i64 0) // EXCLUDE: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test2, i64 0, i64 0) return i - 1; }
the_stack_data/117328560.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_recursive_factorial.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: albarbos <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/11/07 11:00:04 by albarbos #+# #+# */ /* Updated: 2017/11/07 11:00:05 by albarbos ### ########.fr */ /* */ /* ************************************************************************** */ int ft_recursive_factorial(int nb) { int temp; temp = 1; if (nb == 0 || nb == 1) return (1); else if (nb >= 2 && nb < 13) { temp = ft_recursive_factorial(nb - 1); } else return (0); return (nb * temp); }
the_stack_data/67325469.c
/* Copyright (C) 2001 Free Software Foundation, Inc. */ /* { dg-do preprocess } */ /* { dg-options "-fpreprocessed" } */ /* Source: Neil Booth, 16 Sep 2001. This file, with an indented line marker, is not possible without user editing of preprocessed output, or the user using -fpreprocessed on raw source. Nevertheless, we should not segfault. This is a test that we don't back up two tokens in cpplib.c - one to back up over the number, and one when we recognise that it's not a valid directive in preprocessed input. */ # 1 "foo.c"
the_stack_data/165768057.c
/* Not copyrighted 1990 Mark Adler */ #include <stdio.h> int main(int argc, const char *argv[]) /* Generate a table for a byte-wise 32-bit CRC calculation on the polynomial: x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. Polynomials over GF(2) are represented in binary, one bit per coefficient, with the lowest powers in the most significant bit. Then adding polynomials is just exclusive-or, and multiplying a polynomial by x is a right shift by one. If we call the above polynomial p, and represent a byte as the polynomial q, also with the lowest power in the most significant bit (so the byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, where a mod b means the remainder after dividing a by b. This calculation is done using the shift-register method of multiplying and taking the remainder. The register is initialized to zero, and for each incoming bit, x^32 is added mod p to the register if the bit is a one (where x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by x (which is shifting right by one and adding x^32 mod p if the bit shifted out is a one). We start with the highest power (least significant bit) of q and repeat for all eight bits of q. The table is simply the CRC of all possible eight bit values. This is all the information needed to generate CRC's on data a byte at a time for all combinations of CRC register values and incoming bytes. The table is written to stdout as 256 long hexadecimal values in C language format. */ { unsigned long c; /* crc shift register */ unsigned long e; /* polynomial exclusive-or pattern */ int i; /* counter for all possible eight bit values */ int k; /* byte being shifted into crc apparatus */ /* terms of polynomial defining this crc (except x^32): */ static int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; /* Make exclusive-or pattern from polynomial (0xedb88320) */ e = 0; for (i = 0; i < sizeof(p)/sizeof(int); i++) e |= 1L << (31 - p[i]); /* Compute and print table of CRC's, five per line */ printf(" 0x00000000L"); for (i = 1; i < 256; i++) { c = i; /* The idea to initialize the register with the byte instead of * zero was stolen from Haruhiko Okumura's ar002 */ for (k = 8; k; k--) c = c & 1 ? (c >> 1) ^ e : c >> 1; printf(i % 5 ? ", 0x%08lxL" : ",\n 0x%08lxL", c); } putchar('\n'); return 0; }
the_stack_data/89199954.c
// To test that we can count when a loop can be sliced away. void main(int x){ int a,b,c,d,y; x = 0; /*OUT*/ while (x < 10){ /*OUT*/ a = b; /*OUT*/ c = d; /*OUT*/ x++; /*OUT*/ } return; /*OUT*/ _SLICE(y); }
the_stack_data/26701013.c
#include <stdio.h> #include <math.h> #include <stdbool.h> double ran1(double idum); double snippet (double ia, double idumx, double idum) { idum = idumx; int j = 0; double am = 0; double e = 0; double s = 0; double v1 = 0; double v2 = 0; double x = 0; double y = 0; if (ia <= 4)//change return -1000 + ia;//change if (ia < 6) { x = 1.0; for (j=1;j<=ia;j++) x *= ran1((int)idum); x = -log(x); } else { do { do { v1 += idumx; v2 = 2.0 * idumx - 1.0; } while (v1 * v1 + v2 * v2 > 1.0); y = v2 / v1; am = ia - 1; s = sqrt(2.0 * am + 2.0); x = s * y + am; } while (x <= 0.0); } return x; } double ran1(double idum){ int IA=16807; int IM=2147483647; int IQ=127773; int IR=2836; int NTAB=32; int NDIV=(1+(IM-1)/NTAB); double EPS=3.0e-16; double AM=1.0/IM; double RNMX=(1.0-EPS); int iy=0; int iv[NTAB] ; int j,k; double temp; if (idum <= 0 || iy == 0) { if (-idum < 1) idum=1; else idum = -idum; for (j=NTAB+7;j>=0;j--) { k= (int) (idum/IQ); idum=IA*(idum-k*IQ)-IR*k; if (idum < 0) idum += IM; if (j < NTAB) iv[j] = (int) idum; } iy=iv[0]; } k= (int) (idum/IQ); idum=IA*(idum-k*IQ)-IR*k; if (idum < 0) idum += IM; j=iy/NDIV; iy=iv[j]; iv[j] = (int) idum; if ((temp=AM*iy) > RNMX) return RNMX; else return temp; }
the_stack_data/144005.c
/* 8bit Bitmap to NES pattern table */ #include <stdio.h> #include <stdlib.h> #include <string.h> /* 情報ヘッダ */ struct DatHead { int isize; /* 情報ヘッダサイズ */ int width; /* 幅 */ int height; /* 高さ */ unsigned short planes; /* プレーン数 */ unsigned short bits; /* 色ビット数 */ unsigned int ctype; /* 圧縮形式 */ unsigned int gsize; /* 画像データサイズ */ int xppm; /* X方向解像度 */ int yppm; /* Y方向解像度 */ unsigned int cnum; /* 使用色数 */ unsigned int inum; /* 重要色数 */ }; int main(int argc, char* argv[]) { FILE* fpR = NULL; FILE* fpW = NULL; int rc = 0; char fh[14]; int pal[256]; struct DatHead dh; unsigned char bh, bl; unsigned char mh[4]; int i, j, k, y, x, a; char bmp[16384]; char chr[4096]; /* 引数チェック */ rc++; if (argc < 3) { fprintf(stderr, "usage: bmp2chr input.bmp output.chr\n"); goto ENDPROC; } /* 読み込みファイルをオープン */ rc++; if (NULL == (fpR = fopen(argv[1], "rb"))) { fprintf(stderr, "ERROR: Could not open: %s\n", argv[1]); goto ENDPROC; } /* ファイルヘッダを読み込む */ rc++; if (sizeof(fh) != fread(fh, 1, sizeof(fh), fpR)) { fprintf(stderr, "ERROR: Invalid file header.\n"); goto ENDPROC; } /* 先頭2バイトだけ読む */ rc++; if (strncmp(fh, "BM", 2)) { fprintf(stderr, "ERROR: Inuput file is not bitmap.\n"); goto ENDPROC; } /* 情報ヘッダを読み込む */ rc++; if (sizeof(dh) != fread(&dh, 1, sizeof(dh), fpR)) { fprintf(stderr, "ERROR: Invalid bitmap file header.\n"); goto ENDPROC; } printf("INPUT: width=%d, height=%d, bits=%d(%d), cmp=%d\n", dh.width, dh.height, (int)dh.bits, dh.cnum, dh.ctype); /* 128x128でなければエラー扱い */ rc++; if (128 != dh.width || 128 != dh.height) { fprintf(stderr, "ERROR: Invalid input bitmap size. (128x128 only)"); goto ENDPROC; } /* 8ビットカラー以外は弾く */ rc++; if (8 != dh.bits) { fprintf(stderr, "ERROR: This program supports only 8bit color.\n"); goto ENDPROC; } /* 無圧縮以外は弾く */ rc++; if (dh.ctype) { fprintf(stderr, "ERROR: This program supports only none-compress type.\n"); goto ENDPROC; } /* パレットを読み飛ばす */ rc++; if (sizeof(pal) != fread(pal, 1, sizeof(pal), fpR)) { fprintf(stderr, "ERROR: Could not read palette data.\n"); goto ENDPROC; } /* 画像データを上下反転しながら読み込む */ rc++; for (i = 127; 0 <= i; i--) { if (128 != fread(&bmp[i * 128], 1, 128, fpR)) { fprintf(stderr, "ERROR: Could not read graphic data.\n"); goto ENDPROC; } } /* 色情報を mod 4 (0~3) にしておく*/ for (i = 0; i < 16384; i++) { bmp[i] = bmp[i] % 4; } /* Bitmap を CHR に変換 */ for (i = 0; i < 256; i++) { for (j = 0; j < 8; j++) { bh = 0; bl = 0; x = i % 16 * 8; y = (i / 16) * 8 + j; a = y * 128 + x; for (k = 0; k < 8; k++, a++) { bh <<= 1; bh |= bmp[a] & 1; bl <<= 1; bl |= bmp[a] & 2 ? 1 : 0; } chr[i * 16 + j] = bh; chr[i * 16 + 8 + j] = bl; } } /* 書き込みファイルをオープンしてchrを書き込む */ rc++; if (NULL == (fpW = fopen(argv[2], "wb"))) { fprintf(stderr, "ERROR: Could not open: %s\n", argv[2]); goto ENDPROC; } if (sizeof(chr) != fwrite(chr, 1, sizeof(chr), fpW)) { fprintf(stderr, "ERROR: File write error: %s\n", argv[2]); goto ENDPROC; } rc = 0; printf("succeed.\n"); /* 終了処理 */ ENDPROC: if (fpR) { fclose(fpR); } if (fpW) { fclose(fpW); } return rc; }
the_stack_data/605982.c
//{{BLOCK(Start) //====================================================================== // // Start, 64x32@8, // + palette 3 entries, not compressed // + 32 tiles Metatiled by 8x4 not compressed // Total size: 6 + 2048 = 2054 // // Time-stamp: 2017-04-15, 15:01:05 // Exported by Cearn's GBA Image Transmogrifier, v0.8.6 // ( http://www.coranac.com/projects/#grit ) // //====================================================================== const unsigned short StartTiles[1024] __attribute__((aligned(4)))= { 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0202,0x0202,0x0002, 0x0200,0x0000,0x0000,0x0200,0x0002,0x0000,0x0000,0x0000, 0x0002,0x0000,0x0000,0x0000,0x0200,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0202,0x0202,0x0202, 0x0000,0x0000,0x0000,0x0002,0x0002,0x0000,0x0000,0x0002, 0x0000,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0002, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0202,0x0002,0x0000,0x0200, 0x0000,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0002, 0x0000,0x0000,0x0200,0x0000,0x0000,0x0000,0x0200,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0202, 0x0002,0x0000,0x0000,0x0002,0x0002,0x0000,0x0000,0x0002, 0x0200,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0002, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0202,0x0202,0x0002,0x0000, 0x0000,0x0000,0x0200,0x0000,0x0000,0x0000,0x0000,0x0002, 0x0000,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0002, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0202,0x0202,0x0202,0x0202, 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0002,0x0000, 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0002,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0202,0x0002,0x0000,0x0000,0x0000,0x0200,0x0202, 0x0000,0x0000,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000, 0x0002,0x0000,0x0000,0x0000,0x0200,0x0000,0x0000,0x0200, 0x0000,0x0202,0x0202,0x0002,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0002, 0x0002,0x0000,0x0000,0x0002,0x0002,0x0000,0x0000,0x0002, 0x0002,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0002, 0x0000,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0200,0x0000,0x0000,0x0000,0x0002,0x0000, 0x0000,0x0000,0x0202,0x0202,0x0000,0x0200,0x0000,0x0000, 0x0000,0x0200,0x0000,0x0000,0x0000,0x0002,0x0000,0x0000, 0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0200,0x0000,0x0000,0x0002,0x0000,0x0002,0x0000,0x0202, 0x0202,0x0002,0x0000,0x0002,0x0000,0x0200,0x0000,0x0002, 0x0000,0x0200,0x0000,0x0002,0x0000,0x0000,0x0002,0x0002, 0x0000,0x0000,0x0002,0x0002,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0200,0x0000,0x0202,0x0202,0x0002,0x0000, 0x0000,0x0200,0x0000,0x0000,0x0000,0x0000,0x0002,0x0000, 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0200,0x0000, 0x0000,0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0002,0x0000, 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0002,0x0000, 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0002,0x0000, 0x0000,0x0000,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, }; const unsigned short StartPal[4] __attribute__((aligned(4)))= { 0x0000,0x0000,0x7FFF, }; //}}BLOCK(Start)
the_stack_data/160998.c
struct a { int b }; struct { struct a c[4] } d[] = {{.c = {}}};
the_stack_data/178266308.c
static void foo(enum bar baz); /* * check-name: enum not in scope * check-known-to-fail */
the_stack_data/109052.c
/*- * Copyright (c) 2008-2015 Varnish Software AS * All rights reserved. * * Author: Poul-Henning Kamp <[email protected]> * * SPDX-License-Identifier: BSD-2-Clause * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifdef VTEST_WITH_VTC_VARNISH #include "config.h" #include <sys/types.h> #include <sys/socket.h> #include <fcntl.h> #include <fnmatch.h> #include <inttypes.h> #include <poll.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "vtc.h" #include "vapi/vsc.h" #include "vapi/vsl.h" #include "vapi/vsm.h" #include "vcli.h" #include "vjsn.h" #include "vre.h" #include "vsub.h" #include "vtcp.h" #include "vtim.h" struct varnish { unsigned magic; #define VARNISH_MAGIC 0x208cd8e3 char *name; struct vtclog *vl; VTAILQ_ENTRY(varnish) list; struct vsb *args; int fds[4]; pid_t pid; double syntax; pthread_t tp; pthread_t tp_vsl; int expect_exit; int cli_fd; int vcl_nbr; char *workdir; char *jail; char *proto; struct vsm *vsm_vsl; struct vsm *vsm_vsc; struct vsc *vsc; int has_a_arg; unsigned vsl_tag_count[256]; volatile int vsl_rec; volatile int vsl_idle; }; #define NONSENSE "%XJEIFLH|)Xspa8P" static VTAILQ_HEAD(, varnish) varnishes = VTAILQ_HEAD_INITIALIZER(varnishes); /********************************************************************** * Ask a question over CLI */ static enum VCLI_status_e varnish_ask_cli(const struct varnish *v, const char *cmd, char **repl) { int i; unsigned retval; char *r; if (cmd != NULL) { vtc_dump(v->vl, 4, "CLI TX", cmd, -1); i = write(v->cli_fd, cmd, strlen(cmd)); if (i != strlen(cmd) && !vtc_stop) vtc_fatal(v->vl, "CLI write failed (%s) = %u %s", cmd, errno, strerror(errno)); i = write(v->cli_fd, "\n", 1); if (i != 1 && !vtc_stop) vtc_fatal(v->vl, "CLI write failed (%s) = %u %s", cmd, errno, strerror(errno)); } i = VCLI_ReadResult(v->cli_fd, &retval, &r, vtc_maxdur); if (i != 0 && !vtc_stop) vtc_fatal(v->vl, "CLI failed (%s) = %d %u %s", cmd != NULL ? cmd : "NULL", i, retval, r); vtc_log(v->vl, 3, "CLI RX %u", retval); vtc_dump(v->vl, 4, "CLI RX", r, -1); if (repl != NULL) *repl = r; else free(r); return ((enum VCLI_status_e)retval); } /********************************************************************** * */ static void wait_stopped(const struct varnish *v) { char *r = NULL; enum VCLI_status_e st; vtc_log(v->vl, 3, "wait-stopped"); while (1) { st = varnish_ask_cli(v, "status", &r); if (st != CLIS_OK) vtc_fatal(v->vl, "CLI status command failed: %u %s", st, r); if (!strcmp(r, "Child in state stopped")) { free(r); break; } free(r); r = NULL; (void)usleep(200000); } } /********************************************************************** * */ static void wait_running(const struct varnish *v) { char *r = NULL; enum VCLI_status_e st; while (1) { vtc_log(v->vl, 3, "wait-running"); st = varnish_ask_cli(v, "status", &r); if (st != CLIS_OK) vtc_fatal(v->vl, "CLI status command failed: %u %s", st, r); if (!strcmp(r, "Child in state stopped")) vtc_fatal(v->vl, "Child stopped before running: %u %s", st, r); if (!strcmp(r, "Child in state running")) { free(r); r = NULL; st = varnish_ask_cli(v, "debug.listen_address", &r); if (st != CLIS_OK) vtc_fatal(v->vl, "CLI status command failed: %u %s", st, r); free(r); break; } free(r); r = NULL; (void)usleep(200000); } } /********************************************************************** * Varnishlog gatherer thread */ static void * varnishlog_thread(void *priv) { struct varnish *v; struct VSL_data *vsl; struct vsm *vsm; struct VSL_cursor *c; enum VSL_tag_e tag; uint32_t vxid; unsigned len; const char *tagname, *data; int type, i, opt; struct vsb *vsb = NULL; CAST_OBJ_NOTNULL(v, priv, VARNISH_MAGIC); vsl = VSL_New(); AN(vsl); vsm = v->vsm_vsl; c = NULL; opt = 0; while (v->fds[1] > 0 || c != NULL) { //lint !e845 bug in flint if (c == NULL) { if (vtc_error) break; VTIM_sleep(0.1); (void)VSM_Status(vsm); c = VSL_CursorVSM(vsl, vsm, opt); if (c == NULL) { vtc_log(v->vl, 3, "vsl|%s", VSL_Error(vsl)); VSL_ResetError(vsl); continue; } } AN(c); opt = VSL_COPT_TAIL; while (1) { i = VSL_Next(c); if (i != 1) break; v->vsl_rec = 1; tag = VSL_TAG(c->rec.ptr); vxid = VSL_ID(c->rec.ptr); if (tag == SLT__Batch) continue; tagname = VSL_tags[tag]; len = VSL_LEN(c->rec.ptr); type = VSL_CLIENT(c->rec.ptr) ? 'c' : VSL_BACKEND(c->rec.ptr) ? 'b' : '-'; data = VSL_CDATA(c->rec.ptr); v->vsl_tag_count[tag]++; if (VSL_tagflags[tag] & SLT_F_BINARY) { if (vsb == NULL) vsb = VSB_new_auto(); VSB_clear(vsb); VSB_quote(vsb, data, len, VSB_QUOTE_HEX); AZ(VSB_finish(vsb)); /* +2 to skip "0x" */ vtc_log(v->vl, 4, "vsl| %10u %-15s %c [%s]", vxid, tagname, type, VSB_data(vsb) + 2); } else { vtc_log(v->vl, 4, "vsl| %10u %-15s %c %.*s", vxid, tagname, type, (int)len, data); } } if (i == 0) { /* Nothing to do but wait */ v->vsl_idle++; if (!(VSM_Status(vsm) & VSM_WRK_RUNNING)) { /* Abandoned - try reconnect */ VSL_DeleteCursor(c); c = NULL; } else { VTIM_sleep(0.1); } } else if (i == -2) { /* Abandoned - try reconnect */ VSL_DeleteCursor(c); c = NULL; } else break; } if (c) VSL_DeleteCursor(c); VSL_Delete(vsl); if (vsb != NULL) VSB_destroy(&vsb); return (NULL); } /********************************************************************** * Allocate and initialize a varnish */ static struct varnish * varnish_new(const char *name) { struct varnish *v; struct vsb *vsb; char buf[1024]; ALLOC_OBJ(v, VARNISH_MAGIC); AN(v); REPLACE(v->name, name); REPLACE(v->jail, ""); v->vl = vtc_logopen("%s", name); AN(v->vl); vsb = macro_expandf(v->vl, "${tmpdir}/%s", name); AN(vsb); v->workdir = strdup(VSB_data(vsb)); AN(v->workdir); VSB_destroy(&vsb); bprintf(buf, "rm -rf %s ; mkdir -p %s", v->workdir, v->workdir); AZ(system(buf)); v->args = VSB_new_auto(); v->cli_fd = -1; VTAILQ_INSERT_TAIL(&varnishes, v, list); return (v); } /********************************************************************** * Delete a varnish instance */ static void varnish_delete(struct varnish *v) { CHECK_OBJ_NOTNULL(v, VARNISH_MAGIC); vtc_logclose(v->vl); free(v->name); free(v->jail); free(v->workdir); VSB_destroy(&v->args); if (v->vsc != NULL) VSC_Destroy(&v->vsc, v->vsm_vsc); if (v->vsm_vsc != NULL) VSM_Destroy(&v->vsm_vsc); if (v->vsm_vsl != NULL) VSM_Destroy(&v->vsm_vsl); /* * We do not delete the workdir, it may contain stuff people * want (coredumps, shmlog/stats etc), and trying to divine * "may want" is just too much trouble. Leave it around and * nuke it at the start of the next test-run. */ /* XXX: MEMLEAK (?) */ FREE_OBJ(v); } /********************************************************************** * Varnish listener */ static void * varnish_thread(void *priv) { struct varnish *v; CAST_OBJ_NOTNULL(v, priv, VARNISH_MAGIC); return (vtc_record(v->vl, v->fds[0], NULL)); } /********************************************************************** * Launch a Varnish */ static void varnish_launch(struct varnish *v) { struct vsb *vsb, *vsb1; int i, nfd, asock; char abuf[128], pbuf[128]; struct pollfd fd[3]; enum VCLI_status_e u; const char *err; char *r = NULL; /* Create listener socket */ asock = VTCP_listen_on(default_listen_addr, NULL, 1, &err); if (err != NULL) vtc_fatal(v->vl, "Create CLI listen socket failed: %s", err); assert(asock > 0); VTCP_myname(asock, abuf, sizeof abuf, pbuf, sizeof pbuf); AZ(VSB_finish(v->args)); vtc_log(v->vl, 2, "Launch"); vsb = VSB_new_auto(); AN(vsb); VSB_cat(vsb, "cd ${pwd} &&"); VSB_printf(vsb, " exec varnishd %s -d -n %s", v->jail, v->workdir); VSB_cat(vsb, VSB_data(params_vsb)); if (leave_temp) { VSB_cat(vsb, " -p debug=+vcl_keep"); VSB_cat(vsb, " -p debug=+vmod_so_keep"); VSB_cat(vsb, " -p debug=+vsm_keep"); } VSB_cat(vsb, " -l 2m"); VSB_cat(vsb, " -p auto_restart=off"); VSB_cat(vsb, " -p syslog_cli_traffic=off"); VSB_cat(vsb, " -p thread_pool_min=10"); VSB_cat(vsb, " -p debug=+vtc_mode"); VSB_cat(vsb, " -p vsl_mask=+Debug"); VSB_cat(vsb, " -p h2_initial_window_size=1m"); VSB_cat(vsb, " -p h2_rx_window_low_water=64k"); if (!v->has_a_arg) { VSB_printf(vsb, " -a '%s'", default_listen_addr); if (v->proto != NULL) VSB_printf(vsb, ",%s", v->proto); } VSB_printf(vsb, " -M '%s %s'", abuf, pbuf); VSB_printf(vsb, " -P %s/varnishd.pid", v->workdir); if (vmod_path != NULL) VSB_printf(vsb, " -p vmod_path=%s", vmod_path); VSB_printf(vsb, " %s", VSB_data(v->args)); AZ(VSB_finish(vsb)); vtc_log(v->vl, 3, "CMD: %s", VSB_data(vsb)); vsb1 = macro_expand(v->vl, VSB_data(vsb)); AN(vsb1); VSB_destroy(&vsb); vsb = vsb1; vtc_log(v->vl, 3, "CMD: %s", VSB_data(vsb)); AZ(pipe(&v->fds[0])); AZ(pipe(&v->fds[2])); v->pid = fork(); assert(v->pid >= 0); if (v->pid == 0) { AZ(dup2(v->fds[0], 0)); assert(dup2(v->fds[3], 1) == 1); assert(dup2(1, 2) == 2); closefd(&v->fds[0]); closefd(&v->fds[1]); closefd(&v->fds[2]); closefd(&v->fds[3]); VSUB_closefrom(STDERR_FILENO + 1); AZ(execl("/bin/sh", "/bin/sh", "-c", VSB_data(vsb), (char*)0)); exit(1); } else { vtc_log(v->vl, 3, "PID: %ld", (long)v->pid); macro_def(v->vl, v->name, "pid", "%ld", (long)v->pid); macro_def(v->vl, v->name, "name", "%s", v->workdir); } closefd(&v->fds[0]); closefd(&v->fds[3]); v->fds[0] = v->fds[2]; v->fds[2] = v->fds[3] = -1; VSB_destroy(&vsb); AZ(pthread_create(&v->tp, NULL, varnish_thread, v)); /* Wait for the varnish to call home */ memset(fd, 0, sizeof fd); fd[0].fd = asock; fd[0].events = POLLIN; fd[1].fd = v->fds[1]; fd[1].events = POLLIN; fd[2].fd = v->fds[2]; fd[2].events = POLLIN; i = poll(fd, 2, vtc_maxdur * 1000 / 3); vtc_log(v->vl, 4, "CLIPOLL %d 0x%x 0x%x 0x%x", i, fd[0].revents, fd[1].revents, fd[2].revents); if (i == 0) vtc_fatal(v->vl, "FAIL timeout waiting for CLI connection"); if (fd[1].revents & POLLHUP) vtc_fatal(v->vl, "FAIL debug pipe closed"); if (!(fd[0].revents & POLLIN)) vtc_fatal(v->vl, "FAIL CLI connection wait failure"); nfd = accept(asock, NULL, NULL); closefd(&asock); if (nfd < 0) vtc_fatal(v->vl, "FAIL no CLI connection accepted"); v->cli_fd = nfd; vtc_log(v->vl, 3, "CLI connection fd = %d", v->cli_fd); assert(v->cli_fd >= 0); /* Receive the banner or auth response */ u = varnish_ask_cli(v, NULL, &r); if (vtc_error) return; if (u != CLIS_AUTH) vtc_fatal(v->vl, "CLI auth demand expected: %u %s", u, r); bprintf(abuf, "%s/_.secret", v->workdir); nfd = open(abuf, O_RDONLY); assert(nfd >= 0); assert(sizeof abuf >= CLI_AUTH_RESPONSE_LEN + 7); bstrcpy(abuf, "auth "); VCLI_AuthResponse(nfd, r, abuf + 5); closefd(&nfd); free(r); r = NULL; strcat(abuf, "\n"); u = varnish_ask_cli(v, abuf, &r); if (vtc_error) return; if (u != CLIS_OK) vtc_fatal(v->vl, "CLI auth command failed: %u %s", u, r); free(r); v->vsm_vsc = VSM_New(); AN(v->vsm_vsc); v->vsc = VSC_New(); AN(v->vsc); assert(VSM_Arg(v->vsm_vsc, 'n', v->workdir) > 0); AZ(VSM_Attach(v->vsm_vsc, -1)); v->vsm_vsl = VSM_New(); assert(VSM_Arg(v->vsm_vsl, 'n', v->workdir) > 0); AZ(VSM_Attach(v->vsm_vsl, -1)); AZ(pthread_create(&v->tp_vsl, NULL, varnishlog_thread, v)); } #define VARNISH_LAUNCH(v) \ do { \ CHECK_OBJ_NOTNULL(v, VARNISH_MAGIC); \ if (v->cli_fd < 0) \ varnish_launch(v); \ if (vtc_error) \ return; \ } while (0) /********************************************************************** * Start a Varnish */ static void varnish_listen(const struct varnish *v, char *la) { const char *a, *p, *n, *n2; char m[64], s[256]; unsigned first; n2 = ""; first = 1; while (*la != '\0') { n = la; la = strchr(la, ' '); AN(la); *la = '\0'; a = ++la; la = strchr(la, ' '); AN(la); *la = '\0'; p = ++la; la = strchr(la, '\n'); AN(la); *la = '\0'; la++; AN(*n); AN(*a); AN(*p); if (*p == '-') { bprintf(s, "%s", a); a = "0.0.0.0"; p = "0"; } else if (strchr(a, ':')) { bprintf(s, "[%s]:%s", a, p); } else { bprintf(s, "%s:%s", a, p); } if (first) { vtc_log(v->vl, 2, "Listen on %s %s", a, p); macro_def(v->vl, v->name, "addr", "%s", a); macro_def(v->vl, v->name, "port", "%s", p); macro_def(v->vl, v->name, "sock", "%s", s); first = 0; } if (!strcmp(n, n2)) continue; bprintf(m, "%s_addr", n); macro_def(v->vl, v->name, m, "%s", a); bprintf(m, "%s_port", n); macro_def(v->vl, v->name, m, "%s", p); bprintf(m, "%s_sock", n); macro_def(v->vl, v->name, m, "%s", s); n2 = n; } } static void varnish_start(struct varnish *v) { enum VCLI_status_e u; char *resp = NULL; VARNISH_LAUNCH(v); vtc_log(v->vl, 2, "Start"); u = varnish_ask_cli(v, "start", &resp); if (vtc_error) return; if (u != CLIS_OK) vtc_fatal(v->vl, "CLI start command failed: %u %s", u, resp); wait_running(v); free(resp); resp = NULL; u = varnish_ask_cli(v, "debug.xid 999", &resp); if (vtc_error) return; if (u != CLIS_OK) vtc_fatal(v->vl, "CLI debug.xid command failed: %u %s", u, resp); free(resp); resp = NULL; u = varnish_ask_cli(v, "debug.listen_address", &resp); if (vtc_error) return; if (u != CLIS_OK) vtc_fatal(v->vl, "CLI debug.listen_address command failed: %u %s", u, resp); varnish_listen(v, resp); free(resp); /* Wait for vsl logging to get underway */ while (v->vsl_rec == 0) VTIM_sleep(.1); } /********************************************************************** * Stop a Varnish */ static void varnish_stop(struct varnish *v) { VARNISH_LAUNCH(v); vtc_log(v->vl, 2, "Stop"); (void)varnish_ask_cli(v, "stop", NULL); wait_stopped(v); } /********************************************************************** * Cleanup */ static void varnish_cleanup(struct varnish *v) { void *p; /* Close the CLI connection */ closefd(&v->cli_fd); /* Close the STDIN connection. */ closefd(&v->fds[1]); /* Wait until STDOUT+STDERR closes */ AZ(pthread_join(v->tp, &p)); closefd(&v->fds[0]); /* Pick up the VSL thread */ AZ(pthread_join(v->tp_vsl, &p)); vtc_wait4(v->vl, v->pid, v->expect_exit, 0, 0); v->pid = 0; } /********************************************************************** * Wait for a Varnish */ static void varnish_wait(struct varnish *v) { if (v->cli_fd < 0) return; vtc_log(v->vl, 2, "Wait"); if (!vtc_error) { /* Do a backend.list to log if child is still running */ (void)varnish_ask_cli(v, "backend.list", NULL); } /* Then stop it */ varnish_stop(v); if (varnish_ask_cli(v, "panic.show", NULL) != CLIS_CANT) vtc_fatal(v->vl, "Unexpected panic"); varnish_cleanup(v); } /********************************************************************** * Ask a CLI JSON question */ static void varnish_cli_json(struct varnish *v, const char *cli) { enum VCLI_status_e u; char *resp = NULL; const char *errptr; struct vjsn *vj; VARNISH_LAUNCH(v); u = varnish_ask_cli(v, cli, &resp); vtc_log(v->vl, 2, "CLI %03u <%s>", u, cli); if (u != CLIS_OK) vtc_fatal(v->vl, "FAIL CLI response %u expected %u", u, CLIS_OK); vj = vjsn_parse(resp, &errptr); if (vj == NULL) vtc_fatal(v->vl, "FAIL CLI, not good JSON: %s", errptr); vjsn_delete(&vj); free(resp); } /********************************************************************** * Ask a CLI question */ static void varnish_cli(struct varnish *v, const char *cli, unsigned exp, const char *re) { enum VCLI_status_e u; struct vsb vsb[1]; vre_t *vre = NULL; char *resp = NULL, errbuf[VRE_ERROR_LEN]; int err, erroff; VARNISH_LAUNCH(v); if (re != NULL) { vre = VRE_compile(re, 0, &err, &erroff, 1); if (vre == NULL) { AN(VSB_init(vsb, errbuf, sizeof errbuf)); AZ(VRE_error(vsb, err)); AZ(VSB_finish(vsb)); VSB_fini(vsb); vtc_fatal(v->vl, "Illegal regexp: %s (@%d)", errbuf, erroff); } } u = varnish_ask_cli(v, cli, &resp); vtc_log(v->vl, 2, "CLI %03u <%s>", u, cli); if (exp != 0 && exp != (unsigned)u) vtc_fatal(v->vl, "FAIL CLI response %u expected %u", u, exp); if (vre != NULL) { err = VRE_match(vre, resp, 0, 0, NULL); if (err < 1) { AN(VSB_init(vsb, errbuf, sizeof errbuf)); AZ(VRE_error(vsb, err)); AZ(VSB_finish(vsb)); VSB_fini(vsb); vtc_fatal(v->vl, "Expect failed (%s)", errbuf); } VRE_free(&vre); } free(resp); } /********************************************************************** * Load a VCL program */ static void varnish_vcl(struct varnish *v, const char *vcl, int fail, char **resp) { struct vsb *vsb; enum VCLI_status_e u; VARNISH_LAUNCH(v); vsb = VSB_new_auto(); AN(vsb); VSB_printf(vsb, "vcl.inline vcl%d << %s\nvcl %.1f;\n%s\n%s\n", ++v->vcl_nbr, NONSENSE, v->syntax, vcl, NONSENSE); AZ(VSB_finish(vsb)); u = varnish_ask_cli(v, VSB_data(vsb), resp); if (u == CLIS_OK) { VSB_clear(vsb); VSB_printf(vsb, "vcl.use vcl%d", v->vcl_nbr); AZ(VSB_finish(vsb)); u = varnish_ask_cli(v, VSB_data(vsb), NULL); } if (u == CLIS_OK && fail) { VSB_destroy(&vsb); vtc_fatal(v->vl, "VCL compilation succeeded expected failure"); } else if (u != CLIS_OK && !fail) { VSB_destroy(&vsb); vtc_fatal(v->vl, "VCL compilation failed expected success"); } else if (fail) vtc_log(v->vl, 2, "VCL compilation failed (as expected)"); VSB_destroy(&vsb); } /********************************************************************** * Load a VCL program prefixed by backend decls for our servers */ static void varnish_vclbackend(struct varnish *v, const char *vcl) { struct vsb *vsb, *vsb2; enum VCLI_status_e u; VARNISH_LAUNCH(v); vsb = VSB_new_auto(); AN(vsb); vsb2 = VSB_new_auto(); AN(vsb2); VSB_printf(vsb2, "vcl %.1f;\n", v->syntax); cmd_server_gen_vcl(vsb2); AZ(VSB_finish(vsb2)); VSB_printf(vsb, "vcl.inline vcl%d << %s\n%s\n%s\n%s\n", ++v->vcl_nbr, NONSENSE, VSB_data(vsb2), vcl, NONSENSE); AZ(VSB_finish(vsb)); u = varnish_ask_cli(v, VSB_data(vsb), NULL); if (u != CLIS_OK) { VSB_destroy(&vsb); VSB_destroy(&vsb2); vtc_fatal(v->vl, "FAIL VCL does not compile"); } VSB_clear(vsb); VSB_printf(vsb, "vcl.use vcl%d", v->vcl_nbr); AZ(VSB_finish(vsb)); u = varnish_ask_cli(v, VSB_data(vsb), NULL); assert(u == CLIS_OK); VSB_destroy(&vsb); VSB_destroy(&vsb2); } /********************************************************************** */ struct dump_priv { const char *arg; const struct varnish *v; }; static int do_stat_dump_cb(void *priv, const struct VSC_point * const pt) { const struct varnish *v; struct dump_priv *dp; uint64_t u; if (pt == NULL) return (0); dp = priv; v = dp->v; if (strcmp(pt->ctype, "uint64_t")) return (0); u = VSC_Value(pt); if (strcmp(dp->arg, "*")) { if (fnmatch(dp->arg, pt->name, 0)) return (0); } vtc_log(v->vl, 4, "VSC %s %ju", pt->name, (uintmax_t)u); return (0); } static void varnish_vsc(struct varnish *v, const char *arg) { struct dump_priv dp; VARNISH_LAUNCH(v); memset(&dp, 0, sizeof dp); dp.v = v; dp.arg = arg; (void)VSM_Status(v->vsm_vsc); (void)VSC_Iter(v->vsc, v->vsm_vsc, do_stat_dump_cb, &dp); } /********************************************************************** * Check statistics */ struct stat_arg { const char *pattern; uintmax_t val; unsigned good; }; struct stat_priv { struct stat_arg lhs; struct stat_arg rhs; }; static int stat_match(const char *pattern, const char *name) { if (strchr(pattern, '.') == NULL) { if (fnmatch("MAIN.*", name, 0)) return (FNM_NOMATCH); name += 5; } return (fnmatch(pattern, name, 0)); } static int do_expect_cb(void *priv, const struct VSC_point * const pt) { struct stat_priv *sp = priv; if (pt == NULL) return (0); if (!sp->lhs.good && stat_match(sp->lhs.pattern, pt->name) == 0) { AZ(strcmp(pt->ctype, "uint64_t")); AN(pt->ptr); sp->lhs.val = VSC_Value(pt); sp->lhs.good = 1; } if (sp->rhs.pattern == NULL) { sp->rhs.good = 1; } else if (!sp->rhs.good && stat_match(sp->rhs.pattern, pt->name) == 0) { AZ(strcmp(pt->ctype, "uint64_t")); AN(pt->ptr); sp->rhs.val = VSC_Value(pt); sp->rhs.good = 1; } return (sp->lhs.good && sp->rhs.good); } /********************************************************************** */ static void varnish_expect(struct varnish *v, char * const *av) { struct stat_priv sp; int good, i, not; uintmax_t u; char *l, *p; VARNISH_LAUNCH(v); ZERO_OBJ(&sp, sizeof sp); l = av[0]; not = (*l == '!'); if (not) { l++; AZ(av[1]); } else { AN(av[1]); AN(av[2]); u = strtoumax(av[2], &p, 0); if (u != UINTMAX_MAX && *p == '\0') sp.rhs.val = u; else sp.rhs.pattern = av[2]; } sp.lhs.pattern = l; for (i = 0; i < 50; i++, (void)usleep(100000)) { (void)VSM_Status(v->vsm_vsc); sp.lhs.good = sp.rhs.good = 0; good = VSC_Iter(v->vsc, v->vsm_vsc, do_expect_cb, &sp); if (!good) good = -2; if (good < 0) continue; if (not) vtc_fatal(v->vl, "Found (not expected): %s", l); good = -1; if (!strcmp(av[1], "==")) good = (sp.lhs.val == sp.rhs.val); if (!strcmp(av[1], "!=")) good = (sp.lhs.val != sp.rhs.val); if (!strcmp(av[1], ">" )) good = (sp.lhs.val > sp.rhs.val); if (!strcmp(av[1], "<" )) good = (sp.lhs.val < sp.rhs.val); if (!strcmp(av[1], ">=")) good = (sp.lhs.val >= sp.rhs.val); if (!strcmp(av[1], "<=")) good = (sp.lhs.val <= sp.rhs.val); if (good == -1) vtc_fatal(v->vl, "comparison %s unknown", av[1]); if (good) break; } if (good == -1) { vtc_fatal(v->vl, "VSM error: %s", VSM_Error(v->vsm_vsc)); } if (good == -2) { if (not) { vtc_log(v->vl, 2, "not found (as expected): %s", l); return; } vtc_fatal(v->vl, "stats field %s unknown", sp.lhs.good ? sp.rhs.pattern : sp.lhs.pattern); } if (good == 1) { vtc_log(v->vl, 2, "as expected: %s (%ju) %s %s (%ju)", av[0], sp.lhs.val, av[1], av[2], sp.rhs.val); } else { vtc_fatal(v->vl, "Not true: %s (%ju) %s %s (%ju)", av[0], sp.lhs.val, av[1], av[2], sp.rhs.val); } } static void vsl_catchup(struct varnish *v) { int vsl_idle; VARNISH_LAUNCH(v); vsl_idle = v->vsl_idle; while (!vtc_error && vsl_idle == v->vsl_idle) VTIM_sleep(0.1); } /* SECTION: varnish varnish * * Define and interact with varnish instances. * * To define a Varnish server, you'll use this syntax:: * * varnish vNAME [-arg STRING] [-vcl STRING] [-vcl+backend STRING] * [-errvcl STRING STRING] [-jail STRING] [-proto PROXY] * * The first ``varnish vNAME`` invocation will start the varnishd master * process in the background, waiting for the ``-start`` switch to actually * start the child. * * Types used in the description below: * * PATTERN * is a 'glob' style pattern (ie: fnmatch(3)) as used in shell filename * expansion. * * Arguments: * * vNAME * Identify the Varnish server with a string, it must starts with 'v'. * * \-arg STRING * Pass an argument to varnishd, for example "-h simple_list". * * \-vcl STRING * Specify the VCL to load on this Varnish instance. You'll probably * want to use multi-lines strings for this ({...}). * * \-vcl+backend STRING * Do the exact same thing as -vcl, but adds the definition block of * known backends (ie. already defined). * * \-errvcl STRING1 STRING2 * Load STRING2 as VCL, expecting it to fail, and Varnish to send an * error string matching STRING1 * * \-jail STRING * Look at ``man varnishd`` (-j) for more information. * * \-proto PROXY * Have Varnish use the proxy protocol. Note that PROXY here is the * actual string. * * You can decide to start the Varnish instance and/or wait for several events:: * * varnish vNAME [-start] [-wait] [-wait-running] [-wait-stopped] * * \-start * Start the child process. * * Once successfully started, the following macros are available for * the default listen address: ``${vNAME_addr}``, ``${vNAME_port}`` * and ``${vNAME_sock}``. Additional macros are available, including * the listen address name for each address vNAME listens to, like for * example: ``${vNAME_a0_addr}``. * * \-stop * Stop the child process. * * \-syntax * Set the VCL syntax level for this command (default: 4.1) * * \-wait * Wait for that instance to terminate. * * \-wait-running * Wait for the Varnish child process to be started. * * \-wait-stopped * Wait for the Varnish child process to stop. * * \-cleanup * Once Varnish is stopped, clean everything after it. This is only used * in very few tests and you should never need it. * * \-expectexit NUMBER * Expect varnishd to exit(3) with this value * * Once Varnish is started, you can talk to it (as you would through * ``varnishadm``) with these additional switches:: * * varnish vNAME [-cli STRING] [-cliok STRING] [-clierr STRING] * [-clijson STRING] * * \-cli STRING|-cliok STRING|-clierr STATUS STRING|-cliexpect REGEXP STRING * All four of these will send STRING to the CLI, the only difference * is what they expect the result to be. -cli doesn't expect * anything, -cliok expects 200, -clierr expects STATUS, and * -cliexpect expects the REGEXP to match the returned response. * * \-clijson STRING * Send STRING to the CLI, expect success (CLIS_OK/200) and check * that the response is parsable JSON. * * It is also possible to interact with its shared memory (as you would * through tools like ``varnishstat``) with additional switches: * * \-expect \!PATTERN|PATTERN OP NUMBER|PATTERN OP PATTERN * Look into the VSM and make sure the first VSC counter identified by * PATTERN has a correct value. OP can be ==, >, >=, <, <=. For * example:: * * varnish v1 -expect SM?.s1.g_space > 1000000 * varnish v1 -expect cache_hit >= cache_hit_grace * * In the \! form the test fails if a counter matches PATTERN. * * The ``MAIN.`` namespace can be omitted from PATTERN. * * The test takes up to 5 seconds before timing out. * * \-vsc PATTERN * Dump VSC counters matching PATTERN. * * \-vsl_catchup * Wait until the logging thread has idled to make sure that all * the generated log is flushed */ void cmd_varnish(CMD_ARGS) { struct varnish *v, *v2; (void)priv; if (av == NULL) { /* Reset and free */ VTAILQ_FOREACH_SAFE(v, &varnishes, list, v2) { if (v->cli_fd >= 0) varnish_wait(v); VTAILQ_REMOVE(&varnishes, v, list); varnish_delete(v); } return; } AZ(strcmp(av[0], "varnish")); av++; VTC_CHECK_NAME(vl, av[0], "Varnish", 'v'); VTAILQ_FOREACH(v, &varnishes, list) if (!strcmp(v->name, av[0])) break; if (v == NULL) v = varnish_new(av[0]); av++; v->syntax = 4.1; for (; *av != NULL; av++) { if (vtc_error) break; if (!strcmp(*av, "-arg")) { AN(av[1]); AZ(v->pid); VSB_cat(v->args, " "); VSB_cat(v->args, av[1]); if (av[1][0] == '-' && av[1][1] == 'a') v->has_a_arg = 1; av++; continue; } if (!strcmp(*av, "-cleanup")) { AZ(av[1]); varnish_cleanup(v); continue; } if (!strcmp(*av, "-cli")) { AN(av[1]); varnish_cli(v, av[1], 0, NULL); av++; continue; } if (!strcmp(*av, "-clierr")) { AN(av[1]); AN(av[2]); varnish_cli(v, av[2], atoi(av[1]), NULL); av += 2; continue; } if (!strcmp(*av, "-cliexpect")) { AN(av[1]); AN(av[2]); varnish_cli(v, av[2], 0, av[1]); av += 2; continue; } if (!strcmp(*av, "-clijson")) { AN(av[1]); varnish_cli_json(v, av[1]); av++; continue; } if (!strcmp(*av, "-cliok")) { AN(av[1]); varnish_cli(v, av[1], (unsigned)CLIS_OK, NULL); av++; continue; } if (!strcmp(*av, "-errvcl")) { char *r = NULL; AN(av[1]); AN(av[2]); varnish_vcl(v, av[2], 1, &r); if (strstr(r, av[1]) == NULL) vtc_fatal(v->vl, "Did not find expected string: (\"%s\")", av[1]); else vtc_log(v->vl, 3, "Found expected string: (\"%s\")", av[1]); free(r); av += 2; continue; } if (!strcmp(*av, "-expect")) { av++; varnish_expect(v, av); av += 2; continue; } if (!strcmp(*av, "-expectexit")) { v->expect_exit = strtoul(av[1], NULL, 0); av++; continue; } if (!strcmp(*av, "-jail")) { AN(av[1]); AZ(v->pid); REPLACE(v->jail, av[1]); av++; continue; } if (!strcmp(*av, "-proto")) { AN(av[1]); AZ(v->pid); REPLACE(v->proto, av[1]); av++; continue; } if (!strcmp(*av, "-start")) { varnish_start(v); continue; } if (!strcmp(*av, "-stop")) { varnish_stop(v); continue; } if (!strcmp(*av, "-syntax")) { AN(av[1]); v->syntax = strtod(av[1], NULL); av++; continue; } if (!strcmp(*av, "-vcl")) { AN(av[1]); varnish_vcl(v, av[1], 0, NULL); av++; continue; } if (!strcmp(*av, "-vcl+backend")) { AN(av[1]); varnish_vclbackend(v, av[1]); av++; continue; } if (!strcmp(*av, "-vsc")) { AN(av[1]); varnish_vsc(v, av[1]); av++; continue; } if (!strcmp(*av, "-wait-stopped")) { wait_stopped(v); continue; } if (!strcmp(*av, "-wait-running")) { wait_running(v); continue; } if (!strcmp(*av, "-wait")) { varnish_wait(v); continue; } if (!strcmp(*av, "-vsl_catchup")) { vsl_catchup(v); continue; } vtc_fatal(v->vl, "Unknown varnish argument: %s", *av); } } #endif /* VTEST_WITH_VTC_VARNISH */
the_stack_data/480483.c
#include <stdio.h> int main() { char name[8][30]; int totalMovie[8]; int totalFreeMovie[8]; int i; for(i=0; i < 8; i++){ printf("Insira o nome: "); gets(name[i]); printf("\nPlease, insert the total movie:"); scanf("%d", &totalMovie[i]); totalFreeMovie[i] = (totalMovie[i] * 1/10); } for(i = 0;i < 8;i++) { printf("\n Nome do cliente: "); pusts(name[i]); printf("\nTotal de filmes alocados: %d", totalMovie[i]); printf("\nTotal de filmes gratuidos para alocar: %d", totalFreeMovie[i]); } }
the_stack_data/184517328.c
/* * Copyright (c) 2010 Todd C. Miller <[email protected]> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* $OpenBSD: strnlen.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */ #include <string.h> size_t strnlen(const char* str, size_t maxlen) { const char* cp; for(cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--) { ; } return (size_t)(cp - str); }
the_stack_data/86074025.c
#include <stdio.h> int main() { int a, b; while (scanf("%d%d", &a, &b) == 2) { int mul = a * b; if (b) while ((a %= b) && (b %= a)); int gcd = a + b; printf("%d\n", mul / gcd); } }
the_stack_data/568238.c
a, b; c() { int d = e(); if (d < 0 || d && b) a = b; }
the_stack_data/61075929.c
// Copyright (c) 2016 Wladimir J. van der Laan // Distributed under the MIT software license. // Based on an example from the OpenCL cookbook. #include <stdio.h> #include <stdlib.h> #ifdef __APPLE__ #include <OpenCL/opencl.h> #else #define CL_USE_DEPRECATED_OPENCL_1_2_APIS #include <CL/cl.h> #endif #ifndef CL_DEVICE_PCI_BUS_ID_NV #define CL_DEVICE_PCI_BUS_ID_NV (0x4008) #endif struct platform_data_item { int id; char *name; }; struct platform_data_item platform_data_items[] = { { CL_PLATFORM_PROFILE, "Profile"}, { CL_PLATFORM_VERSION, "Version"}, { CL_PLATFORM_NAME, "Name"}, { CL_PLATFORM_VENDOR, "Vendor"}, { CL_PLATFORM_EXTENSIONS, "Extensions"}, }; #define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0])) int main() { int i, j; char* value; size_t valueSize; cl_uint platformCount = 0; cl_platform_id* platforms; cl_uint deviceCount; cl_device_id* devices; cl_uint maxComputeUnits; // get all platforms if (clGetPlatformIDs(0, NULL, &platformCount) != CL_SUCCESS) { printf("Unable to get platform IDs\n"); exit(1); } platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount); if (clGetPlatformIDs(platformCount, platforms, NULL) != CL_SUCCESS) { printf("Unable to get platform IDs\n"); exit(1); } for (i = 0; i < platformCount; i++) { printf("%i. Platform\n", i+1); char data[1024]; size_t retsize; for (int j=0; j<ARRAYLEN(platform_data_items); ++j) { if (clGetPlatformInfo(platforms[i], platform_data_items[j].id, sizeof(data), data, &retsize) != CL_SUCCESS || retsize == sizeof(data)) { printf("Unable to get platform %s\n", platform_data_items[j].name); continue; } printf(" %s: %s\n", platform_data_items[j].name, data); } // get all devices int status = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount); if (status != CL_SUCCESS) { printf("Unable to get device IDs for platform %p, code %d\n", platforms[i], status); continue; } devices = (cl_device_id*) malloc(sizeof(cl_device_id) * deviceCount); status = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL); if (status != CL_SUCCESS) { printf("Unable to get device IDs detail for platform %p, code %d\n", platforms[i], status); continue; } // for each device print critical attributes for (j = 0; j < deviceCount; j++) { // print device name clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 0, NULL, &valueSize); value = (char*) malloc(valueSize); clGetDeviceInfo(devices[j], CL_DEVICE_NAME, valueSize, value, NULL); printf("%d. Device: %s\n", j+1, value); free(value); unsigned bus_id = 0; clGetDeviceInfo(devices[j], CL_DEVICE_PCI_BUS_ID_NV, sizeof(unsigned), &bus_id, NULL); printf(" PCI bus id: %d\n", bus_id); // print hardware device version clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, 0, NULL, &valueSize); value = (char*) malloc(valueSize); clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, valueSize, value, NULL); printf(" %d.%d Hardware version: %s\n", j+1, 1, value); free(value); // print software driver version clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, 0, NULL, &valueSize); value = (char*) malloc(valueSize); clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, valueSize, value, NULL); printf(" %d.%d Software version: %s\n", j+1, 2, value); free(value); // print c version supported by compiler for device clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, 0, NULL, &valueSize); value = (char*) malloc(valueSize); clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, valueSize, value, NULL); printf(" %d.%d OpenCL C version: %s\n", j+1, 3, value); free(value); // print parallel compute units clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(maxComputeUnits), &maxComputeUnits, NULL); printf(" %d.%d Parallel compute units: %d\n", j+1, 4, maxComputeUnits); } free(devices); } free(platforms); return 0; }
the_stack_data/111078820.c
#include <stdio.h> // [opt] 0 1 // [out] <auto> int main(int argc, char* argv[]) { int a, b; printf("a =\n"); scanf("%i", &a); // [in] -73322 printf("b =\n"); scanf("%i", &b); // [in] 1292 printf("\n"); unsigned int c = (unsigned int)a; unsigned int d = (unsigned int)b; printf(" a + b = %i\n", a + b); printf("2 * a - b = %i\n", 2 * a - b); printf("3 * a + a / b = %i\n", 3 * a + a / b); printf("4 * a * a - b = %i\n", 4 * a * a - b); printf("\n"); printf("Signed: a / b = %i\n", a / b); printf("Signed: a %% b = %i\n", a % b); printf("Unsigned: a / b = %i\n", (int)(c / d)); printf("Unsigned: a %% b = %i\n", (int)(c % d)); return 0; }
the_stack_data/173577776.c
#include <stdio.h> int findPoisonedDuration(int* timeSeries, int timeSeriesSize, int duration) { if(timeSeriesSize <= 0) { return 0; } int ret = 0; for(int i = 1; i < timeSeriesSize; ++i) { int diff = *(timeSeries+i) - *(timeSeries+i-1); ret += (diff < duration) ? diff : duration; } return ret + duration; } void main() { int input[] = {1, 4}; int duration = 2; printf("the output is %d\n", findPoisonedDuration(input, sizeof(input)/sizeof(int), duration)); }
the_stack_data/248580652.c
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> /* ** LÝ THUYẾT CHUỖI KÝ TỰ */ int main() { #if 0 // Khai báo chuỗi ký tự char s[15] = { 'L','e','H','o','n','g','H','a','i','\0' }; // Khai báo tường minh đầy đủ cả ký tự kết thúc chuỗi char name[] = "Le Hong Hai"; // Tự động thêm '\0' và tự xác định độ dài // Xuất chuỗi printf("%s\n", s); puts(s); // Tự động xuống dòng printf("Size of s[]: %d\n", sizeof(s)); printf("So phan tu cua s = %d\n", strlen(s)); printf("%s\n", name); puts(name); // Tự động xuống dòng printf("Size of name[]: %d\n", sizeof(name)); #endif // Khai báo chuỗi ký tự #if 0 // Nhập chuỗi char ten[20]; int tuoi; printf("Nhap tuoi: "); scanf("%d", &tuoi); //fflush(stdin); not working vs 2017 //rewind(stdin); while (getchar() != '\n') {} printf("Nhap ten: "); gets(ten); // Xuất chuỗi printf("\nBan ten: %s\n", ten); printf("Ban %d tuoi\n", tuoi); #endif // Nhập chuỗi #if 0 // Hàm tính độ dài chuỗi char s[] = "Visual Studio 2017"; int dodaichuoi = strlen(s); printf("Do dai chuoi = %d\n", dodaichuoi); #endif // Hàm tính độ dài chuỗi #if 0 // Hàm sao chép chuỗi char s[50], say[] = "Hello Friend"; strcpy(s, say); // Sao chép nội dung chuỗi say[] sang cho chuỗi s[] // Lưu ý: s >= say thì mới sao chép chuỗi đc. printf("Chuoi s: %s\n", s); #endif // Hàm sao chép chuỗi #if 0 // Hàm tạo một bản sao của chuỗi char *s; // Khai báo một con trỏ s kiểu char char z[] = "Lap trinh C co ban"; s = strdup(z); // Không phải là một standard C++ function printf("Ban goc z = %s\n", z); printf("Do dai ban goc z = %d\n", strlen(z)); printf("Ban sao s = %s\n", s); printf("Do dai ban sao s = %d\n", strlen(s)); delete(s); // Hủy printf("Sau khi huy z = %s\n", z); printf("Sau khi huy s = %s\n", s); #endif // Hàm tạo một bản sao của chuỗi #if 0 // Hàm chuyển các chữ cái hoa về chữ thường char name[] = "Le Hong Hai"; printf("Chuoi trc khi chuyen: %s\n", name); _strlwr(name); printf("Chuoi sau khi chuyen: %s\n", name); #endif // Hàm chuyển các chữ cái hoa về chữ thường #if 0 // Hàm chuyển ký tự thường lên ký tự hoa char name[] = "Le Hong Hai"; printf("Chuoi trc khi chuyen: %s\n", name); _strupr(name); printf("Chuoi sau khi chuyen: %s\n", name); #endif // Hàm chuyển ký tự thường lên ký tự hoa #if 0 // Hàm đảo ngược chuỗi char name[] = "Le Hong Hai"; printf("Chuoi trc khi dao: %s\n", name); _strrev(name); printf("Chuoi sau khi dao: %s\n", name); #endif // 1 #if 0 // Hàm so sánh hai chuỗi. Có phân biệt hoa thường char s1[] = "Le Van A"; char s2[] = "Nguyen Van B"; int kq = strcmp(s1, s2); printf("Ket qua: %d\n", kq); /* // So sánh từng cặp ký tự (byte) lần lượt dựa vào việc đối chiếu lên bảng mã ascii. // Không phải là so sánh độ dài chuỗi // Gặp ký tự nào mà khác nhau thì nó so sánh và trả về kết quả. Nếu cặp ký tự == nhau thì // mới xét cặp ký tự tiếp theo. -1 => s1 < s2 0 => s1 == s2 1 => s1 > s2 */ #endif // Hàm so sánh hai chuỗi. Có phân biệt hoa thường #if 0 // Hàm so sánh hai chuỗi. Không phân biệt hoa thường // Giống với strcmp nhưng không phân biệt hoa hay thường char s1[] = "Le Van A"; char s2[] = "Le Van A"; int kq = _stricmp(s1, s2); printf("Ket qua: %d\n", kq); #endif // Hàm so sánh hai chuỗi. Không phân biệt hoa thường #if 0 // Hàm nối hai chuỗi với nhau char s1[50] = "Lap trinh C"; char s2[] = "co ban"; strcat(s1, " "); strcat(s1, s2); printf("Chuoi sau khi noi: %s\n", s1); #endif // Hàm nối hai chuỗi với nhau #if 0 // Hàm tìm chuỗi trong chuỗi (Tìm chuỗi con) char s1[] = "Lap trinh C co ban"; char s2[] = "co ban"; char s3[] = "nang cao"; // Trả về con trỏ đến vị trí xuất hiện đầu tiên của chuỗi con trong chuỗi lớn // Trả về null nếu không tìm thấy if (strstr(s1, s2) != NULL) printf("Tim thay '%s' trong '%s'\n", s2, s1); if (strstr(s1, s3) == NULL) printf("Khong tim thay '%s' trong '%s'\n", s3, s1); #endif /// Hàm tìm chuỗi trong chuỗi (Tìm chuỗi con) #if 0 // Hàm tách chuỗi char s1[50]; printf("Nhap chuoi muon tach: "); gets(s1); char *ptr1 = strtok(s1, " "); printf("%s\n", ptr1); while (ptr1 != '\0') { ptr1 = strtok(NULL, " "); if (ptr1 != '\0') printf("%s\n", ptr1); } //char *ptr2 = strtok(NULL, " "); // NULL: Xét từ vị trí vừa cắt trước đó //printf("ptr1 = %s\n", ptr2); //char *ptr3 = strtok(NULL, " "); //printf("ptr1 = %s\n", ptr3); #endif // Hàm tách chuỗi getch(); return 0; } /* - Chuỗi ký tự = mảng các ký tự - Chuỗi ký tự luôn có một ký tự kết thúc chuỗi là '\0' (null) - Độ dài chuỗi = kích thước mảng - 1 (Không tính ký tự '\0') - Trường hợp chuỗi được nhập sau khi đã nhập một số trươc đó chẳng hạn thì dẫn tới việc ký tự enter sau khi nhập số được coi là ký tự kết thúc chuỗi lên vùng đệm của chuỗi nhận ký tự đó và không cho nhập chuỗi nữa => cần phải xóa bộ đệm (buffer) trước khi nhập chuỗi */ /* Phân biệt hàm strcpy() và hàm strdup() - Với hàm strcpy, bản gốc và bản sao chép đều nằm trên Stack. Tự động được clear khi kết thúc hàm. - Còn với hàm strdup, bản gốc nằm trên Stack còn bản sao thì nằm trên Heap và được quản lý bởi 1 con trỏ. Không tự động clear mà lập trình viên phải chủ động clear vùng nhớ này khi không dùng. - Với hàm strcpy thì vùng dữ liệu của bản sao phải được khai báo trước với một kích thước nào đó => dễ gây dư thừa. (lớn hơn hoặc bằng với vùng dữ liệu chứa bản gốc) - Còn với strdup thì linh động hơn do hàm này sẽ cấp phát động và chỉ cần khai báo một con trỏ để trỏ tới vùng nhớ chứa bản sao. */
the_stack_data/153269325.c
int ternary_true() { return 3 > 1 ? 5 : 4; }
the_stack_data/131658.c
// create a linked list #include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }; struct node *ptr,*temp,*head=0; void create_node() { int choice; do { printf("create node\n"); ptr=(struct node*)malloc(sizeof(struct node*)); printf("enter the data:\n"); scanf("%d",&ptr->data); ptr->next=0; if(head==0) { head=temp=ptr; } else { temp->next=ptr; temp=temp->next; } printf("do you want to continue(0,1):\n"); scanf("%d",&choice); }while(choice); } void insert_begining() { printf("insert the element at first position:\n"); printf("create node\n"); ptr=(struct node*)malloc(sizeof(struct node*)); printf("enter the data:\n"); scanf("%d",&ptr->data); ptr->next=head; head=ptr; } void insert_end() { printf("insert the element at end:\n"); printf("create node\n"); ptr=(struct node*)malloc(sizeof(struct node*)); printf("enter the data:\n"); scanf("%d",&ptr->data); ptr->next=0; temp=head; while(temp->next!=0) { temp=temp->next; } temp->next=ptr; } void insert_position() { printf("insert the element at given position:\n"); int i,pos; printf("create node\n"); ptr=(struct node*)malloc(sizeof(struct node*)); printf("enter the data:\n"); scanf("%d",&ptr->data); ptr->next=0; printf("enter the position:"); scanf("%d",&pos); temp=head; for(i=0;i<pos-1;i++) { temp=temp->next; } ptr->next=temp->next; temp->next=ptr; } void display() { temp=head; while(temp->next!=0) { printf("%d\t",temp->data); temp=temp->next; } printf("%d",temp->data); } void main() { create_node(); insert_begining(); insert_end(); insert_position(); display(); }
the_stack_data/1188789.c
#include <arpa/inet.h> #include <netinet/in.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <unistd.h> #define MAX_BATCH 2048 typedef uint64_t elemtype; unsigned short listen_port = 0x8888; unsigned short response_port = 0x9999; struct flow_key { uint32_t srcip; uint32_t dstip; uint16_t srcport; uint16_t dstport; uint16_t protocol; }; struct countmax_entry { struct flow_key key; elemtype value; }; const char* magic_finish = "finish"; void print_ip(uint32_t ip) { printf("%d.%d.%d.%d", (ip) % 0x100, (ip / 0x100) % 0x100, (ip / 0x10000) % 0x100, ip / 0x1000000); } int main() { const unsigned buf_size = MAX_BATCH * sizeof(struct flow_key); struct sockaddr_in s_addr; int ret = 0; memset(&s_addr, 0, sizeof(s_addr)); s_addr.sin_family = AF_INET; s_addr.sin_port = htons(listen_port); inet_pton(AF_INET, "127.0.0.1", &s_addr.sin_addr); //printf("1\n"); int sockfd = socket(AF_INET, SOCK_STREAM, 0); ret = connect(sockfd, (struct sockaddr*)&s_addr, sizeof(s_addr)); char* send_buf = "lol233hhh"; printf("%d\n", ret); write(sockfd, send_buf, strlen(send_buf) + 1); size_t recv_size = MAX_BATCH * sizeof(struct countmax_entry); struct countmax_entry* recv_buf = malloc(recv_size); bzero(recv_buf, recv_size); while (1) { int n = read(sockfd, recv_buf, recv_size); if (n) printf("get response! length: %d\n", n); sleep(1); if(strcmp((char*)recv_buf,magic_finish) == 0){ printf("END.\n"); break; } int i = 0; for (; i < n / sizeof(struct countmax_entry); ++i) { //if(recv_buf[i].key.srcip==0&&recv_buf[i].key.dstip==0) break; print_ip(recv_buf[i].key.srcip); printf("->"); print_ip(recv_buf[i].key.dstip); printf(": %llu \n", recv_buf[i].value); } } close(sockfd); return 0; }
the_stack_data/40763321.c
int max(int a, int b) { if (a > b) { return a; } else { return b; } }
the_stack_data/117296.c
int foo() { return -5; } int main() { int z; int y = -5; foo(); z = 4; return 0; //y out of scope, __cil for foo out of scope }
the_stack_data/97823.c
/*** * This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License. * When used, please cite the following article(s): V. Mrazek, R. Hrbacek, Z. Vasicek and L. Sekanina, "EvoApprox8b: Library of approximate adders and multipliers for circuit design and benchmarking of approximation methods". Design, Automation & Test in Europe Conference & Exhibition (DATE), 2017, Lausanne, 2017, pp. 258-261. doi: 10.23919/DATE.2017.7926993 * This file contains a circuit from evoapprox8b dataset. Note that a new version of library was already published. ***/ #include <stdint.h> #include <stdlib.h> /// Approximate function add8_182 /// Library = EvoApprox8b /// Circuit = add8_182 /// Area (180) = 1264 /// Delay (180) = 0.910 /// Power (180) = 347.00 /// Area (45) = 89 /// Delay (45) = 0.380 /// Power (45) = 27.63 /// Nodes = 31 /// HD = 188032 /// MAE = 6.65625 /// MSE = 71.00000 /// MRE = 3.45 % /// WCE = 19 /// WCRE = 400 % /// EP = 93.9 % uint16_t add8_182(uint8_t a, uint8_t b) { uint16_t c = 0; uint8_t n4 = (a >> 2) & 0x1; uint8_t n6 = (a >> 3) & 0x1; uint8_t n8 = (a >> 4) & 0x1; uint8_t n10 = (a >> 5) & 0x1; uint8_t n12 = (a >> 6) & 0x1; uint8_t n14 = (a >> 7) & 0x1; uint8_t n20 = (b >> 2) & 0x1; uint8_t n22 = (b >> 3) & 0x1; uint8_t n24 = (b >> 4) & 0x1; uint8_t n26 = (b >> 5) & 0x1; uint8_t n28 = (b >> 6) & 0x1; uint8_t n30 = (b >> 7) & 0x1; uint8_t n36; uint8_t n43; uint8_t n45; uint8_t n46; uint8_t n49; uint8_t n68; uint8_t n70; uint8_t n73; uint8_t n78; uint8_t n79; uint8_t n81; uint8_t n86; uint8_t n87; uint8_t n96; uint8_t n97; uint8_t n135; uint8_t n136; uint8_t n143; uint8_t n153; uint8_t n160; uint8_t n162; uint8_t n177; uint8_t n181; uint8_t n206; uint8_t n209; uint8_t n226; uint8_t n245; uint8_t n254; uint8_t n273; uint8_t n377; uint8_t n394; uint8_t n404; uint8_t n412; uint8_t n413; uint8_t n422; n36 = ~(n6 | n24); n43 = n28 | n12; n45 = n28 | n12; n46 = n26 & n10; n49 = ~(n24 | n8 | n6); n68 = n8 & n24; n70 = n68; n73 = n24 & n8; n78 = n10 ^ n26; n79 = n10 & n26; n81 = n79; n86 = n12 ^ n28; n87 = n12 & n28; n96 = n14 ^ n30; n97 = n14 & n30; n135 = n26 | n10; n136 = n135; n143 = n87; n153 = n70; n160 = n96; n162 = n43 & n46; n177 = ~n49; n181 = n143 | n162; n206 = n136; n209 = n181; n226 = n206 & n153; n245 = n81 | n226; n254 = n45 & n226; n273 = n209 | n254; n377 = n160; n394 = n78 ^ n73; n404 = n86 ^ n245; n412 = n377 ^ n273; n413 = n377 & n273; n422 = n97 | n413; c |= (n4 & 0x1) << 0; c |= (n20 & 0x1) << 1; c |= (n36 & 0x1) << 2; c |= (n22 & 0x1) << 3; c |= (n177 & 0x1) << 4; c |= (n394 & 0x1) << 5; c |= (n404 & 0x1) << 6; c |= (n412 & 0x1) << 7; c |= (n422 & 0x1) << 8; return c; }
the_stack_data/38061.c
/* @jxvtrl Exercicio Número 1a da Prova 1 de Introdução a Programação */ #include <stdio.h> #include <math.h> int X1,Y1,X2,Y2,D1,D2; float resultado; int main(){ // Achar a distancia Euclidiana entre os pontos printf("Qual a primeira coordenada de pontos? (X1,Y1) <- Separado por virgula, sem espaço\n"); scanf("%i,%i", &X1,&Y1); printf("Qual a segunda coordenada de pontos? (X2,Y2) <- Separado por virgula, sem espaço\n"); scanf("%i,%i", &X2,&Y2); D1 = X1-Y1; D2 = X2-Y2; resultado = sqrt((D1^2)+(D2^2)); printf("\nDistancia Euclidiana : %.2f", resultado); return 0; }
the_stack_data/167330934.c
#include <stdio.h> int main() { int num = 0; int currentNumber = 2; printf("Digite um valor inteiro: "); scanf("%d", &num); for (int i = 0; i < num; i++) { printf("Numero %dº: %d \n", i, currentNumber); currentNumber+=2; } return 0; }
the_stack_data/242330456.c
// RUN: %clam -O0 --crab-dom=zones --crab-check=assert --crab-sanity-checks "%s" 2>&1 | OutputCheck %s // CHECK: ^0 Number of total error checks$ // CHECK: ^1 Number of total warning checks$ extern void __CRAB_assert(int); extern void __SEAHORN_error(int); int main (){ int x,y,i; x=0; y=0; for (i=0;i< 10;i++) { x++; y++; } __CRAB_assert(x> y); //error return x+y; }
the_stack_data/37077.c
#include <stdio.h> int main(int argc, char **argv) { printf("Hello word!\n"); return 0; }
the_stack_data/98835.c
#include "malloc.h" #include <memory.h>
the_stack_data/118280.c
#include <stdio.h> #include <iso646.h> #define PERIOD '.' int main(void) { char ch; int charcount = 0; while ((ch = getchar()) != PERIOD) { if (ch != '"' and ch != '\'') charcount++; } printf("There are %d non-quote characters.\n", charcount); return 0; }
the_stack_data/10731.c
/* Capstone Disassembly Engine */ /* By Nguyen Anh Quynh <[email protected]>, 2013-2014 */ #ifdef CAPSTONE_HAS_XCORE #include <stdio.h> // debug #include <string.h> #include "../../utils.h" #include "XCoreMapping.h" #define GET_INSTRINFO_ENUM #include "XCoreGenInstrInfo.inc" static name_map reg_name_maps[] = { { XCORE_REG_INVALID, NULL }, { XCORE_REG_CP, "cp" }, { XCORE_REG_DP, "dp" }, { XCORE_REG_LR, "lr" }, { XCORE_REG_SP, "sp" }, { XCORE_REG_R0, "r0" }, { XCORE_REG_R1, "r1" }, { XCORE_REG_R2, "r2" }, { XCORE_REG_R3, "r3" }, { XCORE_REG_R4, "r4" }, { XCORE_REG_R5, "r5" }, { XCORE_REG_R6, "r6" }, { XCORE_REG_R7, "r7" }, { XCORE_REG_R8, "r8" }, { XCORE_REG_R9, "r9" }, { XCORE_REG_R10, "r10" }, { XCORE_REG_R11, "r11" }, // pseudo registers { XCORE_REG_PC, "pc" }, { XCORE_REG_SCP, "scp" }, { XCORE_REG_SSR, "ssr" }, { XCORE_REG_ET, "et" }, { XCORE_REG_ED, "ed" }, { XCORE_REG_SED, "sed" }, { XCORE_REG_KEP, "kep" }, { XCORE_REG_KSP, "ksp" }, { XCORE_REG_ID, "id" }, }; const char *XCore_reg_name(csh handle, unsigned int reg) { #ifndef CAPSTONE_DIET if (reg >= XCORE_REG_ENDING) return NULL; return reg_name_maps[reg].name; #else return NULL; #endif } xcore_reg XCore_reg_id(char *name) { int i; for(i = 1; i < ARR_SIZE(reg_name_maps); i++) { if (!strcmp(name, reg_name_maps[i].name)) return reg_name_maps[i].id; } // not found return 0; } static insn_map insns[] = { // dummy item { 0, 0, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ADD_2rus, XCORE_INS_ADD, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ADD_3r, XCORE_INS_ADD, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ANDNOT_2r, XCORE_INS_ANDNOT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_AND_3r, XCORE_INS_AND, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ASHR_l2rus, XCORE_INS_ASHR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ASHR_l3r, XCORE_INS_ASHR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_BAU_1r, XCORE_INS_BAU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 1 #endif }, { XCore_BITREV_l2r, XCORE_INS_BITREV, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_BLACP_lu10, XCORE_INS_BLA, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_R0, XCORE_REG_R1, XCORE_REG_R2, XCORE_REG_R3, XCORE_REG_R11, XCORE_REG_LR, 0 }, { 0 }, 0, 0 #endif }, { XCore_BLACP_u10, XCORE_INS_BLA, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_R0, XCORE_REG_R1, XCORE_REG_R2, XCORE_REG_R3, XCORE_REG_R11, XCORE_REG_LR, 0 }, { 0 }, 0, 0 #endif }, { XCore_BLAT_lu6, XCORE_INS_BLAT, #ifndef CAPSTONE_DIET { XCORE_REG_R11, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_BLAT_u6, XCORE_INS_BLAT, #ifndef CAPSTONE_DIET { XCORE_REG_R11, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_BLA_1r, XCORE_INS_BLA, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_R0, XCORE_REG_R1, XCORE_REG_R2, XCORE_REG_R3, XCORE_REG_R11, XCORE_REG_LR, 0 }, { 0 }, 0, 0 #endif }, { XCore_BLRB_lu10, XCORE_INS_BL, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_R0, XCORE_REG_R1, XCORE_REG_R2, XCORE_REG_R3, XCORE_REG_R11, XCORE_REG_LR, 0 }, { 0 }, 0, 0 #endif }, { XCore_BLRB_u10, XCORE_INS_BL, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_R0, XCORE_REG_R1, XCORE_REG_R2, XCORE_REG_R3, XCORE_REG_R11, XCORE_REG_LR, 0 }, { 0 }, 0, 0 #endif }, { XCore_BLRF_lu10, XCORE_INS_BL, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_R0, XCORE_REG_R1, XCORE_REG_R2, XCORE_REG_R3, XCORE_REG_R11, XCORE_REG_LR, 0 }, { 0 }, 0, 0 #endif }, { XCore_BLRF_u10, XCORE_INS_BL, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_R0, XCORE_REG_R1, XCORE_REG_R2, XCORE_REG_R3, XCORE_REG_R11, XCORE_REG_LR, 0 }, { 0 }, 0, 0 #endif }, { XCore_BRBF_lru6, XCORE_INS_BF, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRBF_ru6, XCORE_INS_BF, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRBT_lru6, XCORE_INS_BT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRBT_ru6, XCORE_INS_BT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRBU_lu6, XCORE_INS_BU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRBU_u6, XCORE_INS_BU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRFF_lru6, XCORE_INS_BF, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRFF_ru6, XCORE_INS_BF, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRFT_lru6, XCORE_INS_BT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRFT_ru6, XCORE_INS_BT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRFU_lu6, XCORE_INS_BU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRFU_u6, XCORE_INS_BU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 0 #endif }, { XCore_BRU_1r, XCORE_INS_BRU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 1 #endif }, { XCore_BYTEREV_l2r, XCORE_INS_BYTEREV, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_CHKCT_2r, XCORE_INS_CHKCT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_CHKCT_rus, XCORE_INS_CHKCT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_CLRE_0R, XCORE_INS_CLRE, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_CLRPT_1R, XCORE_INS_CLRPT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_CLRSR_branch_lu6, XCORE_INS_CLRSR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 1 #endif }, { XCore_CLRSR_branch_u6, XCORE_INS_CLRSR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 1 #endif }, { XCore_CLRSR_lu6, XCORE_INS_CLRSR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_CLRSR_u6, XCORE_INS_CLRSR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_CLZ_l2r, XCORE_INS_CLZ, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_CRC8_l4r, XCORE_INS_CRC8, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_CRC_l3r, XCORE_INS_CRC32, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_DCALL_0R, XCORE_INS_DCALL, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_DENTSP_0R, XCORE_INS_DENTSP, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_DGETREG_1r, XCORE_INS_DGETREG, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_DIVS_l3r, XCORE_INS_DIVS, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_DIVU_l3r, XCORE_INS_DIVU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_DRESTSP_0R, XCORE_INS_DRESTSP, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_DRET_0R, XCORE_INS_DRET, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ECALLF_1r, XCORE_INS_ECALLF, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ECALLT_1r, XCORE_INS_ECALLT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_EDU_1r, XCORE_INS_EDU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_EEF_2r, XCORE_INS_EEF, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_EET_2r, XCORE_INS_EET, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_EEU_1r, XCORE_INS_EEU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ENDIN_2r, XCORE_INS_ENDIN, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ENTSP_lu6, XCORE_INS_ENTSP, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_ENTSP_u6, XCORE_INS_ENTSP, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_EQ_2rus, XCORE_INS_EQ, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_EQ_3r, XCORE_INS_EQ, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_EXTDP_lu6, XCORE_INS_EXTDP, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_EXTDP_u6, XCORE_INS_EXTDP, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_EXTSP_lu6, XCORE_INS_EXTSP, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_EXTSP_u6, XCORE_INS_EXTSP, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_FREER_1r, XCORE_INS_FREER, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_FREET_0R, XCORE_INS_FREET, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_GETD_l2r, XCORE_INS_GETD, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_GETED_0R, XCORE_INS_GET, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_GETET_0R, XCORE_INS_GET, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_GETID_0R, XCORE_INS_GET, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_GETKEP_0R, XCORE_INS_GET, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_GETKSP_0R, XCORE_INS_GET, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_GETN_l2r, XCORE_INS_GETN, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_GETPS_l2r, XCORE_INS_GET, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_GETR_rus, XCORE_INS_GETR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_GETSR_lu6, XCORE_INS_GETSR, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_GETSR_u6, XCORE_INS_GETSR, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_GETST_2r, XCORE_INS_GETST, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_GETTS_2r, XCORE_INS_GETTS, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_INCT_2r, XCORE_INS_INCT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_INITCP_2r, XCORE_INS_INIT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_INITDP_2r, XCORE_INS_INIT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_INITLR_l2r, XCORE_INS_INIT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_INITPC_2r, XCORE_INS_INIT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_INITSP_2r, XCORE_INS_INIT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_INPW_l2rus, XCORE_INS_INPW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_INSHR_2r, XCORE_INS_INSHR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_INT_2r, XCORE_INS_INT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_IN_2r, XCORE_INS_IN, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_KCALL_1r, XCORE_INS_KCALL, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_KCALL_lu6, XCORE_INS_KCALL, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_KCALL_u6, XCORE_INS_KCALL, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_KENTSP_lu6, XCORE_INS_KENTSP, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_KENTSP_u6, XCORE_INS_KENTSP, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_KRESTSP_lu6, XCORE_INS_KRESTSP, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_KRESTSP_u6, XCORE_INS_KRESTSP, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_KRET_0R, XCORE_INS_KRET, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_LADD_l5r, XCORE_INS_LADD, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LD16S_3r, XCORE_INS_LD16S, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LD8U_3r, XCORE_INS_LD8U, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDA16B_l3r, XCORE_INS_LDA16, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDA16F_l3r, XCORE_INS_LDA16, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAPB_lu10, XCORE_INS_LDAP, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAPB_u10, XCORE_INS_LDAP, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAPF_lu10, XCORE_INS_LDAP, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAPF_lu10_ba, XCORE_INS_LDAP, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAPF_u10, XCORE_INS_LDAP, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAWB_l2rus, XCORE_INS_LDAW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAWB_l3r, XCORE_INS_LDAW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAWCP_lu6, XCORE_INS_LDAW, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAWCP_u6, XCORE_INS_LDAW, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAWDP_lru6, XCORE_INS_LDAW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAWDP_ru6, XCORE_INS_LDAW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAWF_l2rus, XCORE_INS_LDAW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAWF_l3r, XCORE_INS_LDAW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAWSP_lru6, XCORE_INS_LDAW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDAWSP_ru6, XCORE_INS_LDAW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDC_lru6, XCORE_INS_LDC, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDC_ru6, XCORE_INS_LDC, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDET_0R, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDIVU_l5r, XCORE_INS_LDIVU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDSED_0R, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDSPC_0R, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDSSR_0R, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDWCP_lru6, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDWCP_lu10, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_LDWCP_ru6, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDWCP_u10, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_R11, 0 }, { 0 }, 0, 0 #endif }, { XCore_LDWDP_lru6, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDWDP_ru6, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDWSP_lru6, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDWSP_ru6, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDW_2rus, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LDW_3r, XCORE_INS_LDW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LMUL_l6r, XCORE_INS_LMUL, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LSS_3r, XCORE_INS_LSS, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LSUB_l5r, XCORE_INS_LSUB, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_LSU_3r, XCORE_INS_LSU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_MACCS_l4r, XCORE_INS_MACCS, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_MACCU_l4r, XCORE_INS_MACCU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_MJOIN_1r, XCORE_INS_MJOIN, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_MKMSK_2r, XCORE_INS_MKMSK, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_MKMSK_rus, XCORE_INS_MKMSK, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_MSYNC_1r, XCORE_INS_MSYNC, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_MUL_l3r, XCORE_INS_MUL, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_NEG, XCORE_INS_NEG, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_NOT, XCORE_INS_NOT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_OR_3r, XCORE_INS_OR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_OUTCT_2r, XCORE_INS_OUTCT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_OUTCT_rus, XCORE_INS_OUTCT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_OUTPW_l2rus, XCORE_INS_OUTPW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_OUTSHR_2r, XCORE_INS_OUTSHR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_OUTT_2r, XCORE_INS_OUTT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_OUT_2r, XCORE_INS_OUT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_PEEK_2r, XCORE_INS_PEEK, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_REMS_l3r, XCORE_INS_REMS, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_REMU_l3r, XCORE_INS_REMU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_RETSP_lu6, XCORE_INS_RETSP, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_RETSP_u6, XCORE_INS_RETSP, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_SETCLK_l2r, XCORE_INS_SETCLK, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETCP_1r, XCORE_INS_SET, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETC_l2r, XCORE_INS_SETC, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETC_lru6, XCORE_INS_SETC, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETC_ru6, XCORE_INS_SETC, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETDP_1r, XCORE_INS_SET, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETD_2r, XCORE_INS_SETD, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETEV_1r, XCORE_INS_SETEV, #ifndef CAPSTONE_DIET { XCORE_REG_R11, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETKEP_0R, XCORE_INS_SET, #ifndef CAPSTONE_DIET { XCORE_REG_R11, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETN_l2r, XCORE_INS_SETN, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETPSC_2r, XCORE_INS_SETPSC, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETPS_l2r, XCORE_INS_SET, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETPT_2r, XCORE_INS_SETPT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETRDY_l2r, XCORE_INS_SETRDY, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETSP_1r, XCORE_INS_SET, #ifndef CAPSTONE_DIET { 0 }, { XCORE_REG_SP, 0 }, { 0 }, 0, 0 #endif }, { XCore_SETSR_branch_lu6, XCORE_INS_SETSR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 1 #endif }, { XCore_SETSR_branch_u6, XCORE_INS_SETSR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 1 #endif }, { XCore_SETSR_lu6, XCORE_INS_SETSR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETSR_u6, XCORE_INS_SETSR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETTW_l2r, XCORE_INS_SETTW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SETV_1r, XCORE_INS_SETV, #ifndef CAPSTONE_DIET { XCORE_REG_R11, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SEXT_2r, XCORE_INS_SEXT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SEXT_rus, XCORE_INS_SEXT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SHL_2rus, XCORE_INS_SHL, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SHL_3r, XCORE_INS_SHL, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SHR_2rus, XCORE_INS_SHR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SHR_3r, XCORE_INS_SHR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SSYNC_0r, XCORE_INS_SSYNC, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ST16_l3r, XCORE_INS_ST16, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ST8_l3r, XCORE_INS_ST8, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_STET_0R, XCORE_INS_STW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_STSED_0R, XCORE_INS_STW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_STSPC_0R, XCORE_INS_STW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_STSSR_0R, XCORE_INS_STW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_STWDP_lru6, XCORE_INS_STW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_STWDP_ru6, XCORE_INS_STW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_STWSP_lru6, XCORE_INS_STW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_STWSP_ru6, XCORE_INS_STW, #ifndef CAPSTONE_DIET { XCORE_REG_SP, 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_STW_2rus, XCORE_INS_STW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_STW_l3r, XCORE_INS_STW, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SUB_2rus, XCORE_INS_SUB, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SUB_3r, XCORE_INS_SUB, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_SYNCR_1r, XCORE_INS_SYNCR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_TESTCT_2r, XCORE_INS_TESTCT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_TESTLCL_l2r, XCORE_INS_TESTLCL, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_TESTWCT_2r, XCORE_INS_TESTWCT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_TSETMR_2r, XCORE_INS_TSETMR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_TSETR_3r, XCORE_INS_SET, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_TSTART_1R, XCORE_INS_START, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_WAITEF_1R, XCORE_INS_WAITEF, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_WAITET_1R, XCORE_INS_WAITET, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_WAITEU_0R, XCORE_INS_WAITEU, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 1, 1 #endif }, { XCore_XOR_l3r, XCORE_INS_XOR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ZEXT_2r, XCORE_INS_ZEXT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, { XCore_ZEXT_rus, XCORE_INS_ZEXT, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif }, }; // given internal insn id, return public instruction info void XCore_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id) { unsigned short i; i = insn_find(insns, ARR_SIZE(insns), id, &h->insn_cache); if (i != 0) { insn->id = insns[i].mapid; if (h->detail) { #ifndef CAPSTONE_DIET memcpy(insn->detail->regs_read, insns[i].regs_use, sizeof(insns[i].regs_use)); insn->detail->regs_read_count = (uint8_t)count_positive(insns[i].regs_use); memcpy(insn->detail->regs_write, insns[i].regs_mod, sizeof(insns[i].regs_mod)); insn->detail->regs_write_count = (uint8_t)count_positive(insns[i].regs_mod); memcpy(insn->detail->groups, insns[i].groups, sizeof(insns[i].groups)); insn->detail->groups_count = (uint8_t)count_positive(insns[i].groups); if (insns[i].branch || insns[i].indirect_branch) { // this insn also belongs to JUMP group. add JUMP group insn->detail->groups[insn->detail->groups_count] = XCORE_GRP_JUMP; insn->detail->groups_count++; } #endif } } } #ifndef CAPSTONE_DIET static name_map insn_name_maps[] = { { XCORE_INS_INVALID, NULL }, { XCORE_INS_ADD, "add" }, { XCORE_INS_ANDNOT, "andnot" }, { XCORE_INS_AND, "and" }, { XCORE_INS_ASHR, "ashr" }, { XCORE_INS_BAU, "bau" }, { XCORE_INS_BITREV, "bitrev" }, { XCORE_INS_BLA, "bla" }, { XCORE_INS_BLAT, "blat" }, { XCORE_INS_BL, "bl" }, { XCORE_INS_BF, "bf" }, { XCORE_INS_BT, "bt" }, { XCORE_INS_BU, "bu" }, { XCORE_INS_BRU, "bru" }, { XCORE_INS_BYTEREV, "byterev" }, { XCORE_INS_CHKCT, "chkct" }, { XCORE_INS_CLRE, "clre" }, { XCORE_INS_CLRPT, "clrpt" }, { XCORE_INS_CLRSR, "clrsr" }, { XCORE_INS_CLZ, "clz" }, { XCORE_INS_CRC8, "crc8" }, { XCORE_INS_CRC32, "crc32" }, { XCORE_INS_DCALL, "dcall" }, { XCORE_INS_DENTSP, "dentsp" }, { XCORE_INS_DGETREG, "dgetreg" }, { XCORE_INS_DIVS, "divs" }, { XCORE_INS_DIVU, "divu" }, { XCORE_INS_DRESTSP, "drestsp" }, { XCORE_INS_DRET, "dret" }, { XCORE_INS_ECALLF, "ecallf" }, { XCORE_INS_ECALLT, "ecallt" }, { XCORE_INS_EDU, "edu" }, { XCORE_INS_EEF, "eef" }, { XCORE_INS_EET, "eet" }, { XCORE_INS_EEU, "eeu" }, { XCORE_INS_ENDIN, "endin" }, { XCORE_INS_ENTSP, "entsp" }, { XCORE_INS_EQ, "eq" }, { XCORE_INS_EXTDP, "extdp" }, { XCORE_INS_EXTSP, "extsp" }, { XCORE_INS_FREER, "freer" }, { XCORE_INS_FREET, "freet" }, { XCORE_INS_GETD, "getd" }, { XCORE_INS_GET, "get" }, { XCORE_INS_GETN, "getn" }, { XCORE_INS_GETR, "getr" }, { XCORE_INS_GETSR, "getsr" }, { XCORE_INS_GETST, "getst" }, { XCORE_INS_GETTS, "getts" }, { XCORE_INS_INCT, "inct" }, { XCORE_INS_INIT, "init" }, { XCORE_INS_INPW, "inpw" }, { XCORE_INS_INSHR, "inshr" }, { XCORE_INS_INT, "int" }, { XCORE_INS_IN, "in" }, { XCORE_INS_KCALL, "kcall" }, { XCORE_INS_KENTSP, "kentsp" }, { XCORE_INS_KRESTSP, "krestsp" }, { XCORE_INS_KRET, "kret" }, { XCORE_INS_LADD, "ladd" }, { XCORE_INS_LD16S, "ld16s" }, { XCORE_INS_LD8U, "ld8u" }, { XCORE_INS_LDA16, "lda16" }, { XCORE_INS_LDAP, "ldap" }, { XCORE_INS_LDAW, "ldaw" }, { XCORE_INS_LDC, "ldc" }, { XCORE_INS_LDW, "ldw" }, { XCORE_INS_LDIVU, "ldivu" }, { XCORE_INS_LMUL, "lmul" }, { XCORE_INS_LSS, "lss" }, { XCORE_INS_LSUB, "lsub" }, { XCORE_INS_LSU, "lsu" }, { XCORE_INS_MACCS, "maccs" }, { XCORE_INS_MACCU, "maccu" }, { XCORE_INS_MJOIN, "mjoin" }, { XCORE_INS_MKMSK, "mkmsk" }, { XCORE_INS_MSYNC, "msync" }, { XCORE_INS_MUL, "mul" }, { XCORE_INS_NEG, "neg" }, { XCORE_INS_NOT, "not" }, { XCORE_INS_OR, "or" }, { XCORE_INS_OUTCT, "outct" }, { XCORE_INS_OUTPW, "outpw" }, { XCORE_INS_OUTSHR, "outshr" }, { XCORE_INS_OUTT, "outt" }, { XCORE_INS_OUT, "out" }, { XCORE_INS_PEEK, "peek" }, { XCORE_INS_REMS, "rems" }, { XCORE_INS_REMU, "remu" }, { XCORE_INS_RETSP, "retsp" }, { XCORE_INS_SETCLK, "setclk" }, { XCORE_INS_SET, "set" }, { XCORE_INS_SETC, "setc" }, { XCORE_INS_SETD, "setd" }, { XCORE_INS_SETEV, "setev" }, { XCORE_INS_SETN, "setn" }, { XCORE_INS_SETPSC, "setpsc" }, { XCORE_INS_SETPT, "setpt" }, { XCORE_INS_SETRDY, "setrdy" }, { XCORE_INS_SETSR, "setsr" }, { XCORE_INS_SETTW, "settw" }, { XCORE_INS_SETV, "setv" }, { XCORE_INS_SEXT, "sext" }, { XCORE_INS_SHL, "shl" }, { XCORE_INS_SHR, "shr" }, { XCORE_INS_SSYNC, "ssync" }, { XCORE_INS_ST16, "st16" }, { XCORE_INS_ST8, "st8" }, { XCORE_INS_STW, "stw" }, { XCORE_INS_SUB, "sub" }, { XCORE_INS_SYNCR, "syncr" }, { XCORE_INS_TESTCT, "testct" }, { XCORE_INS_TESTLCL, "testlcl" }, { XCORE_INS_TESTWCT, "testwct" }, { XCORE_INS_TSETMR, "tsetmr" }, { XCORE_INS_START, "start" }, { XCORE_INS_WAITEF, "waitef" }, { XCORE_INS_WAITET, "waitet" }, { XCORE_INS_WAITEU, "waiteu" }, { XCORE_INS_XOR, "xor" }, { XCORE_INS_ZEXT, "zext" }, }; // special alias insn static name_map alias_insn_names[] = { { 0, NULL } }; #endif const char *XCore_insn_name(csh handle, unsigned int id) { #ifndef CAPSTONE_DIET unsigned int i; if (id >= XCORE_INS_ENDING) return NULL; // handle special alias first for (i = 0; i < ARR_SIZE(alias_insn_names); i++) { if (alias_insn_names[i].id == id) return alias_insn_names[i].name; } return insn_name_maps[id].name; #else return NULL; #endif } #ifndef CAPSTONE_DIET static name_map group_name_maps[] = { { XCORE_GRP_INVALID, NULL }, { XCORE_GRP_JUMP, "jump" }, }; #endif const char *XCore_group_name(csh handle, unsigned int id) { #ifndef CAPSTONE_DIET if (id >= XCORE_GRP_ENDING) return NULL; return group_name_maps[id].name; #else return NULL; #endif } // map internal raw register to 'public' register xcore_reg XCore_map_register(unsigned int r) { static unsigned int map[] = { 0, }; if (r < ARR_SIZE(map)) return map[r]; // cannot find this register return 0; } #endif
the_stack_data/140764275.c
extern float __VERIFIER_nondet_float(void); extern int __VERIFIER_nondet_int(void); typedef enum {false, true} bool; bool __VERIFIER_nondet_bool(void) { return __VERIFIER_nondet_int() != 0; } int main() { bool _EL_X_848, _x__EL_X_848; bool _EL_X_855, _x__EL_X_855; float x_1, _x_x_1; float x_3, _x_x_3; float x_0, _x_x_0; float x_5, _x_x_5; float x_6, _x_x_6; float x_9, _x_x_9; float x_10, _x_x_10; float x_11, _x_x_11; float x_12, _x_x_12; float x_2, _x_x_2; float x_7, _x_x_7; float x_8, _x_x_8; float x_13, _x_x_13; float x_15, _x_x_15; bool _EL_U_853, _x__EL_U_853; float x_14, _x_x_14; float x_4, _x_x_4; int __steps_to_fair = __VERIFIER_nondet_int(); _EL_X_848 = __VERIFIER_nondet_bool(); _EL_X_855 = __VERIFIER_nondet_bool(); x_1 = __VERIFIER_nondet_float(); x_3 = __VERIFIER_nondet_float(); x_0 = __VERIFIER_nondet_float(); x_5 = __VERIFIER_nondet_float(); x_6 = __VERIFIER_nondet_float(); x_9 = __VERIFIER_nondet_float(); x_10 = __VERIFIER_nondet_float(); x_11 = __VERIFIER_nondet_float(); x_12 = __VERIFIER_nondet_float(); x_2 = __VERIFIER_nondet_float(); x_7 = __VERIFIER_nondet_float(); x_8 = __VERIFIER_nondet_float(); x_13 = __VERIFIER_nondet_float(); x_15 = __VERIFIER_nondet_float(); _EL_U_853 = __VERIFIER_nondet_bool(); x_14 = __VERIFIER_nondet_float(); x_4 = __VERIFIER_nondet_float(); bool __ok = (1 && ( !(_EL_X_855 && ( !_EL_X_848)))); while (__steps_to_fair >= 0 && __ok) { if ((( !((x_9 + (-1.0 * x_14)) <= 9.0)) || ( !(( !((x_9 + (-1.0 * x_14)) <= 9.0)) || _EL_U_853)))) { __steps_to_fair = __VERIFIER_nondet_int(); } else { __steps_to_fair--; } _x__EL_X_848 = __VERIFIER_nondet_bool(); _x__EL_X_855 = __VERIFIER_nondet_bool(); _x_x_1 = __VERIFIER_nondet_float(); _x_x_3 = __VERIFIER_nondet_float(); _x_x_0 = __VERIFIER_nondet_float(); _x_x_5 = __VERIFIER_nondet_float(); _x_x_6 = __VERIFIER_nondet_float(); _x_x_9 = __VERIFIER_nondet_float(); _x_x_10 = __VERIFIER_nondet_float(); _x_x_11 = __VERIFIER_nondet_float(); _x_x_12 = __VERIFIER_nondet_float(); _x_x_2 = __VERIFIER_nondet_float(); _x_x_7 = __VERIFIER_nondet_float(); _x_x_8 = __VERIFIER_nondet_float(); _x_x_13 = __VERIFIER_nondet_float(); _x_x_15 = __VERIFIER_nondet_float(); _x__EL_U_853 = __VERIFIER_nondet_bool(); _x_x_14 = __VERIFIER_nondet_float(); _x_x_4 = __VERIFIER_nondet_float(); __ok = ((((((((((((((((((((x_13 + (-1.0 * _x_x_0)) <= -18.0) && (((x_11 + (-1.0 * _x_x_0)) <= -3.0) && (((x_10 + (-1.0 * _x_x_0)) <= -15.0) && (((x_9 + (-1.0 * _x_x_0)) <= -3.0) && (((x_8 + (-1.0 * _x_x_0)) <= -1.0) && (((x_6 + (-1.0 * _x_x_0)) <= -16.0) && (((x_2 + (-1.0 * _x_x_0)) <= -12.0) && ((x_3 + (-1.0 * _x_x_0)) <= -10.0)))))))) && (((x_13 + (-1.0 * _x_x_0)) == -18.0) || (((x_11 + (-1.0 * _x_x_0)) == -3.0) || (((x_10 + (-1.0 * _x_x_0)) == -15.0) || (((x_9 + (-1.0 * _x_x_0)) == -3.0) || (((x_8 + (-1.0 * _x_x_0)) == -1.0) || (((x_6 + (-1.0 * _x_x_0)) == -16.0) || (((x_2 + (-1.0 * _x_x_0)) == -12.0) || ((x_3 + (-1.0 * _x_x_0)) == -10.0))))))))) && ((((x_15 + (-1.0 * _x_x_1)) <= -10.0) && (((x_12 + (-1.0 * _x_x_1)) <= -6.0) && (((x_11 + (-1.0 * _x_x_1)) <= -6.0) && (((x_10 + (-1.0 * _x_x_1)) <= -20.0) && (((x_9 + (-1.0 * _x_x_1)) <= -17.0) && (((x_7 + (-1.0 * _x_x_1)) <= -8.0) && (((x_3 + (-1.0 * _x_x_1)) <= -5.0) && ((x_5 + (-1.0 * _x_x_1)) <= -11.0)))))))) && (((x_15 + (-1.0 * _x_x_1)) == -10.0) || (((x_12 + (-1.0 * _x_x_1)) == -6.0) || (((x_11 + (-1.0 * _x_x_1)) == -6.0) || (((x_10 + (-1.0 * _x_x_1)) == -20.0) || (((x_9 + (-1.0 * _x_x_1)) == -17.0) || (((x_7 + (-1.0 * _x_x_1)) == -8.0) || (((x_3 + (-1.0 * _x_x_1)) == -5.0) || ((x_5 + (-1.0 * _x_x_1)) == -11.0)))))))))) && ((((x_15 + (-1.0 * _x_x_2)) <= -14.0) && (((x_13 + (-1.0 * _x_x_2)) <= -6.0) && (((x_12 + (-1.0 * _x_x_2)) <= -19.0) && (((x_11 + (-1.0 * _x_x_2)) <= -11.0) && (((x_8 + (-1.0 * _x_x_2)) <= -9.0) && (((x_6 + (-1.0 * _x_x_2)) <= -12.0) && (((x_0 + (-1.0 * _x_x_2)) <= -15.0) && ((x_3 + (-1.0 * _x_x_2)) <= -19.0)))))))) && (((x_15 + (-1.0 * _x_x_2)) == -14.0) || (((x_13 + (-1.0 * _x_x_2)) == -6.0) || (((x_12 + (-1.0 * _x_x_2)) == -19.0) || (((x_11 + (-1.0 * _x_x_2)) == -11.0) || (((x_8 + (-1.0 * _x_x_2)) == -9.0) || (((x_6 + (-1.0 * _x_x_2)) == -12.0) || (((x_0 + (-1.0 * _x_x_2)) == -15.0) || ((x_3 + (-1.0 * _x_x_2)) == -19.0)))))))))) && ((((x_15 + (-1.0 * _x_x_3)) <= -17.0) && (((x_12 + (-1.0 * _x_x_3)) <= -11.0) && (((x_10 + (-1.0 * _x_x_3)) <= -14.0) && (((x_8 + (-1.0 * _x_x_3)) <= -14.0) && (((x_7 + (-1.0 * _x_x_3)) <= -16.0) && (((x_6 + (-1.0 * _x_x_3)) <= -13.0) && (((x_1 + (-1.0 * _x_x_3)) <= -16.0) && ((x_5 + (-1.0 * _x_x_3)) <= -18.0)))))))) && (((x_15 + (-1.0 * _x_x_3)) == -17.0) || (((x_12 + (-1.0 * _x_x_3)) == -11.0) || (((x_10 + (-1.0 * _x_x_3)) == -14.0) || (((x_8 + (-1.0 * _x_x_3)) == -14.0) || (((x_7 + (-1.0 * _x_x_3)) == -16.0) || (((x_6 + (-1.0 * _x_x_3)) == -13.0) || (((x_1 + (-1.0 * _x_x_3)) == -16.0) || ((x_5 + (-1.0 * _x_x_3)) == -18.0)))))))))) && ((((x_14 + (-1.0 * _x_x_4)) <= -6.0) && (((x_13 + (-1.0 * _x_x_4)) <= -18.0) && (((x_12 + (-1.0 * _x_x_4)) <= -13.0) && (((x_10 + (-1.0 * _x_x_4)) <= -17.0) && (((x_9 + (-1.0 * _x_x_4)) <= -3.0) && (((x_8 + (-1.0 * _x_x_4)) <= -17.0) && (((x_1 + (-1.0 * _x_x_4)) <= -3.0) && ((x_7 + (-1.0 * _x_x_4)) <= -9.0)))))))) && (((x_14 + (-1.0 * _x_x_4)) == -6.0) || (((x_13 + (-1.0 * _x_x_4)) == -18.0) || (((x_12 + (-1.0 * _x_x_4)) == -13.0) || (((x_10 + (-1.0 * _x_x_4)) == -17.0) || (((x_9 + (-1.0 * _x_x_4)) == -3.0) || (((x_8 + (-1.0 * _x_x_4)) == -17.0) || (((x_1 + (-1.0 * _x_x_4)) == -3.0) || ((x_7 + (-1.0 * _x_x_4)) == -9.0)))))))))) && ((((x_15 + (-1.0 * _x_x_5)) <= -14.0) && (((x_14 + (-1.0 * _x_x_5)) <= -1.0) && (((x_13 + (-1.0 * _x_x_5)) <= -3.0) && (((x_10 + (-1.0 * _x_x_5)) <= -15.0) && (((x_4 + (-1.0 * _x_x_5)) <= -12.0) && (((x_2 + (-1.0 * _x_x_5)) <= -9.0) && (((x_0 + (-1.0 * _x_x_5)) <= -20.0) && ((x_1 + (-1.0 * _x_x_5)) <= -6.0)))))))) && (((x_15 + (-1.0 * _x_x_5)) == -14.0) || (((x_14 + (-1.0 * _x_x_5)) == -1.0) || (((x_13 + (-1.0 * _x_x_5)) == -3.0) || (((x_10 + (-1.0 * _x_x_5)) == -15.0) || (((x_4 + (-1.0 * _x_x_5)) == -12.0) || (((x_2 + (-1.0 * _x_x_5)) == -9.0) || (((x_0 + (-1.0 * _x_x_5)) == -20.0) || ((x_1 + (-1.0 * _x_x_5)) == -6.0)))))))))) && ((((x_14 + (-1.0 * _x_x_6)) <= -6.0) && (((x_13 + (-1.0 * _x_x_6)) <= -3.0) && (((x_12 + (-1.0 * _x_x_6)) <= -5.0) && (((x_11 + (-1.0 * _x_x_6)) <= -5.0) && (((x_10 + (-1.0 * _x_x_6)) <= -18.0) && (((x_3 + (-1.0 * _x_x_6)) <= -19.0) && (((x_1 + (-1.0 * _x_x_6)) <= -3.0) && ((x_2 + (-1.0 * _x_x_6)) <= -3.0)))))))) && (((x_14 + (-1.0 * _x_x_6)) == -6.0) || (((x_13 + (-1.0 * _x_x_6)) == -3.0) || (((x_12 + (-1.0 * _x_x_6)) == -5.0) || (((x_11 + (-1.0 * _x_x_6)) == -5.0) || (((x_10 + (-1.0 * _x_x_6)) == -18.0) || (((x_3 + (-1.0 * _x_x_6)) == -19.0) || (((x_1 + (-1.0 * _x_x_6)) == -3.0) || ((x_2 + (-1.0 * _x_x_6)) == -3.0)))))))))) && ((((x_14 + (-1.0 * _x_x_7)) <= -7.0) && (((x_13 + (-1.0 * _x_x_7)) <= -19.0) && (((x_12 + (-1.0 * _x_x_7)) <= -12.0) && (((x_11 + (-1.0 * _x_x_7)) <= -12.0) && (((x_10 + (-1.0 * _x_x_7)) <= -14.0) && (((x_9 + (-1.0 * _x_x_7)) <= -9.0) && (((x_1 + (-1.0 * _x_x_7)) <= -20.0) && ((x_4 + (-1.0 * _x_x_7)) <= -13.0)))))))) && (((x_14 + (-1.0 * _x_x_7)) == -7.0) || (((x_13 + (-1.0 * _x_x_7)) == -19.0) || (((x_12 + (-1.0 * _x_x_7)) == -12.0) || (((x_11 + (-1.0 * _x_x_7)) == -12.0) || (((x_10 + (-1.0 * _x_x_7)) == -14.0) || (((x_9 + (-1.0 * _x_x_7)) == -9.0) || (((x_1 + (-1.0 * _x_x_7)) == -20.0) || ((x_4 + (-1.0 * _x_x_7)) == -13.0)))))))))) && ((((x_15 + (-1.0 * _x_x_8)) <= -13.0) && (((x_13 + (-1.0 * _x_x_8)) <= -19.0) && (((x_10 + (-1.0 * _x_x_8)) <= -10.0) && (((x_9 + (-1.0 * _x_x_8)) <= -12.0) && (((x_4 + (-1.0 * _x_x_8)) <= -2.0) && (((x_3 + (-1.0 * _x_x_8)) <= -8.0) && (((x_1 + (-1.0 * _x_x_8)) <= -2.0) && ((x_2 + (-1.0 * _x_x_8)) <= -2.0)))))))) && (((x_15 + (-1.0 * _x_x_8)) == -13.0) || (((x_13 + (-1.0 * _x_x_8)) == -19.0) || (((x_10 + (-1.0 * _x_x_8)) == -10.0) || (((x_9 + (-1.0 * _x_x_8)) == -12.0) || (((x_4 + (-1.0 * _x_x_8)) == -2.0) || (((x_3 + (-1.0 * _x_x_8)) == -8.0) || (((x_1 + (-1.0 * _x_x_8)) == -2.0) || ((x_2 + (-1.0 * _x_x_8)) == -2.0)))))))))) && ((((x_15 + (-1.0 * _x_x_9)) <= -19.0) && (((x_14 + (-1.0 * _x_x_9)) <= -2.0) && (((x_12 + (-1.0 * _x_x_9)) <= -20.0) && (((x_11 + (-1.0 * _x_x_9)) <= -11.0) && (((x_9 + (-1.0 * _x_x_9)) <= -6.0) && (((x_7 + (-1.0 * _x_x_9)) <= -19.0) && (((x_3 + (-1.0 * _x_x_9)) <= -2.0) && ((x_4 + (-1.0 * _x_x_9)) <= -5.0)))))))) && (((x_15 + (-1.0 * _x_x_9)) == -19.0) || (((x_14 + (-1.0 * _x_x_9)) == -2.0) || (((x_12 + (-1.0 * _x_x_9)) == -20.0) || (((x_11 + (-1.0 * _x_x_9)) == -11.0) || (((x_9 + (-1.0 * _x_x_9)) == -6.0) || (((x_7 + (-1.0 * _x_x_9)) == -19.0) || (((x_3 + (-1.0 * _x_x_9)) == -2.0) || ((x_4 + (-1.0 * _x_x_9)) == -5.0)))))))))) && ((((x_14 + (-1.0 * _x_x_10)) <= -9.0) && (((x_13 + (-1.0 * _x_x_10)) <= -12.0) && (((x_12 + (-1.0 * _x_x_10)) <= -11.0) && (((x_10 + (-1.0 * _x_x_10)) <= -12.0) && (((x_9 + (-1.0 * _x_x_10)) <= -4.0) && (((x_7 + (-1.0 * _x_x_10)) <= -8.0) && (((x_1 + (-1.0 * _x_x_10)) <= -16.0) && ((x_6 + (-1.0 * _x_x_10)) <= -19.0)))))))) && (((x_14 + (-1.0 * _x_x_10)) == -9.0) || (((x_13 + (-1.0 * _x_x_10)) == -12.0) || (((x_12 + (-1.0 * _x_x_10)) == -11.0) || (((x_10 + (-1.0 * _x_x_10)) == -12.0) || (((x_9 + (-1.0 * _x_x_10)) == -4.0) || (((x_7 + (-1.0 * _x_x_10)) == -8.0) || (((x_1 + (-1.0 * _x_x_10)) == -16.0) || ((x_6 + (-1.0 * _x_x_10)) == -19.0)))))))))) && ((((x_15 + (-1.0 * _x_x_11)) <= -4.0) && (((x_14 + (-1.0 * _x_x_11)) <= -18.0) && (((x_12 + (-1.0 * _x_x_11)) <= -15.0) && (((x_8 + (-1.0 * _x_x_11)) <= -19.0) && (((x_6 + (-1.0 * _x_x_11)) <= -18.0) && (((x_4 + (-1.0 * _x_x_11)) <= -12.0) && (((x_0 + (-1.0 * _x_x_11)) <= -9.0) && ((x_2 + (-1.0 * _x_x_11)) <= -13.0)))))))) && (((x_15 + (-1.0 * _x_x_11)) == -4.0) || (((x_14 + (-1.0 * _x_x_11)) == -18.0) || (((x_12 + (-1.0 * _x_x_11)) == -15.0) || (((x_8 + (-1.0 * _x_x_11)) == -19.0) || (((x_6 + (-1.0 * _x_x_11)) == -18.0) || (((x_4 + (-1.0 * _x_x_11)) == -12.0) || (((x_0 + (-1.0 * _x_x_11)) == -9.0) || ((x_2 + (-1.0 * _x_x_11)) == -13.0)))))))))) && ((((x_15 + (-1.0 * _x_x_12)) <= -16.0) && (((x_13 + (-1.0 * _x_x_12)) <= -1.0) && (((x_12 + (-1.0 * _x_x_12)) <= -12.0) && (((x_9 + (-1.0 * _x_x_12)) <= -10.0) && (((x_7 + (-1.0 * _x_x_12)) <= -6.0) && (((x_6 + (-1.0 * _x_x_12)) <= -13.0) && (((x_2 + (-1.0 * _x_x_12)) <= -11.0) && ((x_4 + (-1.0 * _x_x_12)) <= -12.0)))))))) && (((x_15 + (-1.0 * _x_x_12)) == -16.0) || (((x_13 + (-1.0 * _x_x_12)) == -1.0) || (((x_12 + (-1.0 * _x_x_12)) == -12.0) || (((x_9 + (-1.0 * _x_x_12)) == -10.0) || (((x_7 + (-1.0 * _x_x_12)) == -6.0) || (((x_6 + (-1.0 * _x_x_12)) == -13.0) || (((x_2 + (-1.0 * _x_x_12)) == -11.0) || ((x_4 + (-1.0 * _x_x_12)) == -12.0)))))))))) && ((((x_13 + (-1.0 * _x_x_13)) <= -17.0) && (((x_12 + (-1.0 * _x_x_13)) <= -3.0) && (((x_11 + (-1.0 * _x_x_13)) <= -3.0) && (((x_8 + (-1.0 * _x_x_13)) <= -15.0) && (((x_7 + (-1.0 * _x_x_13)) <= -19.0) && (((x_6 + (-1.0 * _x_x_13)) <= -3.0) && (((x_4 + (-1.0 * _x_x_13)) <= -2.0) && ((x_5 + (-1.0 * _x_x_13)) <= -9.0)))))))) && (((x_13 + (-1.0 * _x_x_13)) == -17.0) || (((x_12 + (-1.0 * _x_x_13)) == -3.0) || (((x_11 + (-1.0 * _x_x_13)) == -3.0) || (((x_8 + (-1.0 * _x_x_13)) == -15.0) || (((x_7 + (-1.0 * _x_x_13)) == -19.0) || (((x_6 + (-1.0 * _x_x_13)) == -3.0) || (((x_4 + (-1.0 * _x_x_13)) == -2.0) || ((x_5 + (-1.0 * _x_x_13)) == -9.0)))))))))) && ((((x_15 + (-1.0 * _x_x_14)) <= -5.0) && (((x_13 + (-1.0 * _x_x_14)) <= -10.0) && (((x_11 + (-1.0 * _x_x_14)) <= -14.0) && (((x_10 + (-1.0 * _x_x_14)) <= -13.0) && (((x_8 + (-1.0 * _x_x_14)) <= -14.0) && (((x_7 + (-1.0 * _x_x_14)) <= -1.0) && (((x_0 + (-1.0 * _x_x_14)) <= -17.0) && ((x_6 + (-1.0 * _x_x_14)) <= -19.0)))))))) && (((x_15 + (-1.0 * _x_x_14)) == -5.0) || (((x_13 + (-1.0 * _x_x_14)) == -10.0) || (((x_11 + (-1.0 * _x_x_14)) == -14.0) || (((x_10 + (-1.0 * _x_x_14)) == -13.0) || (((x_8 + (-1.0 * _x_x_14)) == -14.0) || (((x_7 + (-1.0 * _x_x_14)) == -1.0) || (((x_0 + (-1.0 * _x_x_14)) == -17.0) || ((x_6 + (-1.0 * _x_x_14)) == -19.0)))))))))) && ((((x_12 + (-1.0 * _x_x_15)) <= -5.0) && (((x_11 + (-1.0 * _x_x_15)) <= -5.0) && (((x_10 + (-1.0 * _x_x_15)) <= -18.0) && (((x_9 + (-1.0 * _x_x_15)) <= -9.0) && (((x_6 + (-1.0 * _x_x_15)) <= -13.0) && (((x_5 + (-1.0 * _x_x_15)) <= -18.0) && (((x_0 + (-1.0 * _x_x_15)) <= -1.0) && ((x_3 + (-1.0 * _x_x_15)) <= -18.0)))))))) && (((x_12 + (-1.0 * _x_x_15)) == -5.0) || (((x_11 + (-1.0 * _x_x_15)) == -5.0) || (((x_10 + (-1.0 * _x_x_15)) == -18.0) || (((x_9 + (-1.0 * _x_x_15)) == -9.0) || (((x_6 + (-1.0 * _x_x_15)) == -13.0) || (((x_5 + (-1.0 * _x_x_15)) == -18.0) || (((x_0 + (-1.0 * _x_x_15)) == -1.0) || ((x_3 + (-1.0 * _x_x_15)) == -18.0)))))))))) && ((_EL_X_848 == (8.0 <= (_x_x_3 + (-1.0 * _x_x_13)))) && ((_EL_U_853 == (_x__EL_U_853 || ( !((_x_x_9 + (-1.0 * _x_x_14)) <= 9.0)))) && (_EL_X_855 == ( !(_x__EL_U_853 || ( !((_x_x_9 + (-1.0 * _x_x_14)) <= 9.0)))))))); _EL_X_848 = _x__EL_X_848; _EL_X_855 = _x__EL_X_855; x_1 = _x_x_1; x_3 = _x_x_3; x_0 = _x_x_0; x_5 = _x_x_5; x_6 = _x_x_6; x_9 = _x_x_9; x_10 = _x_x_10; x_11 = _x_x_11; x_12 = _x_x_12; x_2 = _x_x_2; x_7 = _x_x_7; x_8 = _x_x_8; x_13 = _x_x_13; x_15 = _x_x_15; _EL_U_853 = _x__EL_U_853; x_14 = _x_x_14; x_4 = _x_x_4; } }
the_stack_data/119108.c
/* PR tree-optimization/63464 */ /* { dg-do compile } */ /* { dg-options "-O2 -fdump-tree-optimized" } */ void bar (void); void foo (int x) { if (x != 2 && x != 3 && x != 10 && x != 11 && x != 17 && x != 18 && x != 23) bar (); } /* Check if the tests have been folded into a bit test. */ /* { dg-final { scan-tree-dump "(8784908|0x0*860c0c)" "optimized" { target i?86-*-* x86_64-*-* } } } */ /* { dg-final { scan-tree-dump "(<<|>>)" "optimized" { target i?86-*-* x86_64-*-* } } } */
the_stack_data/471317.c
foo (a, b) int a, b; { return (a < 0) | (a <= 0) | (a == 0) | (a != 0) | (a >= 0) | (a > 0); }
the_stack_data/578362.c
#include <stdio.h> extern char *stringfn(void); int main(int argc, char **argv) { printf("%s\n", stringfn()); return 0; }
the_stack_data/173578760.c
#include <stdio.h> #include <math.h> #include <stdbool.h> #include <stdlib.h> u_int32_t n5 = 3452775555; u_int32_t n6 = 2223466090; u_int64_t plaintexts[256] = { 0x6C, 0x64, 0x66, 0x62, 0x6A, 0x65, 0x6B, 0x69, 0x6E, 0x68, 0x6D, 0x67, 0x60, 0x63, 0x6F, 0x61, 0x8C, 0x84, 0x86, 0x82, 0x8A, 0x85, 0x8B, 0x89, 0x8E, 0x88, 0x8D, 0x87, 0x80, 0x83, 0x8F, 0x81, 0x2C, 0x24, 0x26, 0x22, 0x2A, 0x25, 0x2B, 0x29, 0x2E, 0x28, 0x2D, 0x27, 0x20, 0x23, 0x2F, 0x21, 0x3C, 0x34, 0x36, 0x32, 0x3A, 0x35, 0x3B, 0x39, 0x3E, 0x38, 0x3D, 0x37, 0x30, 0x33, 0x3F, 0x31, 0x9C, 0x94, 0x96, 0x92, 0x9A, 0x95, 0x9B, 0x99, 0x9E, 0x98, 0x9D, 0x97, 0x90, 0x93, 0x9F, 0x91, 0xAC, 0xA4, 0xA6, 0xA2, 0xAA, 0xA5, 0xAB, 0xA9, 0xAE, 0xA8, 0xAD, 0xA7, 0xA0, 0xA3, 0xAF, 0xA1, 0x5C, 0x54, 0x56, 0x52, 0x5A, 0x55, 0x5B, 0x59, 0x5E, 0x58, 0x5D, 0x57, 0x50, 0x53, 0x5F, 0x51, 0xCC, 0xC4, 0xC6, 0xC2, 0xCA, 0xC5, 0xCB, 0xC9, 0xCE, 0xC8, 0xCD, 0xC7, 0xC0, 0xC3, 0xCF, 0xC1, 0x1C, 0x14, 0x16, 0x12, 0x1A, 0x15, 0x1B, 0x19, 0x1E, 0x18, 0x1D, 0x17, 0x10, 0x13, 0x1F, 0x11, 0xEC, 0xE4, 0xE6, 0xE2, 0xEA, 0xE5, 0xEB, 0xE9, 0xEE, 0xE8, 0xED, 0xE7, 0xE0, 0xE3, 0xEF, 0xE1, 0x4C, 0x44, 0x46, 0x42, 0x4A, 0x45, 0x4B, 0x49, 0x4E, 0x48, 0x4D, 0x47, 0x40, 0x43, 0x4F, 0x41, 0x7C, 0x74, 0x76, 0x72, 0x7A, 0x75, 0x7B, 0x79, 0x7E, 0x78, 0x7D, 0x77, 0x70, 0x73, 0x7F, 0x71, 0xBC, 0xB4, 0xB6, 0xB2, 0xBA, 0xB5, 0xBB, 0xB9, 0xBE, 0xB8, 0xBD, 0xB7, 0xB0, 0xB3, 0xBF, 0xB1, 0xDC, 0xD4, 0xD6, 0xD2, 0xDA, 0xD5, 0xDB, 0xD9, 0xDE, 0xD8, 0xDD, 0xD7, 0xD0, 0xD3, 0xDF, 0xD1, 0x0C, 0x04, 0x06, 0x02, 0x0A, 0x05, 0x0B, 0x09, 0x0E, 0x08, 0x0D, 0x07, 0x00, 0x03, 0x0F, 0x01, 0xFC, 0xF4, 0xF6, 0xF2, 0xFA, 0xF5, 0xFB, 0xF9, 0xFE, 0xF8, 0xFD, 0xF7, 0xF0, 0xF3, 0xFF, 0xF1, }; //один такт u_int64_t tact(u_int64_t T, u_int32_t key, u_int32_t s) { u_int32_t L, R; L = (T & 0xFFFFFFFF00000000) >> 32; R = T & 0x00000000FFFFFFFF; u_int64_t new_r; new_r = R+key; u_int64_t mod = pow(2, 32); new_r = new_r%mod; u_int32_t f[8]; f[0] = 0x0000000F; f[1] = 0x000000F0; f[2] = 0x00000F00; f[3] = 0x0000F000; f[4] = 0x000F0000; f[5] = 0x00F00000; f[6] = 0x0F000000; f[7] = 0xF0000000; u_int32_t r_for_s[8]; u_int32_t s_for_r[8]; for (int i = 0; i<8; i++){ r_for_s[i] = new_r&&f[i]; r_for_s[i] = r_for_s[i] >> 4*i; s_for_r[i] = s&&f[i]; s_for_r[i] = s_for_r[i] >> 4*i; } new_r = 0; for (int i = 0; i<8; i++){ new_r = new_r | (s_for_r[r_for_s[i]]<<4*i); } new_r = (new_r<<11) | (new_r >> 21); new_r = new_r && L; u_int64_t new_l = R; return (new_l<<32) | new_r; } u_int64_t gost_real (u_int64_t T, u_int32_t s, u_int32_t keys[8]) { u_int64_t new_T = T; for (int j = 0; j<3; j++) { for (int i = 0; i < 8; ++i) { new_T = tact(new_T, keys[i], s); } } for (int i = 7; i >=0; i--) { new_T = tact(new_T, keys[i], s); } return new_T; } // //CM1 CM3 - по модулю 2ˆ32 int main() { //заполняем ключи u_int32_t keys[8]; keys[0] = 3294967295; keys[1] = 3294967295; keys[2] = 3294967295; keys[3] = 3294967295; keys[4] = 3294967295; keys[5] = 3294967295; keys[6] = 3294967295; keys[7] = 3294967295; u_int32_t S = 3295967795; bool s[64]; for (int i = 0; i<64; i++){ s[i] = rand() %2; } u_int32_t n1, n2, n3, n4; n1 = 0; n2 = 0; for (int i = 0; i<32; i++){ n1 = n1|(s[i]<<i); n2 = n2|(s[i+32]<<i); } u_int64_t p; p = n1; p = (p<<32) | n2; p = gost_real(p, S, keys); n3 = (p & 0xFFFFFFFF00000000) >> 32; n4 = p & 0x00000000FFFFFFFF; u_int64_t mod = pow(2, 32); u_int64_t g[256]; u_int64_t c[256]; for (int i = 0; i<256; i++){ if (n4+n6>=mod){ n4 = n4+n6-mod+1; } else {n4 = n4+n6;} n3 = (n3+n5)%mod; n1 = n3; n2 = n4; g[i] = n1; g[i] = n2 | (g[i]<<32); g[i] = gost_real(g[i], S, keys); c[i] = plaintexts[i]&&g[i]; } return 0; }
the_stack_data/111077836.c
// // monotouch-fixes.c: // // Author: // Rolf Bjarne Kvinge // // Copyright 2011 Xamarin Inc. // #include <stdio.h> #include <dlfcn.h> #include <signal.h> #include <sys/mman.h> #include <string.h> #include <unistd.h> #include <stdint.h> #include <errno.h> // Apple uses LLVM to implement OpenGL ES on the iPhone Simulator, unfortunately // LLVM has a race condition in their signal handling - they set one-shot // signal handlers and restore the previous handler in those handlers. The // problem is that they set SA_RESETHAND|SA_NODEFER when setting their signal // handler, which means that if another signal arrives before their signal handler // has been able to restore our signal handler, the default signal handler will // be called (which just exits the process without any diagnostics at all). // // For the 32bit simulator we inject our own sigaction method, which takes precedence // over the system one, and reset the flags to 0 if flags is SA_RESETHAND|SA_NODEFER. // // Unfortunately this technique does not seem to work for the 64bit simulator, so there // we patch the system sigaction instead. // typedef int (*SigAction) (int sig, const struct sigaction *__restrict act, struct sigaction *__restrict oact); static SigAction system_sigaction = sigaction; static int my_sigaction (int sig, const struct sigaction *__restrict act, struct sigaction *__restrict oact) { //fprintf (stderr, "my_sigaction (%i, %p: handler = %p mask = %i flags = %i, %p)\n", sig, act, act ? act->sa_handler : NULL, act ? act->sa_mask : -1, act ? act->sa_flags : -1, oact); if (act && act->sa_flags == (SA_NODEFER | SA_RESETHAND)) { switch (sig) { case SIGUSR1: case SIGUSR2: case SIGFPE: // fprintf (stderr, "fixed up sicaction (%i, %p: handler = %p mask = %i flags = %i, %p)\n", sig, act, act ? act->sa_handler : NULL, act ? act->sa_mask : -1, act ? act->sa_flags : -1, oact); ((struct sigaction *) act)->sa_flags = 0; break; } } return system_sigaction (sig, act, oact); } #if defined(__i386__) typedef struct interpose_s { void *new_func; void *orig_func; } interpose_t; static const interpose_t interposers[] __attribute__ ((unused)) \ __attribute__ ((section("__DATA, __interpose"))) = { { (void *) &my_sigaction, (void *) &sigaction }, }; #elif defined(__x86_64__) static void patch_sigaction () { // Sanity check. uint64_t * func = (uint64_t *) &sigaction; uint64_t first = 0x20ec8348e5894855; // first 8 bytes of sigaction uint64_t second = 0x0a771ef883ff478d; // second 8 bytes of sigaction if (func [0] != first || func [1] != second) { fprintf (stderr, "MonoTouch: Could not install sigaction override, unexpected sigaction implementation.\n"); return; } // allocate executable memory uint64_t pagesize = getpagesize (); void *exec = mmap (NULL, pagesize, PROT_EXEC | PROT_WRITE | PROT_READ, MAP_ANON | MAP_PRIVATE, -1, 0); if (exec == NULL) { fprintf (stderr, "MonoTouch: Could not allocate memory for sigaction override: %s\n", strerror (errno)); return; } // create a trampoline that jumps to the real sigaction (to just after where we modified it). uint64_t *i64 = (uint64_t *) exec; i64 [0] = first; i64 [1] = second; uint16_t *i16 = (uint16_t *) exec; // movabsq &sigaction + 14,%r11 i16 [7] = 0xbb49; i64 [2] = (uint64_t) (14 + (char *) &sigaction); // jmpq *%r11 i16 [12] = 0xff41; i16 [13] = 0x00e3; // make sigaction patchable. uint64_t symbol = (uint64_t) (char *) &sigaction; void *aligned_symbol = (void *) (symbol & ~(pagesize - 1)); int ret; ret = mprotect (aligned_symbol, pagesize * 2, PROT_READ | PROT_WRITE | PROT_EXEC); if (ret != 0) { fprintf (stderr, "MonoTouch: could not patch sigaction: %s\n", strerror (errno)); munmap (exec, pagesize); return; } // patch sigaction to call my_sigaction instead. uint16_t *f16 = (uint16_t *) &sigaction; // movabsq my_sigaction,%r11 f16 [0] = 0xbb49; uint64_t *f64 = (uint64_t *) (f16 + 1); f64 [0] = (uint64_t) &my_sigaction; // jmpq *%r11 f16 [5] = 0xff41; f16 [6] = 0x00e3; // Make sigaction non-writeable again. mprotect (aligned_symbol, pagesize * 2, PROT_READ | PROT_EXEC); system_sigaction = (SigAction) exec; } #endif
the_stack_data/95449482.c
// // main.c // AlgorithmExercisesDemo // // Created by SK_Wang on 2020/4/9. // Copyright © 2020 SK_Wang. All rights reserved. // #include <stdio.h> #include "string.h" #include "ctype.h" #include "stdlib.h" #include "math.h" #include "time.h" #define ERROR 0 #define TRUE 1 #define FALSE 0 #define OK 1 typedef int Status; typedef int ElemType; typedef struct Node{ ElemType data; struct Node *next; }Node; typedef struct Node * LinkList; Status InitList(LinkList *L){ *L = (LinkList)malloc(sizeof(Node)); if(*L == NULL) return ERROR; (*L)->next = NULL; return OK; } Status ListInsert(LinkList *L, int i, ElemType e){ int j; LinkList p, s; p = *L; j = 1; while (p && j < i) { p = p->next; ++j; } if(!p || j > i) return ERROR; s = (LinkList)malloc(sizeof(Node)); s->data = e; s->next = p->next; p->next = s; return OK; } Status ListTraverse(LinkList L) { LinkList p = L->next; while(p) { printf("%d ", p->data); p = p->next; } printf("\n"); return OK; } /* 题目1: 将2个递增的有序链表合并为一个有序链表; 要求结果链表仍然使用两个链表的存储空间,不另外占用其他的存储空间. 表中不允许有重复的数据; */ void mergeTwoLists(LinkList *La, LinkList *Lb, LinkList *Lc) { LinkList pa, pb, pc, temp; pa = (*La)->next; pb = (*Lb)->next; *Lc = pc = *La; while (pa && pb) { if (pa->data < pb->data) { pc->next = pa; pc = pa; pa = pa->next; } else if (pa->data > pb->data) { pc->next = pb; pc = pb; pb = pb->next; } else { pc->next = pa; pc = pa; pa = pa->next; temp = pb->next; free(pb); pb = temp; } } pc->next = pa == NULL ? pb : pa; free(*Lb); } /* 题目2: 已知两个链表A和B分别表示两个集合.其元素递增排列. 设计一个算法,用于求出A与B的交集,并存储在A链表中; */ void Intersection(LinkList *La, LinkList *Lb, LinkList *Lc) { LinkList pa, pb, pc, temp; pa = (*La)->next; pb = (*Lb)->next; *Lc = pc = *La; while (pa && pb) { if (pa->data < pb->data) { temp = pa->next; free(pa); pa = temp; } else if (pa->data > pb->data) { temp = pb->next; free(pb); pb = temp; } else { pc->next = pa; pc = pa; pa = pa->next; temp = pb; pb = pb->next; free(temp); } } LinkList pd = pa ? pa: pb; while (pd) { temp = pd; pd = pd->next; free(temp); } pc->next = NULL; free(*Lb); } /* 题目3: 设计一个算法,将链表中所有节点的链接方向"原地旋转",即要求仅仅利用原表的存储空间. 换句话说,要求算法空间复杂度为O(1); 例如:L={0,2,4,6,8,10}, 逆转后: L = {10,8,6,4,2,0}; */ void Inverse(LinkList *L) { LinkList p, temp; p = (*L)->next; (*L)->next = NULL; while (p) { temp = p->next; p->next = (*L)->next; (*L)->next = p; p = temp; } } /* 题目4: 设计一个算法,删除递增有序链表中值大于等于mink且小于等于maxk(mink,maxk是给定的两个参数,其值可以和表中的元素相同,也可以不同)的所有元素; */ void DeleteMinMax(LinkList *L, int mink, int maxk) { LinkList p, q, pre, temp; pre = *L; p = (*L)->next; while (p && p->data < mink) { pre = p; p = p->next; } while (p && p->data <= maxk) { p = p->next; } q = pre->next; pre->next = p; while (q != p) { temp = q->next; free(q); q = temp; } } /* 题目5: 设将n(n>1)个整数存放到一维数组R中, 试设计一个在时间和空间两方面都尽可能高效的算法;将R中保存的序列循环左移p个位置(0<p<n)个位置, 即将R中的数据由(x0,x1,......,xn-1)变换为(xp,xp+1,...,xn-1,x0,x1,...,xp-1). 例如: pre[10] = {0,1,2,3,4,5,6,7,8,9}, n = 10,p = 3; pre[10] = {3,4,5,6,7,8,9,0,1,2} */ void Reverse(int *pre, int left, int right) { int i = left; int j = right; int temp; while (i < j) { temp = pre[i]; pre[i] = pre[j]; pre[j] = temp; i++; j--; } } void RotateLeft(int *pre, int n, int p) { if (p > 0 && p < n) { Reverse(pre, 0, n - 1); Reverse(pre, 0, n -1 - p); Reverse(pre, n - p, n - 1); } } /* 题目6: 已知一个整数序列A = (a0,a1,a2,...an-1),其中(0<= ai <=n),(0<= i<=n). 若存在ap1= ap2 = ...= apm = x,且m>n/2(0<=pk<n,1<=k<=m),则称x 为 A的主元素. 例如,A = (0,5,5,3,5,7,5,5),则5是主元素; 若B = (0,5,5,3,5,1,5,7),则A 中没有主元素,假设A中的n个元素保存在一个一维数组中,请设计一个尽可能高效的算法,找出数组元素中的主元素,若存在主元素则输出该元素,否则输出-1. */ int MainElement(int *A, int n) { int x = A[0]; int count = 1; for (int i = 1; i < n; i++) { if (x == A[i]) { count++; } else { if (count > 0) { count--; } else { x = A[i]; count = 1; } } } if (count > 0) { count = 1; for (int i = 1; i < n; i++) { if (A[i] == x) { count++; } } } if (count > n / 2) { return x; } return -1; } /* 题目7: 用单链表保存m个整数, 结点的结构为(data,link),且|data|<=n(n为正整数). 现在要去设计一个时间复杂度尽可能高效的算法. 对于链表中的data 绝对值相等的结点, 仅保留第一次出现的结点,而删除其余绝对值相等的结点. 例如,链表A = {21,-15,15,-7,15}, 删除后的链表A={21,-15,-7}; */ void DeleteEqualNode(LinkList *L, int n) { int *p = malloc(sizeof(int) * n); for (int i = 0; i < n; i++) { p[i] = 0; } LinkList q = *L; LinkList r = (*L)->next; while (r) { if (p[abs(r->data)] == 1) { q->next = r->next; free(r); r = q->next; } else { p[abs(r->data)] = 1; q = r; r = r->next; } } } int main(int argc, const char * argv[]) { // insert code here... printf("Hello, World!\n"); Status iStatus; LinkList La,Lb,Lc,L; InitList(&La); InitList(&Lb); /*---------题目1--------*/ for(int j = 10; j >= 0; j -= 2) { iStatus = ListInsert(&La, 1, j); } printf("La:\n"); ListTraverse(La); for(int j = 11; j > 0; j -= 2) { iStatus = ListInsert(&Lb, 1, j); } ListInsert(&Lb, 1, 0); printf("Lb:\n"); ListTraverse(Lb); mergeTwoLists(&La, &Lb, &Lc); printf("Lc:\n"); ListTraverse(Lc); /*---------题目2--------*/ ListInsert(&La, 1, 8); ListInsert(&La, 1, 6); ListInsert(&La, 1, 4); ListInsert(&La, 1, 2); printf("La:\n"); ListTraverse(La); ListInsert(&Lb, 1, 12); ListInsert(&Lb, 1, 10); ListInsert(&Lb, 1, 8); ListInsert(&Lb, 1, 6); ListInsert(&Lb, 1, 4); printf("Lb:\n"); ListTraverse(Lb); Intersection(&La, &Lb, &Lc); printf("Lc:\n"); ListTraverse(Lc); /*---------题目3--------*/ InitList(&L); for(int j = 10; j >= 0; j -= 2) { iStatus = ListInsert(&L, 1, j); } printf("L逆转前:\n"); ListTraverse(L); Inverse(&L); printf("L逆转后:\n"); ListTraverse(L); /*---------题目4--------*/ InitList(&L); for(int j = 10; j >= 0; j -= 2) { iStatus = ListInsert(&L, 1, j); } printf("L链表:\n"); ListTraverse(L); DeleteMinMax(&L, 4, 8); printf("删除链表mink与maxk之间结点的链表:\n"); ListTraverse(L); /*---------题目5--------*/ int pre[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; RotateLeft(pre, 10, 3); for (int i = 0; i < 10; i++) { printf("%d ",pre[i]); } printf("\n"); /*---------题目6--------*/ int A[] = {0, 5, 5, 3, 5, 7, 5, 5}; int value = MainElement(A, 8); printf("数组A 主元素为: %d\n", value); /*---------题目7--------*/ InitList(&L); ListInsert(&L, 1, 21); ListInsert(&L, 1, -15); ListInsert(&L, 1, 15); ListInsert(&L, 1, -7); ListInsert(&L, 1, 15); DeleteEqualNode(&L, 21); ListTraverse(L); return 0; }
the_stack_data/87979.c
#include<stdio.h> int main(){ printf("Star Hedha bech yetktib fel console"); // ama star hedha le, khatrou comment return 0; }
the_stack_data/76699134.c
#include <stdio.h> #include <stdbool.h> int main(){ int n,k, c = 0,v,s; bool ans[50] = {false}; scanf("%d %d",&n,&v); for(int i = 0; i < n; i++){ scanf("%d",&k); for(int j = 0; j < k; j++){ scanf("%d", &s); if(s < v) ans[i] = true; } if(ans[i] == true) c++; } if(c == 0) printf("0"); else{ int i = 0; printf("%d\n",c); while(c){ if(ans[i++]){ c--; printf("%d ",i); } } } return 0; }
the_stack_data/32949179.c
/* prog4.c: this program * Author: Charles E. Campbell, Jr. * Date: Dec 20, 2008 */ /* ===================================================================== * Header Section: {{{1 */ /* --------------------------------------------------------------------- * Includes: {{{2 */ #include <stdio.h> /* ------------------------------------------------------------------------ * Definitions: {{{2 */ /* ------------------------------------------------------------------------ * Typedefs: {{{2 */ /* ------------------------------------------------------------------------ * Local Data Structures: {{{2 */ /* ------------------------------------------------------------------------ * Global Data: {{{2 */ /* ------------------------------------------------------------------------ * Explanation: {{{2 */ /* ------------------------------------------------------------------------ * Prototypes: {{{2 */ /* ======================================================================== * Functions: {{{1 */ /* --------------------------------------------------------------------- */ /* main: {{{2 */ int main( int argc, char **argv) { printf("What happens to this string?\n"); return 0; } /* ===================================================================== */ /* Modelines: {{{1 * vim: fdm=marker */
the_stack_data/82950645.c
#define CONST_seed 45 #include <stdlib.h> /* initialize the random number generator for a particular processor */ void init_random(int myid) { srand48(myid*CONST_seed); } /* return a random number from 0 to range-1 */ int gen_number(int range) { return lrand48() % range; } /* return a random number in [-range+1,range-1] */ int gen_signed_number(int range) { int temp; temp = lrand48() % (2*range-1); /* 0..2*range-2 */ return temp-(range-1); } /* Generate a double from 0.0 to 1.0 */ double gen_uniform_double() { return drand48(); } int check_percent(int percent) { return (drand48() < (double) (percent/100.0)); }
the_stack_data/121702.c
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- * * libtest.c --- auxiliary C lib for testing purposes * * Copyright (C) 2005-2007, Luis Oliveira <loliveira(@)common-lisp.net> * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifdef WIN32 #define DLLEXPORT __declspec(dllexport) #else #define DLLEXPORT #endif #include <stdio.h> #include <limits.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <float.h> #include <stdbool.h> /* MSVC doesn't have stdint.h and uses a different syntax for stdcall */ #ifndef _MSC_VER #include <stdint.h> #endif #ifdef WIN32 #ifdef _MSC_VER #define STDCALL __stdcall #else #define STDCALL __attribute__((stdcall)) #endif #else #define STDCALL #endif /* * Some functions that aren't available on WIN32 */ DLLEXPORT float my_sqrtf(float n) { return (float) sqrt((double) n); } DLLEXPORT char *my_strdup(const char *str) { char *p = malloc(strlen(str) + 1); strcpy(p, str); return p; } DLLEXPORT void my_strfree(char *str) { free(str); } DLLEXPORT long long my_llabs(long long n) { return n < 0 ? -n : n; } DLLEXPORT unsigned long long ullong(unsigned long long n) { return n == ULLONG_MAX ? n : 42; } /* * Foreign Globals * * (var_int is used in MISC-TYPES.EXPAND.3 as well) */ DLLEXPORT char * dll_version = "20120107"; /* TODO: look into signed char vs. unsigned char issue */ DLLEXPORT char var_char = -127; DLLEXPORT unsigned char var_unsigned_char = 255; DLLEXPORT short var_short = -32767; DLLEXPORT unsigned short var_unsigned_short = 65535; DLLEXPORT int var_int = -32767; DLLEXPORT unsigned int var_unsigned_int = 65535; DLLEXPORT long var_long = -2147483647L; DLLEXPORT unsigned long var_unsigned_long = 4294967295UL; DLLEXPORT float var_float = 42.0f; DLLEXPORT double var_double = 42.0; DLLEXPORT void * var_pointer = NULL; DLLEXPORT char * var_string = "Hello, foreign world!"; DLLEXPORT long long var_long_long = -9223372036854775807LL; DLLEXPORT unsigned long long var_unsigned_long_long = 18446744073709551615ULL; DLLEXPORT float float_max = FLT_MAX; DLLEXPORT float float_min = FLT_MIN; DLLEXPORT double double_max = DBL_MAX; DLLEXPORT double double_min = DBL_MIN; /* * Callbacks */ DLLEXPORT int expect_char_sum(char (*f)(char, char)) { return f('a', 3) == 'd'; } DLLEXPORT int expect_unsigned_char_sum(unsigned char (*f)(unsigned char, unsigned char)) { return f(UCHAR_MAX-1, 1) == UCHAR_MAX; } DLLEXPORT int expect_short_sum(short (*f)(short a, short b)) { return f(SHRT_MIN+1, -1) == SHRT_MIN; } DLLEXPORT int expect_unsigned_short_sum(unsigned short (*f)(unsigned short, unsigned short)) { return f(USHRT_MAX-1, 1) == USHRT_MAX; } /* used in MISC-TYPES.EXPAND.4 as well */ DLLEXPORT int expect_int_sum(int (*f)(int, int)) { return f(INT_MIN+1, -1) == INT_MIN; } DLLEXPORT int expect_unsigned_int_sum(unsigned int (*f)(unsigned int, unsigned int)) { return f(UINT_MAX-1, 1) == UINT_MAX; } DLLEXPORT int expect_long_sum(long (*f)(long, long)) { return f(LONG_MIN+1, -1) == LONG_MIN; } DLLEXPORT int expect_unsigned_long_sum(unsigned long (*f)(unsigned long, unsigned long)) { return f(ULONG_MAX-1, 1) == ULONG_MAX; } DLLEXPORT int expect_long_long_sum(long long (*f)(long long, long long)) { return f(LLONG_MIN+1, -1) == LLONG_MIN; } DLLEXPORT int expect_unsigned_long_long_sum (unsigned long long (*f)(unsigned long long, unsigned long long)) { return f(ULLONG_MAX-1, 1) == ULLONG_MAX; } DLLEXPORT int expect_float_sum(float (*f)(float, float)) { /*printf("\n>>> FLOAT: %f <<<\n", f(20.0f, 22.0f));*/ return f(20.0f, 22.0f) == 42.0f; } DLLEXPORT int expect_double_sum(double (*f)(double, double)) { /*printf("\n>>> DOUBLE: %f<<<\n", f(-20.0, -22.0));*/ return f(-20.0, -22.0) == -42.0; } DLLEXPORT int expect_long_double_sum(long double (*f)(long double, long double)) { /*printf("\n>>> DOUBLE: %f<<<\n", f(-20.0, -22.0));*/ return f(-20.0, -22.0) == -42.0; } DLLEXPORT int expect_pointer_sum(void* (*f)(void*, int)) { return f(NULL, 0xDEAD) == (void *) 0xDEAD; } DLLEXPORT int expect_strcat(char* (*f)(char*, char*)) { char *ret = f("Hello, ", "C world!"); int res = strcmp(ret, "Hello, C world!") == 0; /* commented out as a quick fix on platforms that don't foreign allocate in C malloc space. */ /*free(ret);*/ /* is this allowed? */ return res; } DLLEXPORT void pass_int_ref(void (*f)(int*)) { int x = 1984; f(&x); } /* * Enums */ typedef enum { ONE = 1, TWO, THREE, FOUR, FORTY_ONE = 41, FORTY_TWO } numeros; DLLEXPORT int check_enums(numeros one, numeros two, numeros three, numeros four, numeros forty_one, numeros forty_two) { if (one == ONE && two == TWO && three == THREE && four == FOUR && forty_one == FORTY_ONE && forty_two == FORTY_TWO) return 1; return 0; } typedef enum { FALSE, TRUE } another_boolean; DLLEXPORT another_boolean return_enum(int x) { if (x == 0) return FALSE; else return TRUE; } /* * Booleans */ DLLEXPORT int equalequal(int a, unsigned int b) { return ((unsigned int) a) == b; } DLLEXPORT char bool_and(unsigned char a, char b) { return a && b; } DLLEXPORT unsigned long bool_xor(long a, unsigned long b) { return (a && !b) || (!a && b); } DLLEXPORT unsigned sizeof_bool(void) { return (unsigned) sizeof(_Bool); } DLLEXPORT unsigned bool_to_unsigned(_Bool b) { return (unsigned) b; } DLLEXPORT _Bool unsigned_to_bool(unsigned u) { return (_Bool) u; } /* * Test struct alignment issues. These comments assume the x86 gABI. * Hopefully these tests will spot alignment issues in others archs * too. */ /* * STRUCT.ALIGNMENT.1 */ struct s_ch { char a_char; }; /* This struct's size should be 2 bytes */ struct s_s_ch { char another_char; struct s_ch a_s_ch; }; DLLEXPORT struct s_s_ch the_s_s_ch = { 2, { 1 } }; /* * STRUCT.ALIGNMENT.2 */ /* This one should be alignment should be the same as short's alignment. */ struct s_short { char a_char; char another_char; short a_short; }; struct s_s_short { char yet_another_char; struct s_short a_s_short; /* so this should be 2-byte aligned */ }; /* size: 6 bytes */ DLLEXPORT struct s_s_short the_s_s_short = { 4, { 1, 2, 3 } }; /* * STRUCT.ALIGNMENT.3 */ /* This test will, among other things, check for the existence tail padding. */ struct s_double { char a_char; /* 1 byte */ /* padding: 3 bytes */ double a_double; /* 8 bytes */ char another_char; /* 1 byte */ /* padding: 3 bytes */ }; /* total size: 16 bytes */ struct s_s_double { char yet_another_char; /* 1 byte */ /* 3 bytes padding */ struct s_double a_s_double; /* 16 bytes */ short a_short; /* 2 byte */ /* 2 bytes padding */ }; /* total size: 24 bytes */ DLLEXPORT struct s_s_double the_s_s_double = { 4, { 1, 2.0, 3 }, 5 }; /* * STRUCT.ALIGNMENT.4 */ struct s_s_s_double { short another_short; /* 2 bytes */ /* 2 bytes padding */ struct s_s_double a_s_s_double; /* 24 bytes */ char last_char; /* 1 byte */ /* 3 bytes padding */ }; /* total size: 32 */ DLLEXPORT struct s_s_s_double the_s_s_s_double = { 6, { 4, { 1, 2.0, 3 }, 5 }, 7 }; /* * STRUCT.ALIGNMENT.5 */ /* MacOSX ABI says: "The embedding alignment of the first element in a data structure is equal to the element's natural alignment." and "For subsequent elements that have a natural alignment greater than 4 bytes, the embedding alignment is 4, unless the element is a vector." */ /* note: these rules will apply to the structure itself. So, unless it is the first element of another structure, its alignment will be 4. */ /* the following offsets and sizes are specific to darwin/ppc32 */ struct s_double2 { double a_double; /* 8 bytes (alignment 8) */ short a_short; /* 2 bytes */ /* 6 bytes padding */ }; /* total size: 16 */ struct s_s_double2 { char a_char; /* 1 byte */ /* 3 bytes padding */ struct s_double2 a_s_double2; /* 16 bytes, alignment 4 */ short another_short; /* 2 bytes */ /* 2 bytes padding */ }; /* total size: 24 bytes */ /* alignment: 4 */ DLLEXPORT struct s_s_double2 the_s_s_double2 = { 3, { 1.0, 2 }, 4 }; /* * STRUCT.ALIGNMENT.6 */ /* Same as STRUCT.ALIGNMENT.5 but with long long. */ struct s_long_long { long long a_long_long; /* 8 bytes (alignment 8) */ short a_short; /* 2 bytes */ /* 6 bytes padding */ }; /* total size: 16 */ struct s_s_long_long { char a_char; /* 1 byte */ /* 3 bytes padding */ struct s_long_long a_s_long_long; /* 16 bytes, alignment 4 */ short a_short; /* 2 bytes */ /* 2 bytes padding */ }; /* total size: 24 bytes */ /* alignment: 4 */ DLLEXPORT struct s_s_long_long the_s_s_long_long = { 3, { 1, 2 }, 4 }; /* * STRUCT.ALIGNMENT.7 */ /* Another test for Darwin's PPC32 ABI. */ struct s_s_double3 { struct s_double2 a_s_double2; /* 16 bytes, alignment 8*/ short another_short; /* 2 bytes */ /* 6 bytes padding */ }; /* total size: 24 */ struct s_s_s_double3 { struct s_s_double3 a_s_s_double3; /* 24 bytes */ char a_char; /* 1 byte */ /* 7 bytes padding */ }; /* total size: 32 */ DLLEXPORT struct s_s_s_double3 the_s_s_s_double3 = { { { 1.0, 2 }, 3 }, 4 }; /* * STRUCT.ALIGNMENT.8 */ /* Same as STRUCT.ALIGNMENT.[56] but with unsigned long long. */ struct s_unsigned_long_long { unsigned long long an_unsigned_long_long; /* 8 bytes (alignment 8) */ short a_short; /* 2 bytes */ /* 6 bytes padding */ }; /* total size: 16 */ struct s_s_unsigned_long_long { char a_char; /* 1 byte */ /* 3 bytes padding */ struct s_unsigned_long_long a_s_unsigned_long_long; /* 16 bytes, align 4 */ short a_short; /* 2 bytes */ /* 2 bytes padding */ }; /* total size: 24 bytes */ /* alignment: 4 */ DLLEXPORT struct s_s_unsigned_long_long the_s_s_unsigned_long_long = { 3, { 1, 2 }, 4 }; /* STRUCT.ALIGNMENT.x */ /* commented this test out because this is not standard C and MSVC++ (or some versions of it at least) won't compile it. */ /* struct empty_struct {}; struct with_empty_struct { struct empty_struct foo; int an_int; }; DLLEXPORT struct with_empty_struct the_with_empty_struct = { {}, 42 }; */ /* * STRUCT-VALUES.* */ struct pair { int a, b; }; DLLEXPORT int pair_sum(struct pair p) { return p.a + p.b; } DLLEXPORT int pair_pointer_sum(struct pair *p) { return p->a + p->b; } DLLEXPORT struct pair make_pair(int a, int b) { return (struct pair) { a, b }; } DLLEXPORT struct pair *alloc_pair(int a, int b) { struct pair *p = malloc(sizeof(struct pair)); p->a = a; p->b = b; return p; } struct pair_plus_one { struct pair p; int c; }; DLLEXPORT int pair_plus_one_sum(struct pair_plus_one p) { return p.p.a + p.p.b + p.c; } DLLEXPORT int pair_plus_one_pointer_sum(struct pair_plus_one *p) { return p->p.a + p->p.b + p->c; } DLLEXPORT struct pair_plus_one make_pair_plus_one(int a, int b, int c) { return (struct pair_plus_one) { { a, b }, c }; } DLLEXPORT struct pair_plus_one *alloc_pair_plus_one(int a, int b, int c) { struct pair_plus_one *p = malloc(sizeof(struct pair_plus_one)); p->p.a = a; p->p.b = b; p->c = c; return p; } /* * DEFCFUN.NOARGS and DEFCFUN.NOOP */ DLLEXPORT int noargs() { return 42; } DLLEXPORT void noop() { return; } /* * DEFCFUN.BFF.1 * * (let ((rettype (find-type :long)) * (arg-types (n-random-types-no-ll 127))) * (c-function rettype arg-types) * (gen-function-test rettype arg-types)) */ DLLEXPORT long sum_127_no_ll (long a1, unsigned long a2, short a3, unsigned short a4, float a5, double a6, unsigned long a7, float a8, unsigned char a9, unsigned short a10, short a11, unsigned long a12, double a13, long a14, unsigned int a15, void* a16, unsigned int a17, unsigned short a18, long a19, float a20, void* a21, float a22, int a23, int a24, unsigned short a25, long a26, long a27, double a28, unsigned char a29, unsigned int a30, unsigned int a31, int a32, unsigned short a33, unsigned int a34, void* a35, double a36, double a37, long a38, short a39, unsigned short a40, long a41, char a42, long a43, unsigned short a44, void* a45, int a46, unsigned int a47, double a48, unsigned char a49, unsigned char a50, float a51, int a52, unsigned short a53, double a54, short a55, unsigned char a56, unsigned long a57, float a58, float a59, float a60, void* a61, void* a62, unsigned int a63, unsigned long a64, char a65, short a66, unsigned short a67, unsigned long a68, void* a69, float a70, double a71, long a72, unsigned long a73, short a74, unsigned int a75, unsigned short a76, int a77, unsigned short a78, char a79, double a80, short a81, unsigned char a82, float a83, char a84, int a85, double a86, unsigned char a87, int a88, unsigned long a89, double a90, short a91, short a92, unsigned int a93, unsigned char a94, float a95, long a96, float a97, long a98, long a99, int a100, int a101, unsigned int a102, char a103, char a104, unsigned short a105, unsigned int a106, unsigned short a107, unsigned short a108, int a109, long a110, char a111, double a112, unsigned int a113, char a114, short a115, unsigned long a116, unsigned int a117, short a118, unsigned char a119, float a120, void* a121, double a122, int a123, long a124, char a125, unsigned short a126, float a127) { return (long) a1 + a2 + a3 + a4 + ((long) a5) + ((long) a6) + a7 + ((long) a8) + a9 + a10 + a11 + a12 + ((long) a13) + a14 + a15 + ((intptr_t) a16) + a17 + a18 + a19 + ((long) a20) + ((intptr_t) a21) + ((long) a22) + a23 + a24 + a25 + a26 + a27 + ((long) a28) + a29 + a30 + a31 + a32 + a33 + a34 + ((intptr_t) a35) + ((long) a36) + ((long) a37) + a38 + a39 + a40 + a41 + a42 + a43 + a44 + ((intptr_t) a45) + a46 + a47 + ((long) a48) + a49 + a50 + ((long) a51) + a52 + a53 + ((long) a54) + a55 + a56 + a57 + ((long) a58) + ((long) a59) + ((long) a60) + ((intptr_t) a61) + ((intptr_t) a62) + a63 + a64 + a65 + a66 + a67 + a68 + ((intptr_t) a69) + ((long) a70) + ((long) a71) + a72 + a73 + a74 + a75 + a76 + a77 + a78 + a79 + ((long) a80) + a81 + a82 + ((long) a83) + a84 + a85 + ((long) a86) + a87 + a88 + a89 + ((long) a90) + a91 + a92 + a93 + a94 + ((long) a95) + a96 + ((long) a97) + a98 + a99 + a100 + a101 + a102 + a103 + a104 + a105 + a106 + a107 + a108 + a109 + a110 + a111 + ((long) a112) + a113 + a114 + a115 + a116 + a117 + a118 + a119 + ((long) a120) + ((intptr_t) a121) + ((long) a122) + a123 + a124 + a125 + a126 + ((long) a127); } /* * DEFCFUN.BFF.2 * * (let ((rettype (find-type :long-long)) * (arg-types (n-random-types 127))) * (c-function rettype arg-types) * (gen-function-test rettype arg-types)) */ DLLEXPORT long long sum_127 (void* a1, void* a2, float a3, unsigned long a4, void* a5, long long a6, double a7, double a8, unsigned short a9, int a10, long long a11, long a12, short a13, unsigned int a14, long a15, unsigned char a16, int a17, double a18, short a19, short a20, long long a21, unsigned int a22, unsigned short a23, short a24, void* a25, short a26, unsigned short a27, unsigned short a28, int a29, long long a30, void* a31, int a32, unsigned long a33, unsigned long a34, void* a35, unsigned long long a36, float a37, int a38, short a39, void* a40, unsigned long long a41, long long a42, unsigned long a43, unsigned long a44, unsigned long long a45, unsigned long a46, char a47, double a48, long a49, unsigned int a50, int a51, short a52, void* a53, long a54, unsigned long long a55, int a56, unsigned short a57, unsigned long long a58, float a59, void* a60, float a61, unsigned short a62, unsigned long a63, float a64, unsigned int a65, unsigned long long a66, void* a67, double a68, unsigned long long a69, double a70, double a71, long long a72, void* a73, unsigned short a74, long a75, void* a76, short a77, double a78, long a79, unsigned char a80, void* a81, unsigned char a82, long a83, double a84, void* a85, int a86, double a87, unsigned char a88, double a89, short a90, long a91, int a92, long a93, double a94, unsigned short a95, unsigned int a96, int a97, char a98, long long a99, double a100, float a101, unsigned long a102, short a103, void* a104, float a105, long long a106, int a107, long long a108, long long a109, double a110, unsigned long long a111, double a112, unsigned long a113, char a114, char a115, unsigned long a116, short a117, unsigned char a118, unsigned char a119, int a120, int a121, float a122, unsigned char a123, unsigned char a124, double a125, unsigned long long a126, char a127) { return (long long) ((intptr_t) a1) + ((intptr_t) a2) + ((long) a3) + a4 + ((intptr_t) a5) + a6 + ((long) a7) + ((long) a8) + a9 + a10 + a11 + a12 + a13 + a14 + a15 + a16 + a17 + ((long) a18) + a19 + a20 + a21 + a22 + a23 + a24 + ((intptr_t) a25) + a26 + a27 + a28 + a29 + a30 + ((intptr_t) a31) + a32 + a33 + a34 + ((intptr_t) a35) + a36 + ((long) a37) + a38 + a39 + ((intptr_t) a40) + a41 + a42 + a43 + a44 + a45 + a46 + a47 + ((long) a48) + a49 + a50 + a51 + a52 + ((intptr_t) a53) + a54 + a55 + a56 + a57 + a58 + ((long) a59) + ((intptr_t) a60) + ((long) a61) + a62 + a63 + ((long) a64) + a65 + a66 + ((intptr_t) a67) + ((long) a68) + a69 + ((long) a70) + ((long) a71) + a72 + ((intptr_t) a73) + a74 + a75 + ((intptr_t) a76) + a77 + ((long) a78) + a79 + a80 + ((intptr_t) a81) + a82 + a83 + ((long) a84) + ((intptr_t) a85) + a86 + ((long) a87) + a88 + ((long) a89) + a90 + a91 + a92 + a93 + ((long) a94) + a95 + a96 + a97 + a98 + a99 + ((long) a100) + ((long) a101) + a102 + a103 + ((intptr_t) a104) + ((long) a105) + a106 + a107 + a108 + a109 + ((long) a110) + a111 + ((long) a112) + a113 + a114 + a115 + a116 + a117 + a118 + a119 + a120 + a121 + ((long) a122) + a123 + a124 + ((long) a125) + a126 + a127; } /* * CALLBACKS.BFF.1 (cb-test :no-long-long t) */ DLLEXPORT long call_sum_127_no_ll (long (*func) (unsigned long, void*, long, double, unsigned long, float, float, int, unsigned int, double, double, double, void*, unsigned short, unsigned short, void*, long, long, int, short, unsigned short, unsigned short, char, long, void*, void*, char, unsigned char, unsigned long, short, int, int, unsigned char, short, long, long, void*, unsigned short, char, double, unsigned short, void*, short, unsigned long, unsigned short, float, unsigned char, short, float, short, char, unsigned long, unsigned long, char, float, long, void*, short, float, unsigned int, float, unsigned int, double, unsigned int, unsigned char, int, long, char, short, double, int, void*, char, unsigned short, void*, unsigned short, void*, unsigned long, double, void*, long, float, unsigned short, unsigned short, void*, float, int, unsigned int, double, float, long, void*, unsigned short, float, unsigned char, unsigned char, float, unsigned int, float, unsigned short, double, unsigned short, unsigned long, unsigned int, unsigned long, void*, unsigned char, char, char, unsigned short, unsigned long, float, short, void*, long, unsigned short, short, double, short, int, char, unsigned long, long, int, void*, double, unsigned char)) { return func(948223085, (void *) 803308438, -465723152, 20385, 219679466, -10035, 13915, -1193455756, 1265303699, 27935, -18478, -10508, (void *) 215389089, 55561, 55472, (void *) 146070433, -1040819989, -17851453, -1622662247, -19473, 20837, 30216, 79, 986800400, (void *) 390281604, (void *) 1178532858, 19, 117, 78337699, -5718, -991300738, 872160910, 184, 926, -1487245383, 1633973783, (void *) 33738609, 53985, -116, 31645, 27196, (void *) 145569903, -6960, 17252220, 47404, -10491, 88, -30438, -21212, -1982, -16, 1175270, 7949380, -121, 8559, -432968526, (void *) 293455312, 11894, -8394, 142421516, -25758, 3422998, 4004, 15758212, 198, -1071899743, -1284904617, -11, -17219, -30039, 311589092, (void *) 541468577, 123, 63517, (void *) 1252504506, 39368, (void *) 10057868, 134781408, -7143, (void *) 72825877, -1190798667, -30862, 63757, 14965, (void *) 802391252, 22008, -517289619, 806091099, 1125, 451, -498145176, (void *) 55960931, 15379, 4629, 184, 254, 22532, 465856451, -1669, 49416, -16546, 2983, 4337541, 65292495, 39253529, (void *) 669025, 211, 85, -19, 24298, 65358, 16776, -29957, (void *) 124311, -163231228, 2610, -7806, 26434, -21913, -753615541, 120, 358697932, -1198889034, -2131350926, (void *) 3749492036, -13413, 17); } /* * CALLBACKS.BFF.2 (cb-test) */ DLLEXPORT long long call_sum_127 (long long (*func) (short, char, void*, float, long, double, unsigned long long, unsigned short, unsigned char, char, char, unsigned short, unsigned long long, unsigned short, long long, unsigned short, unsigned long long, unsigned char, unsigned char, unsigned long long, long long, char, float, unsigned int, float, float, unsigned int, float, char, unsigned char, long, long long, unsigned char, double, long, double, unsigned int, unsigned short, long long, unsigned int, int, unsigned long long, long, short, unsigned int, unsigned int, unsigned long long, unsigned int, long, void*, unsigned char, char, long long, unsigned short, unsigned int, float, unsigned char, unsigned long, long long, float, long, float, int, float, unsigned short, unsigned long long, short, unsigned long, long, char, unsigned short, long long, short, double, void*, unsigned int, char, unsigned int, void*, void*, unsigned char, void*, unsigned short, unsigned char, long, void*, char, long, unsigned short, unsigned char, double, unsigned long long, unsigned short, unsigned short, unsigned int, long, char, long, char, short, unsigned short, unsigned long, unsigned long, short, long long, long long, long long, double, unsigned short, unsigned char, short, unsigned char, long, long long, unsigned long long, unsigned int, unsigned long, unsigned char, long long, unsigned char, unsigned long long, double, unsigned char, long long, unsigned char, char, long long)) { return func(-8573, 14, (void *) 832601021, -32334, -1532040888, -18478, 2793023182591311826, 2740, 230, 103, 97, 13121, 5112369026351511084, 7763, -8134147951003417418, 34348, 5776613699556468853, 19, 122, 1431603726926527625, 439503521880490337, -112, -21557, 1578969190, -22008, -4953, 2127745975, -7262, -6, 180, 226352974, -3928775366167459219, 134, -17730, -1175042526, 23868, 3494181009, 57364, 3134876875147518682, 104531655, -1286882727, 803577887579693487, 1349268803, 24912, 3313099419, 3907347884, 1738833249233805034, 2794230885, 1008818752, (void *) 1820044575, 189, 61, -931654560961745071, 57531, 3096859985, 10405, 220, 3631311224, -8531370353478907668, 31258, 678896693, -32150, -1869057813, -19877, 62841, 4161660185772906873, -23869, 4016251006, 610353435, 105, 47315, -1051054492535331660, 6846, -15163, (void *) 736672359, 2123928476, -122, 3859258652, (void *) 3923394833, (void *) 1265031970, 161, (void *) 1993867800, 55056, 122, 1562112760, (void *) 866615125, -79, -1261399547, 31737, 254, -31279, 5462649659172897980, 5202, 7644, 174224940, -337854382, -45, -583502442, -37, -13266, 24520, 2198606699, 2890453969, -8282, -2295716637858246075, -1905178488651598878, -6384652209316714643, 14841, 35443, 132, 15524, 187, 2138878229, -5153032566879951000, 9056545530140684207, 4124632010, 276167701, 56, -2307310370663738730, 66, 9113015627153789746, -9618, 167, 755753399701306200, 119, -28, -990561962725435433); } /* * CALLBACKS.DOUBLE26 */ DLLEXPORT double call_double26 (double (*f)(double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double)) { return f(3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14); } /* * DEFCFUN.DOUBLE26 and FUNCALL.DOUBLE26 */ DLLEXPORT double sum_double26(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15, double a16, double a17, double a18, double a19, double a20, double a21, double a22, double a23, double a24, double a25, double a26) { return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15 + a16 + a17 + a18 + a19 + a20 + a21 + a22 + a23 + a24 + a25 + a26; } /* * CALLBACKS.FLOAT26 */ DLLEXPORT float call_float26 (float (*f)(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)) { return f(5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0); } /* * DEFCFUN.FLOAT26 and FUNCALL.FLOAT26 */ DLLEXPORT float sum_float26(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16, float a17, float a18, float a19, float a20, float a21, float a22, float a23, float a24, float a25, float a26) { return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15 + a16 + a17 + a18 + a19 + a20 + a21 + a22 + a23 + a24 + a25 + a26; } /* * Symbol case. */ DLLEXPORT int UPPERCASEINT1 = 12345; DLLEXPORT int UPPER_CASE_INT1 = 23456; DLLEXPORT int MiXeDCaSeInT1 = 34567; DLLEXPORT int MiXeD_CaSe_InT1 = 45678; DLLEXPORT int UPPERCASEINT2 = 12345; DLLEXPORT int UPPER_CASE_INT2 = 23456; DLLEXPORT int MiXeDCaSeInT2 = 34567; DLLEXPORT int MiXeD_CaSe_InT2 = 45678; DLLEXPORT int UPPERCASEINT3 = 12345; DLLEXPORT int UPPER_CASE_INT3 = 23456; DLLEXPORT int MiXeDCaSeInT3 = 34567; DLLEXPORT int MiXeD_CaSe_InT3 = 45678; /* * FOREIGN-SYMBOL-POINTER.1 */ DLLEXPORT int compare_against_abs(intptr_t p) { return p == (intptr_t) abs; } /* * FOREIGN-SYMBOL-POINTER.2 */ DLLEXPORT void xpto_fun() {} DLLEXPORT int compare_against_xpto_fun(intptr_t p) { return p == (intptr_t) xpto_fun; } /* * [DEFCFUN|FUNCALL].NAMESPACE.1 */ DLLEXPORT int ns_function() { return 1; } /* * FOREIGN-GLOBALS.NAMESPACE.* */ DLLEXPORT int ns_var = 1; /* * DEFCFUN.STDCALL.1 */ DLLEXPORT int STDCALL stdcall_fun(int a, int b, int c) { return a + b + c; } /* * CALLBACKS.STDCALL.1 */ DLLEXPORT int call_stdcall_fun(int (STDCALL *f)(int, int, int)) { int a = 42; f(1, 2, 3); return a; } /* Unlike the one above, this commented test below actually * works. But, alas, it doesn't compile with -std=c99. */ /* DLLEXPORT int call_stdcall_fun(int __attribute__((stdcall)) (*f)(int, int, int)) { asm("pushl $42"); register int ebx asm("%ebx"); f(1, 2, 3); asm("popl %ebx"); return ebx; } */ /* vim: ts=4 et */
the_stack_data/106044.c
#include <stdio.h> int FooBar() { int class; int private = 10; for ( class = 0; class < private; class ++ ) { printf("Count: %d/%d\n", class, private); } return 0; }
the_stack_data/31388049.c
// 75. Sort Colors // https://leetcode.com/problems/sort-colors/ #include "stdio.h" void sortColors(int* nums, int numsSize) { int counts[3] = {0, 0, 0}; for (int i = 0; i != numsSize; ++i) counts[nums[i]]++; for (int i = 0; i != counts[0]; ++i) nums[i] = 0; for (int i = 0; i != counts[1]; ++i) nums[counts[0] + i] = 1; for (int i = 0; i != counts[2]; ++i) nums[counts[0] + counts[1] + i] = 2; } void printVec(int* v, int n) { for (int i = 0; i != n; ++i) printf("%d ", v[i]); printf("\n"); } int main() { int v1[] = {2,0,2,1,1,0}; printVec(v1, 6); sortColors(v1, 6); printVec(v1, 6); int v2[] = {0,2,0,2,2,0,2,2,2,0,0,0,2,2,2,2,0,2,2,0}; printVec(v2, 10); sortColors(v2, 10); printVec(v2, 10); }
the_stack_data/14199134.c
//Test C file #include <stdio.h> int main() { printf("This is just a test"); return 0; }
the_stack_data/540568.c
/* * CRT_noglob.c * This file has no copyright is assigned and is placed in the Public Domain. * This file is part of the mingw-w64 runtime package. * No warranty is given; refer to the file DISCLAIMER.PD within the package. * * Include this object file to set _dowildcard to a state that will turn off * command line globbing by default. (wildcard.o which goes into libmingw32.a * has a default state of off if not configured with --enable-wildcard.) * * To use this object include the object file in your link command: * gcc -o foo.exe foo.o CRT_noglob.o * */ int _dowildcard = 0;
the_stack_data/1070068.c
#include <stdlib.h> #include <string.h> #include <limits.h> #include <stdio.h> #include <inttypes.h> static uintmax_t get_width(void) { static uintmax_t width = 0; static int done = 0; static uintmax_t n = UINTMAX_MAX; if (done) { return width; } while (n > 0) { ++width; n >>= 1; } done = 1; return width; } static size_t count_bits(uintmax_t v) { size_t n = 0; for (n = 0; v; ++n) { v &= v - 1; } return n; } size_t lcs_len(const char *a, const char *b) { size_t a_len = strlen(a); size_t b_len = strlen(b); size_t a_lower = 0; size_t a_upper = a_len; size_t b_lower = 0; size_t b_upper = b_len; const uintmax_t width = get_width(); uintmax_t positions[UCHAR_MAX + 1] = {0}; uintmax_t i = 0; uintmax_t v = ULLONG_MAX; uintmax_t p = 0; uintmax_t u = 0; if (a_len == 0 || b_len == 0) { return 0; } --a_upper; --b_upper; /* find the lower bound of difference */ while (a_lower <= a_upper && b_lower <= b_upper && a[a_lower] == b[b_lower]) { ++a_lower; ++b_lower; } /* find the upper bound of difference */ while (a_lower <= a_upper && b_lower <= b_upper && a[a_upper] == b[b_upper]) { --a_upper; --b_upper; } /* not supported yet */ if (a_upper >= width) { return 0; } for (i = a_lower; i <= a_upper; ++i) { positions[(unsigned char)a[i]] |= 1 << (i % width); } for (i = b_lower; i <= b_upper; ++i) { p = positions[(unsigned char)b[i]]; u = v & p; v = (v + u) | (v - u); } return a_lower + count_bits(~v) + a_len - 1 - a_upper; } struct test_case { char *a; char *b; size_t expected_value; }; int main(void) { int ret_val = EXIT_SUCCESS; struct test_case test_cases[] = { { "abcdef", "abcdef", 6 }, { "aaaaa", "bbbbb", 0 }, { "xabczdefy", "def", 3 } }; size_t num_of_cases = sizeof test_cases / sizeof *test_cases; size_t success_count = 0; size_t failure_count = 0; size_t i = 0; for (; i < num_of_cases; ++i) { struct test_case *t = test_cases + i; size_t actual_value = lcs_len(t->a, t->b); if (t->expected_value == actual_value) { ++success_count; } else { ++failure_count; fprintf(stderr, "Not OK. Case %zu: Expected: %zu, Actual: %zu\n", i, t->expected_value, actual_value); } } printf("%zu/%zu OK\n", success_count, num_of_cases); if (failure_count > 0) { printf("%zu/%zu OK\n", failure_count, num_of_cases); ret_val = EXIT_FAILURE; } return ret_val; }
the_stack_data/150139300.c
#include <stdarg.h> #include <stddef.h> #include <stdint.h> #define arrayCount(Arr) (sizeof(Arr) / sizeof(*(Arr))) #define staticAssert(Expr, ...) typedef char STATIC_ASSERTION__[(Expr)?1:-1] #if !NDEBUG #define assert(Expr) if(!(Expr)) { abort(); } #else #define assert(Expr) (void)(0) #endif #define invalidCodePath() assert(!"Invalid code path") #define invalidCase(Case) case Case: { assert(!"Invalid case"); } break #define invalidDefaultCase() default: { assert(!"Invalid default case"); } break typedef int8_t s8; typedef uint8_t u8; typedef int16_t s16; typedef uint16_t u16; typedef int32_t s32; typedef uint32_t u32; typedef int64_t s64; typedef uint64_t u64; typedef float r32; typedef double r64; typedef s8 b8; typedef s16 b16; typedef s32 b32; typedef s64 b64; typedef size_t midx; typedef intptr_t sptr; typedef uintptr_t uptr; int stringLength(char *String) { int Length = 0; for(; *String; ++String, ++Length) {} return Length; } typedef struct { char *At; midx RemainingSize; } format_destination; midx formatStringList(char *Buff, midx BuffSize, char *Format, va_list Args) { char *At = Buff; char *BuffEnd = Buff + BuffSize; while(At < BuffEnd) { char Char = *Format++; if(Char == 0) { goto End; } else if(Char == '%') { Char = *Format++; switch(Char) { case 0: { goto End; } break; case '%': { *At++ = '%'; } break; case 'd': { int Number = va_arg(Args, int); char TempBuffer[64]; char *Temp = TempBuffer; do { int Digit = Number % 10; *Temp++ = '0' + Digit; Number /= 10; } while(Number); int DigitsRemaining = Temp - TempBuffer; while(DigitsRemaining && At < BuffEnd) { *At++ = TempBuffer[--DigitsRemaining]; } } break; default: { *At++ = '?'; } break; } } else { *At++ = Char; } } End:; if(At < BuffEnd) { At[0] = 0; } else { *--At = 0; } midx WrittenSize = At - Buff; return WrittenSize; } // NOTE(nox): The return value does not include the null terminator midx formatString(char *Buff, midx BuffSize, char *Format, ...) { va_list Args; va_start(Args, Format); midx WrittenSize = formatStringList(Buff, BuffSize, Format, Args); va_end(Args); return WrittenSize; }
the_stack_data/682690.c
#include <stdio.h> int main() { printf("%3s = %6s\n", "Fahrenheit", "Celsius"); for (float fahrenheit = -50; fahrenheit <= 250; fahrenheit += 10) { float celsius = (5.0/9.0) * (fahrenheit - 32); printf("%3.0f°F = %6.2f°C\n", fahrenheit, celsius); } printf("%3s = %6s\n", "Celsius", "Fahrenheit"); for (float celsius = -50; celsius <= 250; celsius += 10) { float fahrenheit = (celsius*9.0/5.0) + 32; printf("%3.0f°C = %6.2f°F\n", celsius, fahrenheit); } }
the_stack_data/117327576.c
// INFO: task hung in ld_usb_write // https://syzkaller.appspot.com/bug?id=1fa8a7aa1b766d53fee0c3897bcab252d8fcae72 // status:fixed // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <endian.h> #include <errno.h> #include <fcntl.h> #include <stdarg.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mount.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/types.h> #include <unistd.h> #include <linux/usb/ch9.h> unsigned long long procid; static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } #define USB_DEBUG 0 #define USB_MAX_IFACE_NUM 4 #define USB_MAX_EP_NUM 32 struct usb_iface_index { struct usb_interface_descriptor* iface; struct usb_endpoint_descriptor* eps[USB_MAX_EP_NUM]; unsigned eps_num; }; struct usb_device_index { struct usb_device_descriptor* dev; struct usb_config_descriptor* config; unsigned config_length; struct usb_iface_index ifaces[USB_MAX_IFACE_NUM]; unsigned ifaces_num; }; static bool parse_usb_descriptor(char* buffer, size_t length, struct usb_device_index* index) { if (length < sizeof(*index->dev) + sizeof(*index->config)) return false; memset(index, 0, sizeof(*index)); index->dev = (struct usb_device_descriptor*)buffer; index->config = (struct usb_config_descriptor*)(buffer + sizeof(*index->dev)); index->config_length = length - sizeof(*index->dev); size_t offset = 0; while (true) { if (offset + 1 >= length) break; uint8_t desc_length = buffer[offset]; uint8_t desc_type = buffer[offset + 1]; if (desc_length <= 2) break; if (offset + desc_length > length) break; if (desc_type == USB_DT_INTERFACE && index->ifaces_num < USB_MAX_IFACE_NUM) { struct usb_interface_descriptor* iface = (struct usb_interface_descriptor*)(buffer + offset); index->ifaces[index->ifaces_num++].iface = iface; } if (desc_type == USB_DT_ENDPOINT && index->ifaces_num > 0) { struct usb_iface_index* iface = &index->ifaces[index->ifaces_num - 1]; if (iface->eps_num < USB_MAX_EP_NUM) iface->eps[iface->eps_num++] = (struct usb_endpoint_descriptor*)(buffer + offset); } offset += desc_length; } return true; } enum usb_fuzzer_event_type { USB_FUZZER_EVENT_INVALID, USB_FUZZER_EVENT_CONNECT, USB_FUZZER_EVENT_DISCONNECT, USB_FUZZER_EVENT_SUSPEND, USB_FUZZER_EVENT_RESUME, USB_FUZZER_EVENT_CONTROL, }; struct usb_fuzzer_event { uint32_t type; uint32_t length; char data[0]; }; struct usb_fuzzer_init { uint64_t speed; const char* driver_name; const char* device_name; }; struct usb_fuzzer_ep_io { uint16_t ep; uint16_t flags; uint32_t length; char data[0]; }; #define USB_FUZZER_IOCTL_INIT _IOW('U', 0, struct usb_fuzzer_init) #define USB_FUZZER_IOCTL_RUN _IO('U', 1) #define USB_FUZZER_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_fuzzer_event) #define USB_FUZZER_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_fuzzer_ep_io) #define USB_FUZZER_IOCTL_EP0_READ _IOWR('U', 4, struct usb_fuzzer_ep_io) #define USB_FUZZER_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor) #define USB_FUZZER_IOCTL_EP_WRITE _IOW('U', 7, struct usb_fuzzer_ep_io) #define USB_FUZZER_IOCTL_EP_READ _IOWR('U', 8, struct usb_fuzzer_ep_io) #define USB_FUZZER_IOCTL_CONFIGURE _IO('U', 9) #define USB_FUZZER_IOCTL_VBUS_DRAW _IOW('U', 10, uint32_t) int usb_fuzzer_open() { return open("/sys/kernel/debug/usb-fuzzer", O_RDWR); } int usb_fuzzer_init(int fd, uint32_t speed, const char* driver, const char* device) { struct usb_fuzzer_init arg; arg.speed = speed; arg.driver_name = driver; arg.device_name = device; return ioctl(fd, USB_FUZZER_IOCTL_INIT, &arg); } int usb_fuzzer_run(int fd) { return ioctl(fd, USB_FUZZER_IOCTL_RUN, 0); } int usb_fuzzer_event_fetch(int fd, struct usb_fuzzer_event* event) { return ioctl(fd, USB_FUZZER_IOCTL_EVENT_FETCH, event); } int usb_fuzzer_ep0_write(int fd, struct usb_fuzzer_ep_io* io) { return ioctl(fd, USB_FUZZER_IOCTL_EP0_WRITE, io); } int usb_fuzzer_ep0_read(int fd, struct usb_fuzzer_ep_io* io) { return ioctl(fd, USB_FUZZER_IOCTL_EP0_READ, io); } int usb_fuzzer_ep_write(int fd, struct usb_fuzzer_ep_io* io) { return ioctl(fd, USB_FUZZER_IOCTL_EP_WRITE, io); } int usb_fuzzer_ep_read(int fd, struct usb_fuzzer_ep_io* io) { return ioctl(fd, USB_FUZZER_IOCTL_EP_READ, io); } int usb_fuzzer_ep_enable(int fd, struct usb_endpoint_descriptor* desc) { return ioctl(fd, USB_FUZZER_IOCTL_EP_ENABLE, desc); } int usb_fuzzer_configure(int fd) { return ioctl(fd, USB_FUZZER_IOCTL_CONFIGURE, 0); } int usb_fuzzer_vbus_draw(int fd, uint32_t power) { return ioctl(fd, USB_FUZZER_IOCTL_VBUS_DRAW, power); } #define USB_MAX_PACKET_SIZE 1024 struct usb_fuzzer_control_event { struct usb_fuzzer_event inner; struct usb_ctrlrequest ctrl; char data[USB_MAX_PACKET_SIZE]; }; struct usb_fuzzer_ep_io_data { struct usb_fuzzer_ep_io inner; char data[USB_MAX_PACKET_SIZE]; }; struct vusb_connect_string_descriptor { uint32_t len; char* str; } __attribute__((packed)); struct vusb_connect_descriptors { uint32_t qual_len; char* qual; uint32_t bos_len; char* bos; uint32_t strs_len; struct vusb_connect_string_descriptor strs[0]; } __attribute__((packed)); static const char default_string[] = {8, USB_DT_STRING, 's', 0, 'y', 0, 'z', 0}; static const char default_lang_id[] = {4, USB_DT_STRING, 0x09, 0x04}; static bool lookup_connect_response(struct vusb_connect_descriptors* descs, struct usb_device_index* index, struct usb_ctrlrequest* ctrl, char** response_data, uint32_t* response_length) { uint8_t str_idx; switch (ctrl->bRequestType & USB_TYPE_MASK) { case USB_TYPE_STANDARD: switch (ctrl->bRequest) { case USB_REQ_GET_DESCRIPTOR: switch (ctrl->wValue >> 8) { case USB_DT_DEVICE: *response_data = (char*)index->dev; *response_length = sizeof(*index->dev); return true; case USB_DT_CONFIG: *response_data = (char*)index->config; *response_length = index->config_length; return true; case USB_DT_STRING: str_idx = (uint8_t)ctrl->wValue; if (descs && str_idx < descs->strs_len) { *response_data = descs->strs[str_idx].str; *response_length = descs->strs[str_idx].len; return true; } if (str_idx == 0) { *response_data = (char*)&default_lang_id[0]; *response_length = default_lang_id[0]; return true; } *response_data = (char*)&default_string[0]; *response_length = default_string[0]; return true; case USB_DT_BOS: *response_data = descs->bos; *response_length = descs->bos_len; return true; case USB_DT_DEVICE_QUALIFIER: if (!descs->qual) { struct usb_qualifier_descriptor* qual = (struct usb_qualifier_descriptor*)response_data; qual->bLength = sizeof(*qual); qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER; qual->bcdUSB = index->dev->bcdUSB; qual->bDeviceClass = index->dev->bDeviceClass; qual->bDeviceSubClass = index->dev->bDeviceSubClass; qual->bDeviceProtocol = index->dev->bDeviceProtocol; qual->bMaxPacketSize0 = index->dev->bMaxPacketSize0; qual->bNumConfigurations = index->dev->bNumConfigurations; qual->bRESERVED = 0; *response_length = sizeof(*qual); return true; } *response_data = descs->qual; *response_length = descs->qual_len; return true; default: exit(1); return false; } break; default: exit(1); return false; } break; default: exit(1); return false; } return false; } static volatile long syz_usb_connect(volatile long a0, volatile long a1, volatile long a2, volatile long a3) { uint64_t speed = a0; uint64_t dev_len = a1; char* dev = (char*)a2; struct vusb_connect_descriptors* descs = (struct vusb_connect_descriptors*)a3; if (!dev) { return -1; } struct usb_device_index index; memset(&index, 0, sizeof(index)); int rv = 0; rv = parse_usb_descriptor(dev, dev_len, &index); if (!rv) { return rv; } int fd = usb_fuzzer_open(); if (fd < 0) { return fd; } char device[32]; sprintf(&device[0], "dummy_udc.%llu", procid); rv = usb_fuzzer_init(fd, speed, "dummy_udc", &device[0]); if (rv < 0) { return rv; } rv = usb_fuzzer_run(fd); if (rv < 0) { return rv; } bool done = false; while (!done) { struct usb_fuzzer_control_event event; event.inner.type = 0; event.inner.length = sizeof(event.ctrl); rv = usb_fuzzer_event_fetch(fd, (struct usb_fuzzer_event*)&event); if (rv < 0) { return rv; } if (event.inner.type != USB_FUZZER_EVENT_CONTROL) continue; bool response_found = false; char* response_data = NULL; uint32_t response_length = 0; if (event.ctrl.bRequestType & USB_DIR_IN) { response_found = lookup_connect_response( descs, &index, &event.ctrl, &response_data, &response_length); if (!response_found) { return -1; } } else { if ((event.ctrl.bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD || event.ctrl.bRequest != USB_REQ_SET_CONFIGURATION) { exit(1); return -1; } done = true; } if (done) { rv = usb_fuzzer_vbus_draw(fd, index.config->bMaxPower); if (rv < 0) { return rv; } rv = usb_fuzzer_configure(fd); if (rv < 0) { return rv; } unsigned ep; for (ep = 0; ep < index.ifaces[0].eps_num; ep++) { rv = usb_fuzzer_ep_enable(fd, index.ifaces[0].eps[ep]); if (rv < 0) { } else { } } } struct usb_fuzzer_ep_io_data response; response.inner.ep = 0; response.inner.flags = 0; if (response_length > sizeof(response.data)) response_length = 0; if (event.ctrl.wLength < response_length) response_length = event.ctrl.wLength; response.inner.length = response_length; if (response_data) memcpy(&response.data[0], response_data, response_length); else memset(&response.data[0], 0, response_length); if (event.ctrl.bRequestType & USB_DIR_IN) { rv = usb_fuzzer_ep0_write(fd, (struct usb_fuzzer_ep_io*)&response); } else { rv = usb_fuzzer_ep0_read(fd, (struct usb_fuzzer_ep_io*)&response); } if (rv < 0) { return rv; } } sleep_ms(200); return fd; } static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2) { if (a0 == 0xc || a0 == 0xb) { char buf[128]; sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2); return open(buf, O_RDWR, 0); } else { char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } uint64_t r[1] = {0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); intptr_t res = 0; memcpy((void*)0x20000000, "\x12\x01\x00\x00\xaa\x3b\x98\x08\x11\x0f\x20\x20" "\xc9\x4a\x00\x00\x00\x01\x09\x02\x24\x00\x01\x00" "\x00\x00\x00\x09\x04\x1c\x00\x02\x91\x26\xc9\x00" "\x09\x05\x98\x45\x00\x00\x00\x00\x00\x09\x05\x87" "\x03\xa4\x22\x02\x01\x44", 54); syz_usb_connect(0, 0x36, 0x20000000, 0); res = syz_open_dev(0xc, 0xb4, 0); if (res != -1) r[0] = res; memcpy((void*)0x20000080, "\xc6", 1); syscall(__NR_write, r[0], 0x20000080, 1); return 0; }
the_stack_data/165767041.c
/* mbed Microcontroller Library ******************************************************************************* * Copyright (c) 2017, STMicroelectronics * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************* */ #if DEVICE_SERIAL #include "serial_api_hal.h" #define UART_NUM (9) uint32_t serial_irq_ids[UART_NUM] = {0}; UART_HandleTypeDef uart_handlers[UART_NUM]; static uart_irq_handler irq_handler; // Defined in serial_api.c extern int8_t get_uart_index(UARTName uart_name); /****************************************************************************** * INTERRUPTS HANDLING ******************************************************************************/ static void uart_irq(UARTName uart_name) { int8_t id = get_uart_index(uart_name); if (id >= 0) { UART_HandleTypeDef *huart = &uart_handlers[id]; if (serial_irq_ids[id] != 0) { if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) { if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET && __HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE)) { irq_handler(serial_irq_ids[id], TxIrq); } } if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) { if (__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET && __HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE)) { irq_handler(serial_irq_ids[id], RxIrq); /* Flag has been cleared when reading the content */ } } if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) { if (__HAL_UART_GET_IT(huart, UART_IT_ORE) != RESET) { __HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF); } } } } } #if defined(USART1_BASE) static void uart1_irq(void) { uart_irq(UART_1); } #endif #if defined(USART2_BASE) static void uart2_irq(void) { uart_irq(UART_2); } #endif #if defined(USART3_BASE) static void uart3_irq(void) { uart_irq(UART_3); } #endif #if defined(UART4_BASE) static void uart4_irq(void) { uart_irq(UART_4); } #endif #if defined(UART5_BASE) static void uart5_irq(void) { uart_irq(UART_5); } #endif #if defined(USART6_BASE) static void uart6_irq(void) { uart_irq(UART_6); } #endif #if defined(UART7_BASE) static void uart7_irq(void) { uart_irq(UART_7); } #endif #if defined(UART8_BASE) static void uart8_irq(void) { uart_irq(UART_8); } #endif #if defined(LPUART1_BASE) static void lpuart1_irq(void) { uart_irq(LPUART_1); } #endif void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) { struct serial_s *obj_s = SERIAL_S(obj); irq_handler = handler; serial_irq_ids[obj_s->index] = id; } void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) { struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; IRQn_Type irq_n = (IRQn_Type)0; uint32_t vector = 0; switch (obj_s->uart) { #if defined(USART1_BASE) case UART_1: irq_n = USART1_IRQn; vector = (uint32_t)&uart1_irq; break; #endif #if defined(USART2_BASE) case UART_2: irq_n = USART2_IRQn; vector = (uint32_t)&uart2_irq; break; #endif #if defined(USART3_BASE) case UART_3: irq_n = USART3_IRQn; vector = (uint32_t)&uart3_irq; break; #endif #if defined(UART4_BASE) case UART_4: irq_n = UART4_IRQn; vector = (uint32_t)&uart4_irq; break; #endif #if defined(UART5_BASE) case UART_5: irq_n = UART5_IRQn; vector = (uint32_t)&uart5_irq; break; #endif #if defined(USART6_BASE) case UART_6: irq_n = USART6_IRQn; vector = (uint32_t)&uart6_irq; break; #endif #if defined(UART7_BASE) case UART_7: irq_n = UART7_IRQn; vector = (uint32_t)&uart7_irq; break; #endif #if defined(UART8_BASE) case UART_8: irq_n = UART8_IRQn; vector = (uint32_t)&uart8_irq; break; #endif #if defined(LPUART1_BASE) case LPUART_1: irq_n = LPUART1_IRQn; vector = (uint32_t)&lpuart1_irq; break; #endif } if (enable) { if (irq == RxIrq) { __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE); } else { // TxIrq __HAL_UART_ENABLE_IT(huart, UART_IT_TXE); } NVIC_SetVector(irq_n, vector); NVIC_EnableIRQ(irq_n); } else { // disable int all_disabled = 0; if (irq == RxIrq) { __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE); // Check if TxIrq is disabled too if ((huart->Instance->CR1 & USART_CR1_TXEIE) == 0) { all_disabled = 1; } } else { // TxIrq __HAL_UART_DISABLE_IT(huart, UART_IT_TXE); // Check if RxIrq is disabled too if ((huart->Instance->CR1 & USART_CR1_RXNEIE) == 0) { all_disabled = 1; } } if (all_disabled) { NVIC_DisableIRQ(irq_n); } } } /****************************************************************************** * READ/WRITE ******************************************************************************/ int serial_getc(serial_t *obj) { struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; /* Computation of UART mask to apply to RDR register */ UART_MASK_COMPUTATION(huart); uint16_t uhMask = huart->Mask; while (!serial_readable(obj)); /* When receiving with the parity enabled, the value read in the MSB bit * is the received parity bit. */ return (int)(huart->Instance->RDR & uhMask); } void serial_putc(serial_t *obj, int c) { struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; while (!serial_writable(obj)); /* When transmitting with the parity enabled (PCE bit set to 1 in the * USART_CR1 register), the value written in the MSB (bit 7 or bit 8 * depending on the data length) has no effect because it is replaced * by the parity. */ huart->Instance->TDR = (uint16_t)(c & 0x1FFU); } void serial_clear(serial_t *obj) { struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; /* Clear RXNE and error flags */ volatile uint32_t tmpval __attribute__((unused)) = huart->Instance->RDR; HAL_UART_ErrorCallback(huart); } void serial_break_set(serial_t *obj) { struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; HAL_LIN_SendBreak(huart); } #if DEVICE_SERIAL_ASYNCH /****************************************************************************** * LOCAL HELPER FUNCTIONS ******************************************************************************/ /** * Configure the TX buffer for an asynchronous write serial transaction * * @param obj The serial object. * @param tx The buffer for sending. * @param tx_length The number of words to transmit. */ static void serial_tx_buffer_set(serial_t *obj, void *tx, int tx_length, uint8_t width) { (void)width; // Exit if a transmit is already on-going if (serial_tx_active(obj)) { return; } obj->tx_buff.buffer = tx; obj->tx_buff.length = tx_length; obj->tx_buff.pos = 0; } /** * Configure the RX buffer for an asynchronous write serial transaction * * @param obj The serial object. * @param tx The buffer for sending. * @param tx_length The number of words to transmit. */ static void serial_rx_buffer_set(serial_t *obj, void *rx, int rx_length, uint8_t width) { (void)width; // Exit if a reception is already on-going if (serial_rx_active(obj)) { return; } obj->rx_buff.buffer = rx; obj->rx_buff.length = rx_length; obj->rx_buff.pos = 0; } /** * Configure events * * @param obj The serial object * @param event The logical OR of the events to configure * @param enable Set to non-zero to enable events, or zero to disable them */ static void serial_enable_event(serial_t *obj, int event, uint8_t enable) { struct serial_s *obj_s = SERIAL_S(obj); // Shouldn't have to enable interrupt here, just need to keep track of the requested events. if (enable) { obj_s->events |= event; } else { obj_s->events &= ~event; } } /** * Get index of serial object TX IRQ, relating it to the physical peripheral. * * @param uart_name i.e. UART_1, UART_2, ... * @return internal NVIC TX IRQ index of U(S)ART peripheral */ static IRQn_Type serial_get_irq_n(UARTName uart_name) { IRQn_Type irq_n; switch (uart_name) { #if defined(USART1_BASE) case UART_1: irq_n = USART1_IRQn; break; #endif #if defined(USART2_BASE) case UART_2: irq_n = USART2_IRQn; break; #endif #if defined(USART3_BASE) case UART_3: irq_n = USART3_IRQn; break; #endif #if defined(UART4_BASE) case UART_4: irq_n = UART4_IRQn; break; #endif #if defined(UART5_BASE) case UART_5: irq_n = UART5_IRQn; break; #endif #if defined(USART6_BASE) case UART_6: irq_n = USART6_IRQn; break; #endif #if defined(UART7_BASE) case UART_7: irq_n = UART7_IRQn; break; #endif #if defined(UART8_BASE) case UART_8: irq_n = UART8_IRQn; break; #endif default: irq_n = (IRQn_Type)0; } return irq_n; } /****************************************************************************** * MBED API FUNCTIONS ******************************************************************************/ /** * Begin asynchronous TX transfer. The used buffer is specified in the serial * object, tx_buff * * @param obj The serial object * @param tx The buffer for sending * @param tx_length The number of words to transmit * @param tx_width The bit width of buffer word * @param handler The serial handler * @param event The logical OR of events to be registered * @param hint A suggestion for how to use DMA with this transfer * @return Returns number of data transfered, or 0 otherwise */ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint) { // TODO: DMA usage is currently ignored (void) hint; // Check buffer is ok MBED_ASSERT(tx != (void *)0); MBED_ASSERT(tx_width == 8); // support only 8b width struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; if (tx_length == 0) { return 0; } // Set up buffer serial_tx_buffer_set(obj, (void *)tx, tx_length, tx_width); // Set up events serial_enable_event(obj, SERIAL_EVENT_TX_ALL, 0); // Clear all events serial_enable_event(obj, event, 1); // Set only the wanted events // Enable interrupt IRQn_Type irq_n = serial_get_irq_n(obj_s->uart); NVIC_ClearPendingIRQ(irq_n); NVIC_DisableIRQ(irq_n); NVIC_SetPriority(irq_n, 1); NVIC_SetVector(irq_n, (uint32_t)handler); NVIC_EnableIRQ(irq_n); // the following function will enable UART_IT_TXE and error interrupts if (HAL_UART_Transmit_IT(huart, (uint8_t *)tx, tx_length) != HAL_OK) { return 0; } return tx_length; } /** * Begin asynchronous RX transfer (enable interrupt for data collecting) * The used buffer is specified in the serial object, rx_buff * * @param obj The serial object * @param rx The buffer for sending * @param rx_length The number of words to transmit * @param rx_width The bit width of buffer word * @param handler The serial handler * @param event The logical OR of events to be registered * @param handler The serial handler * @param char_match A character in range 0-254 to be matched * @param hint A suggestion for how to use DMA with this transfer */ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint) { // TODO: DMA usage is currently ignored (void) hint; /* Sanity check arguments */ MBED_ASSERT(obj); MBED_ASSERT(rx != (void *)0); MBED_ASSERT(rx_width == 8); // support only 8b width struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; serial_enable_event(obj, SERIAL_EVENT_RX_ALL, 0); serial_enable_event(obj, event, 1); // set CharMatch obj->char_match = char_match; serial_rx_buffer_set(obj, rx, rx_length, rx_width); IRQn_Type irq_n = serial_get_irq_n(obj_s->uart); NVIC_ClearPendingIRQ(irq_n); NVIC_DisableIRQ(irq_n); NVIC_SetPriority(irq_n, 0); NVIC_SetVector(irq_n, (uint32_t)handler); NVIC_EnableIRQ(irq_n); // following HAL function will enable the RXNE interrupt + error interrupts HAL_UART_Receive_IT(huart, (uint8_t *)rx, rx_length); } /** * Attempts to determine if the serial peripheral is already in use for TX * * @param obj The serial object * @return Non-zero if the TX transaction is ongoing, 0 otherwise */ uint8_t serial_tx_active(serial_t *obj) { MBED_ASSERT(obj); struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; return (((HAL_UART_GetState(huart) & HAL_UART_STATE_BUSY_TX) == HAL_UART_STATE_BUSY_TX) ? 1 : 0); } /** * Attempts to determine if the serial peripheral is already in use for RX * * @param obj The serial object * @return Non-zero if the RX transaction is ongoing, 0 otherwise */ uint8_t serial_rx_active(serial_t *obj) { MBED_ASSERT(obj); struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; return (((HAL_UART_GetState(huart) & HAL_UART_STATE_BUSY_RX) == HAL_UART_STATE_BUSY_RX) ? 1 : 0); } void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) { if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) { __HAL_UART_CLEAR_IT(huart, UART_CLEAR_PEF); } if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) { __HAL_UART_CLEAR_IT(huart, UART_CLEAR_FEF); } if (__HAL_UART_GET_FLAG(huart, UART_FLAG_NE) != RESET) { __HAL_UART_CLEAR_IT(huart, UART_CLEAR_NEF); } if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) { __HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF); } } /** * The asynchronous TX and RX handler. * * @param obj The serial object * @return Returns event flags if a TX/RX transfer termination condition was met or 0 otherwise */ int serial_irq_handler_asynch(serial_t *obj) { struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; volatile int return_event = 0; uint8_t *buf = (uint8_t *)(obj->rx_buff.buffer); size_t i = 0; // TX PART: if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TC) != RESET) { if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TC) != RESET) { // Return event SERIAL_EVENT_TX_COMPLETE if requested if ((obj_s->events & SERIAL_EVENT_TX_COMPLETE) != 0) { return_event |= (SERIAL_EVENT_TX_COMPLETE & obj_s->events); } } } // Handle error events if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) { if (__HAL_UART_GET_IT(huart, UART_IT_PE) != RESET) { return_event |= (SERIAL_EVENT_RX_PARITY_ERROR & obj_s->events); } } if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) { if (__HAL_UART_GET_IT(huart, UART_IT_FE) != RESET) { return_event |= (SERIAL_EVENT_RX_FRAMING_ERROR & obj_s->events); } } if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) { if (__HAL_UART_GET_IT(huart, UART_IT_ORE) != RESET) { return_event |= (SERIAL_EVENT_RX_OVERRUN_ERROR & obj_s->events); } } HAL_UART_IRQHandler(huart); // Abort if an error occurs if ((return_event & SERIAL_EVENT_RX_PARITY_ERROR) || (return_event & SERIAL_EVENT_RX_FRAMING_ERROR) || (return_event & SERIAL_EVENT_RX_OVERRUN_ERROR)) { return return_event; } //RX PART if (huart->RxXferSize != 0) { obj->rx_buff.pos = huart->RxXferSize - huart->RxXferCount; } if ((huart->RxXferCount == 0) && (obj->rx_buff.pos >= (obj->rx_buff.length - 1))) { return_event |= (SERIAL_EVENT_RX_COMPLETE & obj_s->events); } // Check if char_match is present if (obj_s->events & SERIAL_EVENT_RX_CHARACTER_MATCH) { if (buf != NULL) { for (i = 0; i < obj->rx_buff.pos; i++) { if (buf[i] == obj->char_match) { obj->rx_buff.pos = i; return_event |= (SERIAL_EVENT_RX_CHARACTER_MATCH & obj_s->events); serial_rx_abort_asynch(obj); break; } } } } return return_event; } /** * Abort the ongoing TX transaction. It disables the enabled interupt for TX and * flush TX hardware buffer if TX FIFO is used * * @param obj The serial object */ void serial_tx_abort_asynch(serial_t *obj) { struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; __HAL_UART_DISABLE_IT(huart, UART_IT_TC); __HAL_UART_DISABLE_IT(huart, UART_IT_TXE); // reset states huart->TxXferCount = 0; // update handle state if (huart->gState == HAL_UART_STATE_BUSY_TX_RX) { huart->gState = HAL_UART_STATE_BUSY_RX; } else { huart->gState = HAL_UART_STATE_READY; } } /** * Abort the ongoing RX transaction It disables the enabled interrupt for RX and * flush RX hardware buffer if RX FIFO is used * * @param obj The serial object */ void serial_rx_abort_asynch(serial_t *obj) { struct serial_s *obj_s = SERIAL_S(obj); UART_HandleTypeDef *huart = &uart_handlers[obj_s->index]; // disable interrupts __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE); __HAL_UART_DISABLE_IT(huart, UART_IT_PE); __HAL_UART_DISABLE_IT(huart, UART_IT_ERR); // clear flags volatile uint32_t tmpval __attribute__((unused)) = huart->Instance->RDR; // Clear RXNE __HAL_UART_CLEAR_IT(huart, UART_CLEAR_PEF); __HAL_UART_CLEAR_IT(huart, UART_CLEAR_FEF); __HAL_UART_CLEAR_IT(huart, UART_CLEAR_NEF); __HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF); // reset states huart->RxXferCount = 0; // update handle state if (huart->RxState == HAL_UART_STATE_BUSY_TX_RX) { huart->RxState = HAL_UART_STATE_BUSY_TX; } else { huart->RxState = HAL_UART_STATE_READY; } } #endif /* DEVICE_SERIAL_ASYNCH */ #if DEVICE_SERIAL_FC /** * Set HW Control Flow * @param obj The serial object * @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS) * @param rxflow Pin for the rxflow * @param txflow Pin for the txflow */ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) { struct serial_s *obj_s = SERIAL_S(obj); // Checked used UART name (UART_1, UART_2, ...) UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { MBED_ASSERT(0); return; } if (type == FlowControlNone) { // Disable hardware flow control obj_s->hw_flow_ctl = UART_HWCONTROL_NONE; } if (type == FlowControlRTS) { // Enable RTS MBED_ASSERT(uart_rts != (UARTName)NC); obj_s->hw_flow_ctl = UART_HWCONTROL_RTS; obj_s->pin_rts = rxflow; // Enable the pin for RTS function pinmap_pinout(rxflow, PinMap_UART_RTS); } if (type == FlowControlCTS) { // Enable CTS MBED_ASSERT(uart_cts != (UARTName)NC); obj_s->hw_flow_ctl = UART_HWCONTROL_CTS; obj_s->pin_cts = txflow; // Enable the pin for CTS function pinmap_pinout(txflow, PinMap_UART_CTS); } if (type == FlowControlRTSCTS) { // Enable CTS & RTS MBED_ASSERT(uart_rts != (UARTName)NC); MBED_ASSERT(uart_cts != (UARTName)NC); obj_s->hw_flow_ctl = UART_HWCONTROL_RTS_CTS; obj_s->pin_rts = rxflow; obj_s->pin_cts = txflow; // Enable the pin for CTS function pinmap_pinout(txflow, PinMap_UART_CTS); // Enable the pin for RTS function pinmap_pinout(rxflow, PinMap_UART_RTS); } init_uart(obj); } #endif /* DEVICE_SERIAL_FC */ #endif /* DEVICE_SERIAL */
the_stack_data/51699350.c
//Mean-crossings (MCs) by same method as zero-crossings (ZCs). //If mean happens to equal 0.0, then same output as zcs. #include <stdio.h> #ifdef __cplusplus namespace codee { extern "C" { #endif int mcs_s (int *Y, const float *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim, const int going); int mcs_d (int *Y, const double *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim, const int going); int mcs_s (int *Y, const float *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim, const int going) { if (dim>3u) { fprintf(stderr,"error in mcs_s: dim must be in [0 3]\n"); return 1; } const size_t N = R*C*S*H; const size_t L = (dim==0u) ? R : (dim==1u) ? C : (dim==2u) ? S : H; int s, sp; float mn; if (N==0u) {} else if (L==N) { //Mean mn = 0.0f; for (size_t l=L; l>0u; --l, ++X) { mn += *X; } mn /= (float)L; X -= L; if (going==0) { sp = (*X++<mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X<mn); *Y = (s!=sp); sp = s; } } else if (going==1) { sp = (*X++>=mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X>=mn); *Y = s*(s!=sp); sp = s; } } else if (going==-1) { sp = (*X++<mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X<mn); *Y = s*(s!=sp); sp = s; } } else { fprintf(stderr,"error in mcs_s: going must be in {-1,0,1}\n"); return 1; } } else { const size_t K = (iscolmajor) ? ((dim==0u) ? 1u : (dim==1u) ? R : (dim==2u) ? R*C : R*C*S) : ((dim==0u) ? C*S*H : (dim==1u) ? S*H : (dim==2u) ? H : 1u); const size_t B = (iscolmajor && dim==0u) ? C*S*H : K; const size_t V = N/L, G = V/B; if (K==1u && (G==1u || B==1u)) { if (going==0) { for (size_t v=V; v>0u; --v) { mn = 0.0f; for (size_t l=L; l>0u; --l, ++X) { mn += *X; } mn /= (float)L; X -= L; sp = (*X++<mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X<mn); *Y = (s!=sp); sp = s; } } } else if (going==1) { for (size_t v=V; v>0u; --v) { mn = 0.0f; for (size_t l=L; l>0u; --l, ++X) { mn += *X; } mn /= (float)L; X -= L; sp = (*X++>=mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X>=mn); *Y = s*(s!=sp); sp = s; } } } else if (going==-1) { for (size_t v=V; v>0u; --v) { mn = 0.0f; for (size_t l=L; l>0u; --l, ++X) { mn += *X; } mn /= (float)L; X -= L; sp = (*X++<mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X<mn); *Y = s*(s!=sp); sp = s; } } } else { fprintf(stderr,"error in mcs_s: going must be in {-1,0,1}\n"); return 1; } } else { if (going==0) { for (size_t g=G; g>0u; --g, X+=B*(L-1u), Y+=B*(L-1u)) { for (size_t b=B; b>0u; --b, X-=K*L-1u, Y-=K*L-1u) { mn = 0.0f; for (size_t l=L; l>0u; --l, X+=K) { mn += *X; } mn /= (float)L; X -= L*K; sp = (*X<mn); *Y = 0; X+=K; Y+=K; for (size_t l=L; l>1u; --l, X+=K, Y+=K) { s = (*X<mn); *Y = (s!=sp); sp = s; } } } } else if (going==1) { for (size_t g=G; g>0u; --g, X+=B*(L-1u), Y+=B*(L-1u)) { for (size_t b=B; b>0u; --b, X-=K*L-1u, Y-=K*L-1u) { mn = 0.0f; for (size_t l=L; l>0u; --l, X+=K) { mn += *X; } mn /= (float)L; X -= L*K; sp = (*X>=mn); *Y = 0; X+=K; Y+=K; for (size_t l=L; l>1u; --l, X+=K, Y+=K) { s = (*X>=mn); *Y = s*(s!=sp); sp = s; } } } } else if (going==-1) { for (size_t g=G; g>0u; --g, X+=B*(L-1u), Y+=B*(L-1u)) { for (size_t b=B; b>0u; --b, X-=K*L-1u, Y-=K*L-1u) { mn = 0.0f; for (size_t l=L; l>0u; --l, X+=K) { mn += *X; } mn /= (float)L; X -= L*K; sp = (*X<mn); *Y = 0; X+=K; Y+=K; for (size_t l=L; l>1u; --l, X+=K, Y+=K) { s = (*X<mn); *Y = s*(s!=sp); sp = s; } } } } else { fprintf(stderr,"error in mcs_s: going must be in {-1,0,1}\n"); return 1; } } } return 0; } int mcs_d (int *Y, const double *X, const size_t R, const size_t C, const size_t S, const size_t H, const int iscolmajor, const size_t dim, const int going) { if (dim>3u) { fprintf(stderr,"error in mcs_d: dim must be in [0 3]\n"); return 1; } const size_t N = R*C*S*H; const size_t L = (dim==0u) ? R : (dim==1u) ? C : (dim==2u) ? S : H; int s, sp; double mn; if (N==0u) {} else if (L==N) { //Mean mn = 0.0; for (size_t l=L; l>0u; --l, ++X) { mn += *X; } mn /= (double)L; X -= L; if (going==0) { sp = (*X++<mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X<mn); *Y = (s!=sp); sp = s; } } else if (going==1) { sp = (*X++>=mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X>=mn); *Y = s*(s!=sp); sp = s; } } else if (going==-1) { sp = (*X++<mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X<mn); *Y = s*(s!=sp); sp = s; } } else { fprintf(stderr,"error in mcs_d: going must be in {-1,0,1}\n"); return 1; } } else { const size_t K = (iscolmajor) ? ((dim==0u) ? 1u : (dim==1u) ? R : (dim==2u) ? R*C : R*C*S) : ((dim==0u) ? C*S*H : (dim==1u) ? S*H : (dim==2u) ? H : 1u); const size_t B = (iscolmajor && dim==0u) ? C*S*H : K; const size_t V = N/L, G = V/B; if (K==1u && (G==1u || B==1u)) { if (going==0) { for (size_t v=V; v>0u; --v) { mn = 0.0; for (size_t l=L; l>0u; --l, ++X) { mn += *X; } mn /= (double)L; X -= L; sp = (*X++<mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X<mn); *Y = (s!=sp); sp = s; } } } else if (going==1) { for (size_t v=V; v>0u; --v) { mn = 0.0; for (size_t l=L; l>0u; --l, ++X) { mn += *X; } mn /= (double)L; X -= L; sp = (*X++>=mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X>=mn); *Y = s*(s!=sp); sp = s; } } } else if (going==-1) { for (size_t v=V; v>0u; --v) { mn = 0.0; for (size_t l=L; l>0u; --l, ++X) { mn += *X; } mn /= (double)L; X -= L; sp = (*X++<mn); *Y++ = 0; for (size_t l=L; l>1u; --l, ++X, ++Y) { s = (*X<mn); *Y = s*(s!=sp); sp = s; } } } else { fprintf(stderr,"error in mcs_d: going must be in {-1,0,1}\n"); return 1; } } else { if (going==0) { for (size_t g=G; g>0u; --g, X+=B*(L-1u), Y+=B*(L-1u)) { for (size_t b=B; b>0u; --b, X-=K*L-1u, Y-=K*L-1u) { mn = 0.0; for (size_t l=L; l>0u; --l, X+=K) { mn += *X; } mn /= (double)L; X -= L*K; sp = (*X<mn); *Y = 0; X+=K; Y+=K; for (size_t l=L; l>1u; --l, X+=K, Y+=K) { s = (*X<mn); *Y = (s!=sp); sp = s; } } } } else if (going==1) { for (size_t g=G; g>0u; --g, X+=B*(L-1u), Y+=B*(L-1u)) { for (size_t b=B; b>0u; --b, X-=K*L-1u, Y-=K*L-1u) { mn = 0.0; for (size_t l=L; l>0u; --l, X+=K) { mn += *X; } mn /= (double)L; X -= L*K; sp = (*X>=mn); *Y = 0; X+=K; Y+=K; for (size_t l=L; l>1u; --l, X+=K, Y+=K) { s = (*X>=mn); *Y = s*(s!=sp); sp = s; } } } } else if (going==-1) { for (size_t g=G; g>0u; --g, X+=B*(L-1u), Y+=B*(L-1u)) { for (size_t b=B; b>0u; --b, X-=K*L-1u, Y-=K*L-1u) { mn = 0.0; for (size_t l=L; l>0u; --l, X+=K) { mn += *X; } mn /= (double)L; X -= L*K; sp = (*X<mn); *Y = 0; X+=K; Y+=K; for (size_t l=L; l>1u; --l, X+=K, Y+=K) { s = (*X<mn); *Y = s*(s!=sp); sp = s; } } } } else { fprintf(stderr,"error in mcs_d: going must be in {-1,0,1}\n"); return 1; } } } return 0; } #ifdef __cplusplus } } #endif
the_stack_data/68887062.c
#include <stdio.h> #include <stdlib.h> #define WIDTH 100 #define HEIGHT 100 #define PIXEL_DEPTH 15 #define MAX_COMMANDS 100 #define DRAW_LINE 0 #define DRAW_SQUARE 1 #define DRAW_SQUAREFILLED 2 #define DRAW_CIRCLE 3 #define DRAW_ARROW 4 #define DRAW_TRIANGLE 5 #define DRAW_TRIANGLERECT 6 #define DRAW_Pack 7 #define CLEAR_BUFFER 8 #define END_CMD 100 int imagem[WIDTH * HEIGHT]; int comandos[MAX_COMMANDS]; void salvar_imagem(char* nome) { int i; int r; int g; int b; FILE* arquivo; arquivo = fopen(nome, "w"); if (arquivo == NULL) { printf("Erro ao abrir o arquivo %s para escrita\n", nome); exit(0); } /* Cabecalho... */ fprintf(arquivo, "P3\n%i %i\n%i\n", WIDTH, HEIGHT, PIXEL_DEPTH); /* Pixels... */ for (i = 0; i < WIDTH * HEIGHT; ++i) { r = (imagem[i] & 0x0f00) >> 8; g = (imagem[i] & 0x00f0) >> 4; b = (imagem[i] & 0x000f); fprintf(arquivo, "%i %i %i\n", r, g, b); } fclose(arquivo); } void set_pixel(int col, int row, int pixel) { imagem[row * WIDTH + col] = pixel; } int abs(int n) { if (n < 0) { return -n; } return n; } void line(int x0, int y0, int x1, int y1, int pixel) { int dx; int dy; int sx; int sy; int err; int e2; dx = abs(x1-x0); dy = abs(y1-y0); sx = x0<x1 ? 1 : -1; sy = y0<y1 ? 1 : -1; err = (dx > dy ? dx : -dy) / 2; while (1) { set_pixel(x0, y0, pixel); if (x0==x1 && y0==y1) break; e2 = err; if (e2 >-dx) { err -= dy; x0 += sx; } if (e2 < dy) { err += dx; y0 += sy; } } } void Triangle(int x,int y,int h, int pixel) { line(x-h, y, x, y-h, pixel); line(x+h, y, x, y-h, pixel); line(x-h, y, x+h, y, pixel); } void TriangleRect(int x,int y,int h, int pixel) { line(x+h, y-h, x, y, pixel); line(x+h, y, x+h, y-h, pixel); line(x, y, x+h, y, pixel); } void circle(int x,int y,int raio, int pixel) { float n=0,invraio=1/(float)raio; int dx=0,dy=raio-1; while (dx<=dy) { line(x+dy, y-dx, x+dy, y-dx, pixel); // 1o line(x+dx,y-dy,x+dx,y-dy,pixel); // 2o line(x-dx,y-dy,x-dx,y-dy,pixel); // 3o line(x-dy,y-dx,x-dy,y-dx,pixel); // 4o line(x-dy,y+dx,x-dy,y+dx,pixel); // 5o line(x-dx,y+dy,x-dx,y+dy,pixel); // 6o line(x+dx,y+dy,x+dx,y+dy,pixel); // 7o line(x+dy,y+dx,x+dy,y+dx,pixel); // 8o dx++; n+=invraio; dy=raio * sin(acos(n)); } } void circlePAck(int x,int y,int raio, int pixel) { float n=0,invraio=1/(float)raio; int dx=0,dy=raio-1; while (dx<=dy) { line(x+dy, y-dx, x+dy, y-dx, pixel); line(x+dx,y-dy,x+dx,y-dy,pixel); // 2o line(x-dx,y-dy,x-dx,y-dy,pixel); // 3o line(x-dy,y-dx,x-dy,y-dx,pixel); // 4o line(x-dy,y+dx,x-dy,y+dx,pixel); // 5o line(x-dx,y+dy,x-dx,y+dy,pixel); // 6o line(x+dx,y+dy,x+dx,y+dy,pixel); // 7o dx++; n+=invraio; dy=raio * sin(acos(n)); } } void square(int col, int row, int size, int pixel) { line(col, row, col + size, row, pixel); line(col + size, row, col + size, row + size, pixel); line(col + size, row + size, col, row + size, pixel); line(col, row + size, col, row, pixel); } void squareFilled(int col,int row,int size, int pixel) { int a = 0; for(;a<=size;a++) line(col, row+a, col + size, row+a, pixel); } void arrow(int x0, int y0, int x1, int y1, int pixel) // 15 15 70 70 cor { line(x0, y0, x1, y1, pixel); line(x0,y0,x0,y0-10,0x00F); line(x0,y0,x0-10,y0,0x00F); line(x0+5, y0+5, x0+5,y0-5,0x00F); line(x0+5, y0+5, x0-5, y0+5, 0x00F); line(x0+10, y0+10, x0+10, y0, 0x00F); line(x0+10, y0+10, x0, y0+10, 0x00F); line(x0+15,y0+15, x0+15,y0+5, 0x00F); line(x0+15,y0+15,x0+5,y0+15,0x00F); TriangleRect(x1-7,x1+8,15,0xF00); circle(x1+3,y1+3,15, 0x0F0); } void Pack(int x,int y,int raio, int pixel) { int aux; for(aux = 0;aux<=raio;aux ++) { circlePAck(x, y, aux, 0xFF0); } for(aux = 7;aux>=0;aux--) { circle(60,30,aux,0xFFF); circle(80,64, aux,0x00F); } } void clear_buffer(int pixel) { int i; for (i = 0; i < WIDTH * HEIGHT; ++i) { imagem[i] = pixel; } } void processar_comandos() { int i; int cmd; int op1; int op2; int op3; int op4; int op5; int op6; int op7; i = 0; while (i < MAX_COMMANDS) { cmd = comandos[i]; switch (cmd) { case DRAW_LINE: op1 = comandos[i + 1]; // x0 op2 = comandos[i + 2]; // y0 op3 = comandos[i + 3]; // x1 op4 = comandos[i + 4]; // y1 op5 = comandos[i + 5]; // cor line(op1, op2, op3, op4, op5); i = i + 6; // ir para proximo comando break; case DRAW_ARROW: op1 = comandos[i + 1]; // x0 op2 = comandos[i + 2]; // y0 op3 = comandos[i + 3]; // x1 op4 = comandos[i + 4]; // y1 op5 = comandos[i + 5]; // cor arrow(op1, op2, op3, op4, op5); i = i + 6; // ir para proximo comando break; case DRAW_SQUARE: op1 = comandos[i + 1]; // x op2 = comandos[i + 2]; // y op3 = comandos[i + 3]; // tamanho op4 = comandos[i + 4]; // cor square(op1, op2, 5, op4); i = i + 5; // ir para proximo comando break; case DRAW_CIRCLE: op1 = comandos[i + 1]; // x op2 = comandos[i + 2]; // y op3 = comandos[i + 3]; // raio op4 = comandos[i + 4]; // cor circle(op1, op2, op3, op4); i = i + 5; // ir para proximo comando break; case DRAW_Pack: op1 = comandos[i + 1]; // x op2 = comandos[i + 2]; // y op3 = comandos[i + 3]; // raio op4 = comandos[i + 4]; // cor Pack(op1, op2, op3, op4); i = i + 5; // ir para proximo comando break; case DRAW_TRIANGLE: op1 = comandos[i + 1]; // x op2 = comandos[i + 2]; // y op3 = comandos[i + 3]; // op4 = comandos[i + 4]; // cor Triangle(op1, op2, op3, op4); i = i + 5; // ir para proximo comando break; case DRAW_TRIANGLERECT: op1 = comandos[i + 1]; // x op2 = comandos[i + 2]; // y op3 = comandos[i + 3]; // op4 = comandos[i + 4]; // cor TriangleRect(op1, op2, op3, op4); i = i + 5; // ir para proximo comando break; case DRAW_SQUAREFILLED: op1 = comandos[i + 1]; // x op2 = comandos[i + 2]; // y op3 = comandos[i + 3]; // tamanho op4 = comandos[i + 4]; // cor squareFilled(op1, op2, op3, op4); i = i + 5; // ir para proximo comando break; case CLEAR_BUFFER: op1 = comandos[i + 1]; // pixel clear_buffer(op1); i = i + 2; break; case END_CMD: i = MAX_COMMANDS; // n ha mais comandos a ser executado, sai do loop } } } /* imagem com as cores primarias */ int main() { int i; int j; comandos[0] = CLEAR_BUFFER; comandos[1] = 0x0FFF; comandos[2] = DRAW_ARROW; comandos[3] = 15; comandos[4] = 15; comandos[5] = 70; comandos[6] = 70; comandos[7] = 0x000; /* comandos[8] = DRAW_SQUARE; comandos[9] = 40; comandos[10] = 50; comandos[11] = 15; comandos[12] = 0xFFF;*/ /* comandos[2] = DRAW_Pack; comandos[3] = 50; comandos[4] = 50; comandos[5] = 40; comandos[6] = 0x0F0;*/ /* comandos[13] = DRAW_TRIANGLE; comandos[14] = 15; comandos[15] = 60; comandos[16] = 15; comandos[17] = 0xFFF; comandos[18] = DRAW_TRIANGLERECT; comandos[19] = 63; comandos[20] = 78; comandos[21] = 15; comandos[22] = 0xF00; comandos[23] = DRAW_SQUAREFILLED; comandos[24] = 60; comandos[25] = 0; comandos[26] = 30; comandos[27] = 0xFFF; comandos[28] = DRAW_LINE; comandos[29] = 20; comandos[30] = 20; comandos[31] = 20; comandos[32] = 10; comandos[33] = 0x000F; comandos[34] = DRAW_LINE; comandos[35] = 20; comandos[36] = 20; comandos[37] = 10; comandos[38] = 20; comandos[39] = 0x000F; comandos[40] = DRAW_LINE; comandos[41] = 25; comandos[42] = 24; comandos[43] = 25; comandos[44] = 14; comandos[45] = 0x000F; comandos[46] = DRAW_LINE; comandos[47] = 24; comandos[48] = 25; comandos[49] = 14; comandos[50] = 25; comandos[51] = 0x000F; comandos[52] = DRAW_LINE; comandos[53] = 30; comandos[54] = 29; comandos[55] = 30; comandos[56] = 19; comandos[57] = 0x000F; comandos[58] = DRAW_LINE; comandos[59] = 29; comandos[60] = 30; comandos[61] = 19; comandos[62] = 30; comandos[63] = 0x000F; comandos[64] = DRAW_LINE; comandos[65] = 15; comandos[66] = 15; comandos[67] = 15; comandos[68] = 5; comandos[69] = 0x000F; comandos[70] = DRAW_LINE; comandos[71] = 15; comandos[72] = 15; comandos[73] = 5; comandos[74] = 15; comandos[75] = 0x000F;*/ /*comandos[2] = DRAW_LINE; comandos[3] = 78; comandos[4] = 63; comandos[5] = 63; comandos[6] = 78; comandos[7] = 0x000F; comandos[8] = DRAW_LINE; comandos[9] = 78; comandos[10] = 78; comandos[11] = 78; comandos[12] = 63; comandos[13] = 0x000F; comandos[14] = DRAW_LINE; comandos[15] = 63; comandos[16] = 78; comandos[17] = 78; comandos[18] = 78; comandos[19] = 0x000F; comandos[20] = DRAW_LINE; comandos[21] = 15; comandos[22] = 15; comandos[23] = 70; comandos[24] = 70; comandos[25] = 0x000F;*/ comandos[8] = END_CMD; processar_comandos(); salvar_imagem("imagem2.ppm"); return 0; }
the_stack_data/1184944.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); extern void __VERIFIER_assume(int); void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } } extern int __VERIFIER_nondet_int(void); int N; int main() { N = __VERIFIER_nondet_int(); if(N <= 0) return 1; int i; int a[N]; int b[N]; b[0] = 0; a[0] = 0; for(i=1; i<N; i++) { b[i] = b[i-1] + 2; } for(i=1; i<N; i++) { a[i] = a[i-1] + b[i-1] + 2; } for(i=0; i<N; i++) { __VERIFIER_assert(a[i] == (i+1)*(i+1)); } return 1; }
the_stack_data/72012735.c
/* tprintf.c -- test file for mpfr_printf and mpfr_vprintf Copyright 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. Contributed by the AriC and Caramel projects, INRIA. This file is part of the GNU MPFR Library. The GNU MPFR Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The GNU MPFR Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #if HAVE_STDARG #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include "mpfr-intmax.h" #include "mpfr-test.h" #define STDOUT_FILENO 1 #if MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0) #define QUOTE(X) NAME(X) #define NAME(X) #X /* unlike other tests, we print out errors to stderr because stdout might be redirected */ #define check_length(num_test, var, value, var_spec) \ if ((var) != (value)) \ { \ fprintf (stderr, "Error in test #%d: mpfr_printf printed %" \ QUOTE(var_spec)" characters instead of %d\n", \ (num_test), (var), (value)); \ exit (1); \ } #define check_length_with_cmp(num_test, var, value, cmp, var_spec) \ if (cmp != 0) \ { \ mpfr_fprintf (stderr, "Error in test #%d, mpfr_printf printed %" \ QUOTE(var_spec)" characters instead of %d\n", \ (num_test), (var), (value)); \ exit (1); \ } /* limit for random precision in random() */ const int prec_max_printf = 5000; /* boolean: is stdout redirected to a file ? */ int stdout_redirect; static void check (const char *fmt, mpfr_t x) { if (mpfr_printf (fmt, x) == -1) { fprintf (stderr, "Error in mpfr_printf(\"%s\", ...)\n", fmt); exit (1); } putchar ('\n'); } static void check_vprintf (const char *fmt, ...) { va_list ap; va_start (ap, fmt); if (mpfr_vprintf (fmt, ap) == -1) { fprintf (stderr, "Error in mpfr_vprintf(\"%s\", ...)\n", fmt); va_end (ap); exit (1); } putchar ('\n'); va_end (ap); } static void check_vprintf_failure (const char *fmt, ...) { va_list ap; va_start (ap, fmt); if (mpfr_vprintf (fmt, ap) != -1) { putchar ('\n'); fprintf (stderr, "Error in mpfr_vprintf(\"%s\", ...)\n", fmt); va_end (ap); exit (1); } putchar ('\n'); va_end (ap); } static void check_invalid_format (void) { int i = 0; /* format in disorder */ check_vprintf_failure ("blah %l2.1d blah", i); check_vprintf_failure ("blah %2.1#d blah", i); /* incomplete format */ check_vprintf_failure ("%", i); check_vprintf_failure ("% (missing conversion specifier)", i); check_vprintf_failure ("missing conversion specifier %h", i); check_vprintf_failure ("this should fail %.l because of missing conversion specifier " "(or doubling %%)", i); check_vprintf_failure ("%L", i); check_vprintf_failure ("%hh. ", i); check_vprintf_failure ("blah %j."); check_vprintf_failure ("%ll blah"); check_vprintf_failure ("blah%t blah"); check_vprintf_failure ("%z "); check_vprintf_failure ("%F (missing conversion specifier)"); check_vprintf_failure ("%Q (missing conversion specifier)"); check_vprintf_failure ("%M (missing conversion specifier)"); check_vprintf_failure ("%N (missing conversion specifier)"); check_vprintf_failure ("%Z (missing conversion specifier)"); check_vprintf_failure ("%R (missing conversion specifier)"); check_vprintf_failure ("%R"); check_vprintf_failure ("%P (missing conversion specifier)"); /* conversion specifier with wrong length specifier */ check_vprintf_failure ("%ha", i); check_vprintf_failure ("%hhe", i); check_vprintf_failure ("%jf", i); check_vprintf_failure ("%lg", i); check_vprintf_failure ("%tA", i); check_vprintf_failure ("%zE", i); check_vprintf_failure ("%Ld", i); check_vprintf_failure ("%Qf", i); check_vprintf_failure ("%MG", i); check_vprintf_failure ("%Na", i); check_vprintf_failure ("%ZE", i); check_vprintf_failure ("%PG", i); check_vprintf_failure ("%Fu", i); check_vprintf_failure ("%Rx", i); } static void check_long_string (void) { /* this test is VERY expensive both in time (~1 min on core2 @ 2.40GHz) and in memory (~2.5 GB) */ mpfr_t x; mpfr_init2 (x, INT_MAX); mpfr_set_ui (x, 1, MPFR_RNDN); mpfr_nextabove (x); check_vprintf_failure ("%Rb", x); check_vprintf_failure ("%RA %RA %Ra %Ra", x, x, x, x); mpfr_clear (x); } static void check_special (void) { mpfr_t x; mpfr_init (x); mpfr_set_inf (x, 1); check ("%Ra", x); check ("%Rb", x); check ("%Re", x); check ("%Rf", x); check ("%Rg", x); check_vprintf ("%Ra", x); check_vprintf ("%Rb", x); check_vprintf ("%Re", x); check_vprintf ("%Rf", x); check_vprintf ("%Rg", x); mpfr_set_inf (x, -1); check ("%Ra", x); check ("%Rb", x); check ("%Re", x); check ("%Rf", x); check ("%Rg", x); check_vprintf ("%Ra", x); check_vprintf ("%Rb", x); check_vprintf ("%Re", x); check_vprintf ("%Rf", x); check_vprintf ("%Rg", x); mpfr_set_nan (x); check ("%Ra", x); check ("%Rb", x); check ("%Re", x); check ("%Rf", x); check ("%Rg", x); check_vprintf ("%Ra", x); check_vprintf ("%Rb", x); check_vprintf ("%Re", x); check_vprintf ("%Rf", x); check_vprintf ("%Rg", x); mpfr_clear (x); } static void check_mixed (void) { int ch = 'a'; #ifndef NPRINTF_HH signed char sch = -1; unsigned char uch = 1; #endif short sh = -1; unsigned short ush = 1; int i = -1; int j = 1; unsigned int ui = 1; long lo = -1; unsigned long ulo = 1; float f = -1.25; double d = -1.25; #if !defined(NPRINTF_T) || !defined(NPRINTF_L) long double ld = -1.25; #endif #ifndef NPRINTF_T ptrdiff_t p = 1, saved_p; #endif size_t sz = 1; mpz_t mpz; mpq_t mpq; mpf_t mpf; mpfr_rnd_t rnd = MPFR_RNDN; mpfr_t mpfr; mpfr_prec_t prec; mpz_init (mpz); mpz_set_ui (mpz, ulo); mpq_init (mpq); mpq_set_si (mpq, lo, ulo); mpf_init (mpf); mpf_set_q (mpf, mpq); mpfr_init (mpfr); mpfr_set_f (mpfr, mpf, MPFR_RNDN); prec = mpfr_get_prec (mpfr); check_vprintf ("a. %Ra, b. %u, c. %lx%n", mpfr, ui, ulo, &j); check_length (1, j, 22, d); check_vprintf ("a. %c, b. %Rb, c. %u, d. %li%ln", i, mpfr, i, lo, &ulo); check_length (2, ulo, 36, lu); check_vprintf ("a. %hi, b. %*f, c. %Re%hn", ush, 3, f, mpfr, &ush); check_length (3, ush, 29, hu); check_vprintf ("a. %hi, b. %f, c. %#.2Rf%n", sh, d, mpfr, &i); check_length (4, i, 29, d); check_vprintf ("a. %R*A, b. %Fe, c. %i%zn", rnd, mpfr, mpf, sz, &sz); check_length (5, (unsigned long) sz, 34, lu); /* no format specifier '%zu' in C89 */ check_vprintf ("a. %Pu, b. %c, c. %RUG, d. %Zi%Zn", prec, ch, mpfr, mpz, &mpz); check_length_with_cmp (6, mpz, 24, mpz_cmp_ui (mpz, 24), Zi); check_vprintf ("%% a. %#.0RNg, b. %Qx%Rn c. %p", mpfr, mpq, &mpfr, (void *) &i); check_length_with_cmp (7, mpfr, 15, mpfr_cmp_ui (mpfr, 15), Rg); #ifndef NPRINTF_T saved_p = p; check_vprintf ("%% a. %RNg, b. %Qx, c. %td%tn", mpfr, mpq, p, &p); if (p != 20) mpfr_fprintf (stderr, "Error in test 8, got '%% a. %RNg, b. %Qx, c. %td'\n", mpfr, mpq, saved_p); check_length (8, (long) p, 20, ld); /* no format specifier '%td' in C89 */ #endif #ifndef NPRINTF_L check_vprintf ("a. %RA, b. %Lf, c. %QX%zn", mpfr, ld, mpq, &sz); check_length (9, (unsigned long) sz, 30, lu); /* no format specifier '%zu' in C89 */ #endif #ifndef NPRINTF_HH check_vprintf ("a. %hhi, b. %Ra, c. %hhu%hhn", sch, mpfr, uch, &uch); check_length (10, (unsigned int) uch, 22, u); /* no format specifier '%hhu' in C89 */ #endif #if defined(HAVE_LONG_LONG) && !defined(NPRINTF_LL) { long long llo = -1; unsigned long long ullo = 1; check_vprintf ("a. %Re, b. %llx%Qn", mpfr, ullo, &mpq); check_length_with_cmp (11, mpq, 16, mpq_cmp_ui (mpq, 16, 1), Qu); check_vprintf ("a. %lli, b. %Rf%lln", llo, mpfr, &ullo); check_length (12, ullo, 19, llu); } #endif #if defined(_MPFR_H_HAVE_INTMAX_T) && !defined(NPRINTF_J) { intmax_t im = -1; uintmax_t uim = 1; check_vprintf ("a. %*RA, b. %ji%Fn", 10, mpfr, im, &mpf); check_length_with_cmp (31, mpf, 20, mpf_cmp_ui (mpf, 20), Fg); check_vprintf ("a. %.*Re, b. %jx%jn", 10, mpfr, uim, &im); check_length (32, (long) im, 25, li); /* no format specifier "%ji" in C89 */ } #endif mpfr_clear (mpfr); mpf_clear (mpf); mpq_clear (mpq); mpz_clear (mpz); } static void check_random (int nb_tests) { int i; mpfr_t x; mpfr_rnd_t rnd; char flag[] = { '-', '+', ' ', '#', '0', /* no ambiguity: first zeros are flag zero*/ '\'' }; char specifier[] = { 'a', 'b', 'e', 'f', 'g' }; mpfr_exp_t old_emin, old_emax; old_emin = mpfr_get_emin (); old_emax = mpfr_get_emax (); mpfr_init (x); for (i = 0; i < nb_tests; ++i) { int ret; int j, jmax; int spec, prec; #define FMT_SIZE 13 char fmt[FMT_SIZE]; /* at most something like "%-+ #0'.*R*f" */ char *ptr = fmt; tests_default_random (x, 256, MPFR_EMIN_MIN, MPFR_EMAX_MAX); rnd = (mpfr_rnd_t) RND_RAND (); spec = (int) (randlimb () % 5); jmax = (spec == 3 || spec == 4) ? 6 : 5; /* ' flag only with %f or %g */ /* advantage small precision */ prec = (randlimb () % 2) ? 10 : prec_max_printf; prec = (int) (randlimb () % prec); if (spec == 3 && (mpfr_get_exp (x) > prec_max_printf || mpfr_get_exp (x) < -prec_max_printf)) /* change style 'f' to style 'e' when number x is very large or very small*/ --spec; *ptr++ = '%'; for (j = 0; j < jmax; j++) { if (randlimb () % 3 == 0) *ptr++ = flag[j]; } *ptr++ = '.'; *ptr++ = '*'; *ptr++ = 'R'; *ptr++ = '*'; *ptr++ = specifier[spec]; *ptr = '\0'; MPFR_ASSERTD (ptr - fmt < FMT_SIZE); mpfr_printf ("mpfr_printf(\"%s\", %d, %s, %Re)\n", fmt, prec, mpfr_print_rnd_mode (rnd), x); ret = mpfr_printf (fmt, prec, rnd, x); if (ret == -1) { if (spec == 3 && (MPFR_GET_EXP (x) > INT_MAX || MPFR_GET_EXP (x) < -INT_MAX)) /* normal failure: x is too large to be output with full precision */ { mpfr_printf ("too large !"); } else { printf ("Error in mpfr_printf(\"%s\", %d, %s, ...)", fmt, prec, mpfr_print_rnd_mode (rnd)); if (stdout_redirect) { if ((fflush (stdout) == EOF) || (fclose (stdout) == -1)) { perror ("check_random"); exit (1); } } exit (1); } } putchar ('\n'); } mpfr_set_emin (old_emin); mpfr_set_emax (old_emax); mpfr_clear (x); } int main (int argc, char *argv[]) { int N; tests_start_mpfr (); /* with no argument: prints to /dev/null, tprintf N: prints N tests to stdout */ if (argc == 1) { N = 1000; stdout_redirect = 1; if (freopen ("/dev/null", "w", stdout) == NULL) { /* We failed to open this device, try with a dummy file */ if (freopen ("mpfrtest.txt", "w", stdout) == NULL) { /* Output the error message to stderr since it is not a message about a wrong result in MPFR. Anyway the stdandard output may have changed. */ fprintf (stderr, "Can't open /dev/null or a temporary file\n"); exit (1); } } } else { stdout_redirect = 0; N = atoi (argv[1]); } check_invalid_format (); check_special (); check_mixed (); /* expensive tests */ if (getenv ("MPFR_CHECK_LARGEMEM") != NULL) check_long_string(); check_random (N); if (stdout_redirect) { if ((fflush (stdout) == EOF) || (fclose (stdout) == -1)) perror ("main"); } tests_end_mpfr (); return 0; } #else /* MPFR_VERSION */ int main (void) { printf ("Warning! Test disabled for this MPFR version.\n"); return 0; } #endif /* MPFR_VERSION */ #else /* HAVE_STDARG */ int main (void) { /* We have nothing to test. */ return 77; } #endif /* HAVE_STDARG */
the_stack_data/87638941.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int expression) { if (!expression) { ERROR: /* assert not proved */ /* assert not proved */ __VERIFIER_error(); }; return; } int __global_lock; void __VERIFIER_atomic_begin() { /* reachable */ /* reachable */ /* reachable */ /* reachable */ /* reachable */ /* reachable */ __VERIFIER_assume(__global_lock==0); __global_lock=1; return; } void __VERIFIER_atomic_end() { __VERIFIER_assume(__global_lock==1); __global_lock=0; return; } #include <assert.h> #include <pthread.h> #ifndef TRUE #define TRUE (_Bool)1 #endif #ifndef FALSE #define FALSE (_Bool)0 #endif #ifndef NULL #define NULL ((void*)0) #endif #ifndef FENCE #define FENCE(x) ((void)0) #endif #ifndef IEEE_FLOAT_EQUAL #define IEEE_FLOAT_EQUAL(x,y) (x==y) #endif #ifndef IEEE_FLOAT_NOTEQUAL #define IEEE_FLOAT_NOTEQUAL(x,y) (x!=y) #endif void * P0(void *arg); void * P1(void *arg); void * P2(void *arg); void fence(); void isync(); void lwfence(); int __unbuffered_cnt; int __unbuffered_cnt = 0; int __unbuffered_p0_EAX; int __unbuffered_p0_EAX = 0; int __unbuffered_p1_EAX; int __unbuffered_p1_EAX = 0; int __unbuffered_p2_EAX; int __unbuffered_p2_EAX = 0; _Bool __unbuffered_p2_EAX$flush_delayed; int __unbuffered_p2_EAX$mem_tmp; _Bool __unbuffered_p2_EAX$r_buff0_thd0; _Bool __unbuffered_p2_EAX$r_buff0_thd1; _Bool __unbuffered_p2_EAX$r_buff0_thd2; _Bool __unbuffered_p2_EAX$r_buff0_thd3; _Bool __unbuffered_p2_EAX$r_buff1_thd0; _Bool __unbuffered_p2_EAX$r_buff1_thd1; _Bool __unbuffered_p2_EAX$r_buff1_thd2; _Bool __unbuffered_p2_EAX$r_buff1_thd3; _Bool __unbuffered_p2_EAX$read_delayed; int *__unbuffered_p2_EAX$read_delayed_var; int __unbuffered_p2_EAX$w_buff0; _Bool __unbuffered_p2_EAX$w_buff0_used; int __unbuffered_p2_EAX$w_buff1; _Bool __unbuffered_p2_EAX$w_buff1_used; _Bool main$tmp_guard0; _Bool main$tmp_guard1; int x; int x = 0; int y; int y = 0; _Bool y$flush_delayed; int y$mem_tmp; _Bool y$r_buff0_thd0; _Bool y$r_buff0_thd1; _Bool y$r_buff0_thd2; _Bool y$r_buff0_thd3; _Bool y$r_buff1_thd0; _Bool y$r_buff1_thd1; _Bool y$r_buff1_thd2; _Bool y$r_buff1_thd3; _Bool y$read_delayed; int *y$read_delayed_var; int y$w_buff0; _Bool y$w_buff0_used; int y$w_buff1; _Bool y$w_buff1_used; int z; int z = 0; _Bool weak$$choice0; _Bool weak$$choice1; _Bool weak$$choice2; void * P0(void *arg) { __VERIFIER_atomic_begin(); __unbuffered_p0_EAX = z; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); x = 1; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); __unbuffered_cnt = __unbuffered_cnt + 1; __VERIFIER_atomic_end(); return nondet_0(); } void * P1(void *arg) { __VERIFIER_atomic_begin(); __unbuffered_p1_EAX = x; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); y$w_buff1 = y$w_buff0; y$w_buff0 = 1; y$w_buff1_used = y$w_buff0_used; y$w_buff0_used = TRUE; __VERIFIER_assert(!(y$w_buff1_used && y$w_buff0_used)); y$r_buff1_thd0 = y$r_buff0_thd0; y$r_buff1_thd1 = y$r_buff0_thd1; y$r_buff1_thd2 = y$r_buff0_thd2; y$r_buff1_thd3 = y$r_buff0_thd3; y$r_buff0_thd2 = TRUE; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); y = y$w_buff0_used && y$r_buff0_thd2 ? y$w_buff0 : (y$w_buff1_used && y$r_buff1_thd2 ? y$w_buff1 : y); y$w_buff0_used = y$w_buff0_used && y$r_buff0_thd2 ? FALSE : y$w_buff0_used; y$w_buff1_used = y$w_buff0_used && y$r_buff0_thd2 || y$w_buff1_used && y$r_buff1_thd2 ? FALSE : y$w_buff1_used; y$r_buff0_thd2 = y$w_buff0_used && y$r_buff0_thd2 ? FALSE : y$r_buff0_thd2; y$r_buff1_thd2 = y$w_buff0_used && y$r_buff0_thd2 || y$w_buff1_used && y$r_buff1_thd2 ? FALSE : y$r_buff1_thd2; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); __unbuffered_cnt = __unbuffered_cnt + 1; __VERIFIER_atomic_end(); return nondet_0(); } void * P2(void *arg) { __VERIFIER_atomic_begin(); weak$$choice0 = nondet_1(); weak$$choice2 = nondet_1(); y$flush_delayed = weak$$choice2; y$mem_tmp = y; weak$$choice1 = nondet_1(); y = !y$w_buff0_used ? y : (y$w_buff0_used && y$r_buff0_thd3 ? y$w_buff0 : (y$w_buff0_used && !y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? (weak$$choice0 ? y : (weak$$choice1 ? y$w_buff0 : y$w_buff1)) : (y$w_buff0_used && y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? (weak$$choice0 ? y$w_buff1 : y$w_buff0) : (weak$$choice0 ? y$w_buff0 : y)))); y$w_buff0 = weak$$choice2 ? y$w_buff0 : (!y$w_buff0_used ? y$w_buff0 : (y$w_buff0_used && y$r_buff0_thd3 ? y$w_buff0 : (y$w_buff0_used && !y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? y$w_buff0 : (y$w_buff0_used && y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? y$w_buff0 : y$w_buff0)))); y$w_buff1 = weak$$choice2 ? y$w_buff1 : (!y$w_buff0_used ? y$w_buff1 : (y$w_buff0_used && y$r_buff0_thd3 ? y$w_buff1 : (y$w_buff0_used && !y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? y$w_buff1 : (y$w_buff0_used && y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? y$w_buff1 : y$w_buff1)))); y$w_buff0_used = weak$$choice2 ? y$w_buff0_used : (!y$w_buff0_used ? y$w_buff0_used : (y$w_buff0_used && y$r_buff0_thd3 ? FALSE : (y$w_buff0_used && !y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? weak$$choice0 || !weak$$choice1 : (y$w_buff0_used && y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? weak$$choice0 : weak$$choice0)))); y$w_buff1_used = weak$$choice2 ? y$w_buff1_used : (!y$w_buff0_used ? y$w_buff1_used : (y$w_buff0_used && y$r_buff0_thd3 ? FALSE : (y$w_buff0_used && !y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? weak$$choice0 : (y$w_buff0_used && y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? FALSE : FALSE)))); y$r_buff0_thd3 = weak$$choice2 ? y$r_buff0_thd3 : (!y$w_buff0_used ? y$r_buff0_thd3 : (y$w_buff0_used && y$r_buff0_thd3 ? FALSE : (y$w_buff0_used && !y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? y$r_buff0_thd3 : (y$w_buff0_used && y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? FALSE : FALSE)))); y$r_buff1_thd3 = weak$$choice2 ? y$r_buff1_thd3 : (!y$w_buff0_used ? y$r_buff1_thd3 : (y$w_buff0_used && y$r_buff0_thd3 ? FALSE : (y$w_buff0_used && !y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? (weak$$choice0 ? y$r_buff1_thd3 : FALSE) : (y$w_buff0_used && y$r_buff1_thd3 && y$w_buff1_used && !y$r_buff0_thd3 ? FALSE : FALSE)))); __unbuffered_p2_EAX$read_delayed = TRUE; __unbuffered_p2_EAX$read_delayed_var = &y; __unbuffered_p2_EAX = y; y = y$flush_delayed ? y$mem_tmp : y; y$flush_delayed = FALSE; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); z = 1; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); y = y$w_buff0_used && y$r_buff0_thd3 ? y$w_buff0 : (y$w_buff1_used && y$r_buff1_thd3 ? y$w_buff1 : y); y$w_buff0_used = y$w_buff0_used && y$r_buff0_thd3 ? FALSE : y$w_buff0_used; y$w_buff1_used = y$w_buff0_used && y$r_buff0_thd3 || y$w_buff1_used && y$r_buff1_thd3 ? FALSE : y$w_buff1_used; y$r_buff0_thd3 = y$w_buff0_used && y$r_buff0_thd3 ? FALSE : y$r_buff0_thd3; y$r_buff1_thd3 = y$w_buff0_used && y$r_buff0_thd3 || y$w_buff1_used && y$r_buff1_thd3 ? FALSE : y$r_buff1_thd3; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); __unbuffered_cnt = __unbuffered_cnt + 1; __VERIFIER_atomic_end(); return nondet_0(); } void fence() { } void isync() { } void lwfence() { } int main() { pthread_create(NULL, NULL, P0, NULL); pthread_create(NULL, NULL, P1, NULL); pthread_create(NULL, NULL, P2, NULL); __VERIFIER_atomic_begin(); main$tmp_guard0 = __unbuffered_cnt == 3; __VERIFIER_atomic_end(); __VERIFIER_assume(main$tmp_guard0); __VERIFIER_atomic_begin(); y = y$w_buff0_used && y$r_buff0_thd0 ? y$w_buff0 : (y$w_buff1_used && y$r_buff1_thd0 ? y$w_buff1 : y); y$w_buff0_used = y$w_buff0_used && y$r_buff0_thd0 ? FALSE : y$w_buff0_used; y$w_buff1_used = y$w_buff0_used && y$r_buff0_thd0 || y$w_buff1_used && y$r_buff1_thd0 ? FALSE : y$w_buff1_used; y$r_buff0_thd0 = y$w_buff0_used && y$r_buff0_thd0 ? FALSE : y$r_buff0_thd0; y$r_buff1_thd0 = y$w_buff0_used && y$r_buff0_thd0 || y$w_buff1_used && y$r_buff1_thd0 ? FALSE : y$r_buff1_thd0; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); /* Program was expected to be safe for X86, model checker should have said NO. This likely is a bug in the tool chain. */ weak$$choice1 = nondet_1(); /* Program was expected to be safe for X86, model checker should have said NO. This likely is a bug in the tool chain. */ __unbuffered_p2_EAX = __unbuffered_p2_EAX$read_delayed ? (weak$$choice1 ? *__unbuffered_p2_EAX$read_delayed_var : __unbuffered_p2_EAX) : __unbuffered_p2_EAX; /* Program was expected to be safe for X86, model checker should have said NO. This likely is a bug in the tool chain. */ main$tmp_guard1 = !(__unbuffered_p0_EAX == 1 && __unbuffered_p1_EAX == 1 && __unbuffered_p2_EAX == 1); __VERIFIER_atomic_end(); /* Program was expected to be safe for X86, model checker should have said NO. This likely is a bug in the tool chain. */ __VERIFIER_assert(main$tmp_guard1); /* reachable */ return 0; }
the_stack_data/5661.c
/* * test.c * * Created on: Feb 27, 2011 * Author: anallyst * * set -DDEBUG when compiling List.c * to check access on non-initialized lists * gcc -Wall -DDEBUG -DNO_RAM_DEBUGGER -I.. -I../gamelib -g -O0 List_unittest.c List.c -o list_unittest */ #ifdef LIST_UNITTEST #include "List.h" #include <stdlib.h> #include <stdio.h> #include <assert.h> void* memlist[1024]; size_t memidx = 0; char* int2str (int i) { char * ret = malloc(32); sprintf(ret, "%d", i); memlist[memidx++] = ret; return ret; } void freemem() { size_t i; for (i = 0; i < memidx; i++) { free(memlist[i]); } } int eq (char* s1, char* s2) { return (strcmp(s1, s2) == 0); } int main() { List list, list2; size_t dummy = 0x1234; int i = 0; Node* test; List_Init(&list); assert(list.last == NULL); assert(list.first == NULL); assert(list.size == 0); assert(list.index == 0); List_InsertAfter(&list, (void*) dummy, int2str(++i)); assert(list.current == list.first); assert(list.current == list.last); assert(list.last != NULL); assert(list.first != NULL); assert(list.last->next == NULL); assert(list.first->prev == NULL); assert(list.size == i); assert(eq(list.current->name, "1")); List_InsertAfter(&list, (void*) dummy, int2str(++i)); assert(list.current->prev == list.first); assert(list.current == list.last); assert(list.last->next == NULL); assert(list.first->prev == NULL); assert(list.size == i); assert(eq(list.current->name, "2")); List_InsertAfter(&list, (void*) dummy, int2str(++i)); assert(list.current->prev->prev == list.first); assert(list.current == list.last); assert(list.last->next == NULL); assert(list.first->prev == NULL); assert(list.size == i); assert(eq(list.current->name, "3")); List_Remove(&list); assert(list.current->prev == list.first); assert(list.current == list.last); assert(list.last->next == NULL); assert(list.first->prev == NULL); assert(list.size == i - 1); assert(eq(list.current->name, "2")); List_InsertBefore(&list, (void*) dummy, int2str(++i)); assert(list.current != list.last); assert(list.current->next == list.last); assert(list.last->next == NULL); assert(list.first->prev == NULL); assert(list.size == i - 1); assert(eq(list.current->name, "4")); assert(eq(list.last->name, "2")); List_GotoFirst(&list); List_InsertBefore(&list, (void*) dummy, int2str(++i)); assert(list.current == list.first); assert(list.last->next == NULL); assert(list.first->prev == NULL); assert(list.size == i - 1); assert(eq(list.current->name, "5")); assert(eq(list.last->name, "2")); List_InsertAfter(&list, (void*) dummy, int2str(++i)); assert(list.current == list.first->next); assert(list.current->prev == list.first); assert(list.current->next->prev == list.current); assert(list.last->next == NULL); assert(list.first->prev == NULL); assert(list.size == i - 1); assert(eq(list.current->name, "6")); assert(eq(list.last->name, "2")); List_GotoFirst(&list); assert(list.current == list.first); test = list.first->next; List_Remove(&list); assert(list.first == test); assert(list.current == list.first); assert(list.last->next == NULL); assert(list.first->prev == NULL); assert(list.size == i - 2); //assert(eq(list.current->name, "7")); assert(eq(list.last->name, "2")); List_GotoFirst(&list); assert(list.current == list.first); List_Copy(&list2, &list); assert(list2.size == list.size); assert(list2.current == list2.first); assert(eq(list2.last->name, "2")); List_GotoLast(&list); assert(list.current == list.last); List_Copy(&list2, &list); assert(list2.current == list2.last); assert(list2.size == list.size); assert(list2.index == list.index); assert(list2.index == 0); assert(eq(list2.last->name, "2")); assert(eq(list2.last->name, list.last->name)); assert(eq(list2.first->name, list.first->name)); assert(eq(list2.current->name, list.current->name)); assert(eq(list2.current->prev->name, list.current->prev->name)); assert(list2.current->next == list.current->next); assert(list.current->next == 0); List_GotoFirst(&list); assert(!eq(list2.current->name, list.current->name)); List_GotoFirst(&list2); assert(eq(list2.current->name, list.current->name)); assert(list.current == list.first); assert(list.current->prev == NULL); assert(list2.current->prev == NULL); List_InsertAfter(&list, (void*) 0xDEADBEEF, int2str(++i)); assert(list.first->next->value == (void*) 0xDEADBEEF); assert(list.current = list.first->next); List_InsertAfter(&list, (void*) dummy, int2str(++i)); List_InsertBefore(&list, (void*) dummy, int2str(++i)); List_InsertBefore(&list, (void*) dummy, int2str(++i)); List_InsertBefore(&list, (void*) dummy, int2str(++i)); assert(list.size == i - 2); // i = 11 List_GotoFirst(&list); List_GotoNext(&list); List_GotoPrevious(&list); List_GotoLast(&list); test = list.last; assert(list.current == list.last); List_Remove(&list); assert(list.last != test); assert(list.current == list.last); List_Remove(&list); assert(list.current == list.last); List_Remove(&list); assert(list.current == list.last); List_Remove(&list); assert(list.current == list.last); assert(list.size == i - 6); List_GotoPrevious(&list); List_GotoPrevious(&list); List_GotoPrevious(&list); assert(List_Retrieve(&list) == (void*)0xDEADBEEF); List_Remove(&list); assert(!List_Includes(&list, (void*)0xDEADBEEF)); assert(list.size == i - 7); List_GotoLast(&list); List_InsertAfter(&list, (void*) 0xDEADBEEF, int2str(++i)); #ifdef USE_INDEX List_CreateIndices(&list); assert(list.mindices); assert(List_GetIndex(&list) == list.size -1); assert(List_GetNodeIndex(&list, list.first) == 0); assert(List_GetNodeIndex(&list, list.last->prev) == list.size -2); assert(List_GetNodeIndex(&list, list.last->prev->prev) == list.size -3); assert(list.mindices[ptrhash((void*)0xDEADBEEF)]); #endif assert(List_Includes(&list, (void*)0xDEADBEEF)); assert(list.current == list.last); assert(List_Retrieve(&list) == (void*)0xDEADBEEF); List_Update(&list, (void*)0xDEADC0DE); assert(list.current == list.last); assert(List_Retrieve(&list) == (void*)0xDEADC0DE); assert(!List_Includes(&list, (void*)0xDEADBEEF)); assert(List_Includes(&list, (void*)0xDEADC0DE)); #ifdef USE_INDEX assert(list.mindices); assert(list.mindices[ptrhash((void*)0xDEADC0DE)]); #endif List_Remove(&list); assert(!List_Includes(&list, (void*)0xDEADC0DE)); #ifdef USE_INDEX assert(list.mindices); assert(ptrhash((void*) dummy) != ptrhash((void*)0xDEADC0DE)); assert(ptrhash((void*) dummy) != ptrhash((void*)0xDEADBEEF)); // disable temporary assert(list.mindices[ptrhash((void*)0xDEADC0DE)]); assert(list.mindices[ptrhash((void*)0xDEADC0DE)]->nodes[0] == NULL); assert(list.mindices[ptrhash((void*)0xDEADC0DE)]->used ==0); // dead beef was updated, so used must be still 1 assert(list.mindices[ptrhash((void*)0xDEADBEEF)]); assert(list.mindices[ptrhash((void*)0xDEADBEEF)]->nodes[0] == NULL); assert(list.mindices[ptrhash((void*)0xDEADBEEF)]->used == 1); #endif List_Clear(&list); assert(list.size == 0); List_Init(&list); i = 0; List_InsertBefore(&list, (void*) dummy, int2str(++i)); List_InsertBefore(&list, (void*) dummy, int2str(++i)); List_InsertBefore(&list, (void*) dummy, int2str(++i)); assert(list.size == 3); List_Remove(&list); List_Remove(&list); List_Remove(&list); List_Remove(&list); List_GotoFirst(&list); List_Clear(&list); // testing the order of removal is equivalent to gotonext List_Init(&list); List_InsertAfter(&list, (void*) 1, NULL); List_InsertAfter(&list, (void*) 2, NULL); List_InsertAfter(&list, (void*) 3, NULL); List_InsertAfter(&list, (void*) 4, NULL); List_GotoFirst(&list); assert(list.current->value == (void*) 1); List_GotoNext(&list); assert(list.current->value == (void*) 2); List_GotoNext(&list); assert(list.current->value == (void*) 3); List_GotoNext(&list); assert(list.current->value == (void*) 4); assert(list.current == list.last); List_GotoFirst(&list); assert(list.current->value == (void*) 1); List_Remove(&list); assert(list.current->value == (void*) 2); List_Remove(&list); assert(list.current->value == (void*) 3); List_Remove(&list); assert(list.current->value == (void*) 4); assert(list.current == list.last); List_Remove(&list); assert(list.current == list.last); assert(list.current == list.first); assert(list.current == NULL); freemem(); return 0; } #endif
the_stack_data/865955.c
#include <stdio.h> int main() { int a,b; int x[5],u,y,o; for(a=0;a<5;a++) { scanf("%d",&x[a]); } for(a=0;a<5;a++) { printf("%d ",x[a]); printf("\n"); } printf("\n\ntell index of the no. starting from 0 which element to delete\n\n"); scanf("%d",&o); if(o<4) { for(a=o;a<5;a++) { if(o>4) break; x[o] = x[++o]; } } else if (o>=4) { x[o] = 0; } x[4] = 0; for(a=0;a<5;a++) { printf("%d ",x[a]); printf("\n"); } system("pause"); }
the_stack_data/119043.c
/* * A test program for playing with SELinux contexts and permissions * * Based on a simple premise of a native C binary, that reads one config file and writes an output file * * Credits for code: * https://gsamaras.wordpress.com/code/eat-spaces-and-newline-c/ * https://www.pacificsimplicity.ca/blog/simple-read-configuration-file-struct-example * http://www.cprogramming.com/tutorial/c/lesson14.html * https://cboard.cprogramming.com/c-programming/155124-using-c-program-append-text-txt-file.html * https://stackoverflow.com/questions/24249369/how-to-write-pid-to-file-on-unix * https://www.gnu.org/software/libc/manual/html_node/Syslog-Example.html */ #include <stdio.h> #include <sys/io.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <syslog.h> char s[11] = {"\nabcdefghij"}; #define FILENAME "testprog.conf" #define MAXBUF 1024 #define DELIM "=" #define PIDFILE "/var/run/testprog.pid" struct config { char outputfile[MAXBUF]; char loopcount[MAXBUF]; }; struct config get_config(char *filename) { struct config configstruct; FILE *file = fopen (filename, "r"); if (file != NULL) { char line[MAXBUF]; int i = 0; while(fgets(line, sizeof(line), file) != NULL) { char *cfline; cfline = strstr((char *)line,DELIM); cfline = cfline + strlen(DELIM); if (i == 0){ memcpy(configstruct.outputfile,cfline,strlen(cfline)); //printf("%s",configstruct.outputfile); } else if (i == 1){ memcpy(configstruct.loopcount,cfline,strlen(cfline)); //printf("%s",configstruct.loopcount); } i++; } // End while } // End if file fclose(file); return configstruct; } int main(int argc, char *argv[] ) { struct config configstruct; setlogmask (LOG_UPTO (LOG_NOTICE)); openlog ("testprog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); if (argc < 2) { // No arguments were passed configstruct = get_config(FILENAME); printf("Using configuration file: %s\n", FILENAME); syslog (LOG_NOTICE, "Using configuration file: %s\n", FILENAME); // We assume argv[2] is a pidfile to open FILE *file = fopen( PIDFILE, "wb" ); fprintf(file, "%d\n", getpid()); fclose(file); printf("Wrote PID to %s\n", PIDFILE ); syslog (LOG_NOTICE, "Wrote PID to %s\n", PIDFILE ); } else { // We assume argv[1] is a config file to open FILE *file = fopen( argv[1], "r" ); /* fopen returns 0, the NULL pointer, on failure */ if ( file == 0 ) { printf( "Could not open file\n" ); syslog (LOG_CRIT, "Could not open file\n" ); } else { configstruct = get_config(argv[1]); printf("Using configuration file: %s\n", argv[1]); syslog (LOG_NOTICE, "Using configuration file: %s\n", argv[1]); } fclose(file); // We assume argv[2] is a pidfile to open FILE *pidfile = fopen( argv[2], "wb" ); fprintf(pidfile, "%d\n", getpid()); fclose(pidfile); printf("Wrote PID to %s\n", argv[2] ); syslog (LOG_NOTICE, "Wrote PID to %s\n", argv[2] ); } /* Code to trim our string and prevent bad chars in filename */ char* outputfilePtr = configstruct.outputfile; size_t len; outputfilePtr += strspn(outputfilePtr, "\t\n\v\f\r "); len = strcspn(configstruct.outputfile, "\r\n"); configstruct.outputfile[len] = '\0'; printf("Writing output to: %s\n",configstruct.outputfile); syslog (LOG_NOTICE, "Writing output to: %s\n",configstruct.outputfile); /* Cast port as int */ int x; x = atoi(configstruct.loopcount); printf("Iteration count: %d\n",x); syslog (LOG_NOTICE, "Iteration count: %d\n",x); int i = 0; while(i < x || x < 0) { FILE *file = fopen(configstruct.outputfile, "a"); fputs("\nHello World",file); fputs(s,file); fclose(file); sleep(1); i++; } return 0; }
the_stack_data/242331695.c
/* BAR_M.C Map Source File. Info: Section : Bank : 0 Map size : 20 x 18 Tile set : C:\SDK\gb-gb\tmp\bar_c.gbr Plane count : 1 plane (8 bits) Plane order : Tiles are continues This file was generated by GBMB v0.8 */ #define bar_mWidth 20 #define bar_mHeight 18 const unsigned char bar_m[] = { 0x1F,0x1F,0x12,0x12,0x12,0x1B,0x1B,0x1B,0x08,0x08, 0x08,0x16,0x16,0x16,0x07,0x07,0x07,0x0C,0x0C,0x0C, 0x1E,0x1E,0x13,0x13,0x13,0x18,0x18,0x18,0x09,0x09, 0x09,0x17,0x17,0x17,0x04,0x04,0x04,0x0D,0x0D,0x0D, 0x1D,0x1D,0x10,0x10,0x10,0x19,0x19,0x19,0x0A,0x0A, 0x0A,0x14,0x14,0x14,0x05,0x05,0x05,0x0E,0x0E,0x0E, 0x1C,0x1C,0x11,0x11,0x11,0x1A,0x1A,0x1A,0x0B,0x0B, 0x0B,0x15,0x15,0x15,0x06,0x06,0x06,0x0F,0x0F,0x0F, 0x1C,0x1C,0x11,0x11,0x11,0x1A,0x1A,0x1A,0x0B,0x0B, 0x0B,0x15,0x15,0x15,0x06,0x06,0x06,0x0F,0x0F,0x0F, 0x1C,0x1C,0x11,0x11,0x11,0x1A,0x1A,0x1A,0x0B,0x0B, 0x0B,0x15,0x15,0x15,0x06,0x06,0x06,0x0F,0x0F,0x0F, 0x1C,0x1C,0x11,0x11,0x11,0x1A,0x1A,0x1A,0x0B,0x0B, 0x0B,0x15,0x15,0x15,0x06,0x06,0x06,0x0F,0x0F,0x0F, 0x1C,0x1C,0x11,0x11,0x11,0x1A,0x1A,0x1A,0x0B,0x0B, 0x0B,0x15,0x15,0x15,0x06,0x06,0x06,0x0F,0x0F,0x0F, 0x1C,0x1C,0x11,0x11,0x11,0x1A,0x1A,0x1A,0x0B,0x0B, 0x0B,0x15,0x15,0x15,0x06,0x06,0x06,0x0F,0x0F,0x0F, 0x1C,0x1C,0x11,0x11,0x11,0x1A,0x1A,0x1A,0x0B,0x0B, 0x0B,0x15,0x15,0x15,0x06,0x06,0x06,0x0F,0x0F,0x0F, 0x1C,0x1C,0x11,0x11,0x11,0x1A,0x1A,0x1A,0x0B,0x0B, 0x0B,0x15,0x15,0x15,0x06,0x06,0x06,0x0F,0x0F,0x0F, 0x1C,0x1C,0x11,0x11,0x11,0x1A,0x1A,0x1A,0x0B,0x0B, 0x0B,0x15,0x15,0x15,0x06,0x06,0x06,0x0F,0x0F,0x0F, 0x1C,0x1C,0x11,0x11,0x11,0x1A,0x1A,0x1A,0x0B,0x0B, 0x0B,0x15,0x15,0x15,0x06,0x06,0x06,0x0F,0x0F,0x0F, 0x1C,0x1C,0x11,0x11,0x11,0x1A,0x1A,0x1A,0x0B,0x0B, 0x0B,0x15,0x15,0x15,0x06,0x06,0x06,0x0F,0x0F,0x0F, 0x0F,0x0F,0x03,0x03,0x03,0x15,0x15,0x15,0x03,0x03, 0x03,0x1A,0x1A,0x1A,0x03,0x03,0x03,0x1C,0x1C,0x1C, 0x0D,0x0D,0x0D,0x0D,0x00,0x00,0x00,0x00,0x16,0x16, 0x16,0x16,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, 0x0D,0x0D,0x0D,0x0D,0x00,0x00,0x00,0x00,0x16,0x16, 0x16,0x16,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, 0x0D,0x0D,0x0D,0x0D,0x00,0x00,0x00,0x00,0x16,0x16, 0x16,0x16,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, }; /* End of BAR_M.C */
the_stack_data/159516197.c
void kernel_heat_3d(int tsteps, int n, double A[ 120 + 0][120 + 0][120 + 0], double B[ 120 + 0][120 + 0][120 + 0]) { int t, i, j, k; #pragma clang loop(i1, j1, k1) tile sizes(32, 64, 64) for (t = 1; t <= 500; t++) { #pragma clang loop id(i1) for (i = 1; i < n-1; i++) { #pragma clang loop id(j1) for (j = 1; j < n-1; j++) { #pragma clang loop id(k1) for (k = 1; k < n-1; k++) { B[i][j][k] = 0.125 * (A[i+1][j][k] - 2.0 * A[i][j][k] + A[i-1][j][k]) + 0.125 * (A[i][j+1][k] - 2.0 * A[i][j][k] + A[i][j-1][k]) + 0.125 * (A[i][j][k+1] - 2.0 * A[i][j][k] + A[i][j][k-1]) + A[i][j][k]; } } } #pragma clang loop(i2, j2, k2) tile sizes(32, 64, 64) #pragma clang loop id(i2) for (i = 1; i < n-1; i++) { #pragma clang loop id(j2) for (j = 1; j < n-1; j++) { #pragma clang loop id(k2) for (k = 1; k < n-1; k++) { A[i][j][k] = 0.125 * (B[i+1][j][k] - 2.0 * B[i][j][k] + B[i-1][j][k]) + 0.125 * (B[i][j+1][k] - 2.0 * B[i][j][k] + B[i][j-1][k]) + 0.125 * (B[i][j][k+1] - 2.0 * B[i][j][k] + B[i][j][k-1]) + B[i][j][k]; } } } } }
the_stack_data/97012271.c
/* $OpenBSD: col.c,v 1.5 1997/07/25 21:30:12 mickey Exp $ */ /* $NetBSD: col.c,v 1.7 1995/09/02 05:48:50 jtc Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Michael Rendell of the Memorial University of Newfoundland. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1990, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)col.c 8.5 (Berkeley) 5/4/95"; #endif static char rcsid[] = "$OpenBSD: col.c,v 1.5 1997/07/25 21:30:12 mickey Exp $"; #endif /* not lint */ #include <ctype.h> #include <err.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #define BS '\b' /* backspace */ #define TAB '\t' /* tab */ #define SPACE ' ' /* space */ #define NL '\n' /* newline */ #define CR '\r' /* carriage return */ #define ESC '\033' /* escape */ #define SI '\017' /* shift in to normal character set */ #define SO '\016' /* shift out to alternate character set */ #define VT '\013' /* vertical tab (aka reverse line feed) */ #define RLF '\007' /* ESC-07 reverse line feed */ #define RHLF '\010' /* ESC-010 reverse half-line feed */ #define FHLF '\011' /* ESC-011 forward half-line feed */ /* build up at least this many lines before flushing them out */ #define BUFFER_MARGIN 32 typedef char CSET; typedef struct char_str { #define CS_NORMAL 1 #define CS_ALTERNATE 2 short c_column; /* column character is in */ CSET c_set; /* character set (currently only 2) */ char c_char; /* character in question */ } CHAR; typedef struct line_str LINE; struct line_str { CHAR *l_line; /* characters on the line */ LINE *l_prev; /* previous line */ LINE *l_next; /* next line */ int l_lsize; /* allocated sizeof l_line */ int l_line_len; /* strlen(l_line) */ int l_needs_sort; /* set if chars went in out of order */ int l_max_col; /* max column in the line */ }; LINE *alloc_line __P((void)); void dowarn __P((int)); void flush_line __P((LINE *)); void flush_lines __P((int)); void flush_blanks __P((void)); void free_line __P((LINE *)); void usage __P((void)); void *xmalloc __P((void *, size_t)); CSET last_set; /* char_set of last char printed */ LINE *lines; int compress_spaces; /* if doing space -> tab conversion */ int fine; /* if `fine' resolution (half lines) */ int max_bufd_lines; /* max # lines to keep in memory */ int nblank_lines; /* # blanks after last flushed line */ int no_backspaces; /* if not to output any backspaces */ #define PUTC(ch) \ if (putchar(ch) == EOF) \ err(1, "stdout"); int main(argc, argv) int argc; char **argv; { int ch; CHAR *c; CSET cur_set; /* current character set */ LINE *l; /* current line */ int extra_lines; /* # of lines above first line */ int cur_col; /* current column */ int cur_line; /* line number of current position */ int max_line; /* max value of cur_line */ int this_line; /* line l points to */ int nflushd_lines; /* number of lines that were flushed */ int adjust, opt, warned; max_bufd_lines = 128; compress_spaces = 1; /* compress spaces into tabs */ while ((opt = getopt(argc, argv, "bfhl:x")) != -1) switch (opt) { case 'b': /* do not output backspaces */ no_backspaces = 1; break; case 'f': /* allow half forward line feeds */ fine = 1; break; case 'h': /* compress spaces into tabs */ compress_spaces = 1; break; case 'l': /* buffered line count */ if ((max_bufd_lines = atoi(optarg)) <= 0) { (void)fprintf(stderr, "col: bad -l argument %s.\n", optarg); exit(1); } break; case 'x': /* do not compress spaces into tabs */ compress_spaces = 0; break; case '?': default: usage(); } if (optind != argc) usage(); /* this value is in half lines */ max_bufd_lines *= 2; adjust = cur_col = extra_lines = warned = 0; cur_line = max_line = nflushd_lines = this_line = 0; cur_set = last_set = CS_NORMAL; lines = l = alloc_line(); while ((ch = getchar()) != EOF) { if (!isgraph(ch)) { switch (ch) { case BS: /* can't go back further */ if (cur_col == 0) continue; --cur_col; continue; case CR: cur_col = 0; continue; case ESC: /* just ignore EOF */ switch(getchar()) { case RLF: cur_line -= 2; break; case RHLF: cur_line--; break; case FHLF: cur_line++; if (cur_line > max_line) max_line = cur_line; } continue; case NL: cur_line += 2; if (cur_line > max_line) max_line = cur_line; cur_col = 0; continue; case SPACE: ++cur_col; continue; case SI: cur_set = CS_NORMAL; continue; case SO: cur_set = CS_ALTERNATE; continue; case TAB: /* adjust column */ cur_col |= 7; ++cur_col; continue; case VT: cur_line -= 2; continue; } continue; } /* Must stuff ch in a line - are we at the right one? */ if (cur_line != this_line - adjust) { LINE *lnew; int nmove; adjust = 0; nmove = cur_line - this_line; if (!fine) { /* round up to next line */ if (cur_line & 1) { adjust = 1; nmove++; } } if (nmove < 0) { for (; nmove < 0 && l->l_prev; nmove++) l = l->l_prev; if (nmove) { if (nflushd_lines == 0) { /* * Allow backup past first * line if nothing has been * flushed yet. */ for (; nmove < 0; nmove++) { lnew = alloc_line(); l->l_prev = lnew; lnew->l_next = l; l = lines = lnew; extra_lines++; } } else { if (!warned++) dowarn(cur_line); cur_line -= nmove; } } } else { /* may need to allocate here */ for (; nmove > 0 && l->l_next; nmove--) l = l->l_next; for (; nmove > 0; nmove--) { lnew = alloc_line(); lnew->l_prev = l; l->l_next = lnew; l = lnew; } } this_line = cur_line + adjust; nmove = this_line - nflushd_lines; if (nmove >= max_bufd_lines + BUFFER_MARGIN) { nflushd_lines += nmove - max_bufd_lines; flush_lines(nmove - max_bufd_lines); } } /* grow line's buffer? */ if (l->l_line_len + 1 >= l->l_lsize) { int need; need = l->l_lsize ? l->l_lsize * 2 : 90; l->l_line = (CHAR *)xmalloc((void *) l->l_line, (unsigned) need * sizeof(CHAR)); l->l_lsize = need; } c = &l->l_line[l->l_line_len++]; c->c_char = ch; c->c_set = cur_set; c->c_column = cur_col; /* * If things are put in out of order, they will need sorting * when it is flushed. */ if (cur_col < l->l_max_col) l->l_needs_sort = 1; else l->l_max_col = cur_col; cur_col++; } if (max_line == 0) exit(0); /* no lines, so just exit */ /* goto the last line that had a character on it */ for (; l->l_next; l = l->l_next) this_line++; flush_lines(this_line - nflushd_lines + extra_lines + 1); /* make sure we leave things in a sane state */ if (last_set != CS_NORMAL) PUTC('\017'); /* flush out the last few blank lines */ nblank_lines = max_line - this_line; if (max_line & 1) nblank_lines++; else if (!nblank_lines) /* missing a \n on the last line? */ nblank_lines = 2; flush_blanks(); exit(0); } void flush_lines(nflush) int nflush; { LINE *l; while (--nflush >= 0) { l = lines; lines = l->l_next; if (l->l_line) { flush_blanks(); flush_line(l); } nblank_lines++; if (l->l_line) (void)free((void *)l->l_line); free_line(l); } if (lines) lines->l_prev = NULL; } /* * Print a number of newline/half newlines. If fine flag is set, nblank_lines * is the number of half line feeds, otherwise it is the number of whole line * feeds. */ void flush_blanks() { int half, i, nb; half = 0; nb = nblank_lines; if (nb & 1) { if (fine) half = 1; else nb++; } nb /= 2; for (i = nb; --i >= 0;) PUTC('\n'); if (half) { PUTC('\033'); PUTC('9'); if (!nb) PUTC('\r'); } nblank_lines = 0; } /* * Write a line to stdout taking care of space to tab conversion (-h flag) * and character set shifts. */ void flush_line(l) LINE *l; { CHAR *c, *endc; int nchars, last_col, this_col; last_col = 0; nchars = l->l_line_len; if (l->l_needs_sort) { static CHAR *sorted; static int count_size, *count, i, save, sorted_size, tot; /* * Do an O(n) sort on l->l_line by column being careful to * preserve the order of characters in the same column. */ if (l->l_lsize > sorted_size) { sorted_size = l->l_lsize; sorted = (CHAR *)xmalloc((void *)sorted, (unsigned)sizeof(CHAR) * sorted_size); } if (l->l_max_col >= count_size) { count_size = l->l_max_col + 1; count = (int *)xmalloc((void *)count, (unsigned)sizeof(int) * count_size); } memset((char *)count, 0, sizeof(int) * l->l_max_col + 1); for (i = nchars, c = l->l_line; --i >= 0; c++) count[c->c_column]++; /* * calculate running total (shifted down by 1) to use as * indices into new line. */ for (tot = 0, i = 0; i <= l->l_max_col; i++) { save = count[i]; count[i] = tot; tot += save; } for (i = nchars, c = l->l_line; --i >= 0; c++) sorted[count[c->c_column]++] = *c; c = sorted; } else c = l->l_line; while (nchars > 0) { this_col = c->c_column; endc = c; do { ++endc; } while (--nchars > 0 && this_col == endc->c_column); /* if -b only print last character */ if (no_backspaces) c = endc - 1; if (this_col > last_col) { int nspace = this_col - last_col; if (compress_spaces && nspace > 1) { int ntabs; ntabs = ((last_col % 8) + nspace) / 8; if (ntabs) { nspace -= (ntabs * 8) - (last_col % 8); while (--ntabs >= 0) PUTC('\t'); } } while (--nspace >= 0) PUTC(' '); last_col = this_col; } last_col++; for (;;) { if (c->c_set != last_set) { switch (c->c_set) { case CS_NORMAL: PUTC('\017'); break; case CS_ALTERNATE: PUTC('\016'); } last_set = c->c_set; } PUTC(c->c_char); if (++c >= endc) break; PUTC('\b'); } } } #define NALLOC 64 static LINE *line_freelist; LINE * alloc_line() { LINE *l; int i; if (!line_freelist) { l = (LINE *)xmalloc(NULL, sizeof(LINE) * NALLOC); line_freelist = l; for (i = 1; i < NALLOC; i++, l++) l->l_next = l + 1; l->l_next = NULL; } l = line_freelist; line_freelist = l->l_next; memset(l, 0, sizeof(LINE)); return (l); } void free_line(l) LINE *l; { l->l_next = line_freelist; line_freelist = l; } void * xmalloc(p, size) void *p; size_t size; { if (!(p = (void *)realloc(p, size))) err(1, "realloc failed"); return (p); } void usage() { (void)fprintf(stderr, "usage: col [-bfx] [-l nline]\n"); exit(1); } void dowarn(line) int line; { warnx("warning: can't back up %s", line < 0 ? "past first line" : "-- line already flushed"); }
the_stack_data/923424.c
/* * Copyright (c) 2013 The Native Client Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ extern void sym_a(void); extern void sym_b(void); int main() { sym_a(); sym_b(); return 0; }
the_stack_data/82951486.c
#include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/types.h> #include<string.h> #include<sys/stat.h> #include<fcntl.h> #define N 1024 char buffer[N],buffer_read[N]; int main() { int fd; fd = open("/dev/ESCOM_device", O_RDWR ); if(fd == -1) { perror("ERROR al abrir el ddc \n"); exit(EXIT_FAILURE); } printf("Mensaje para el módulo:"); scanf("%s",buffer); write(fd,buffer, strlen(buffer)+1 ); sleep( 5 ); read(fd, buffer_read, N); printf("Mensaje recibido en el DDC: %s\n", buffer_read); close(fd); }
the_stack_data/31388102.c
#include <stdlib.h> #include <string.h> #include <stdio.h> int main(int argc, char *argv[]) { printf("Hello World!\r"); return 0; }
the_stack_data/90766357.c
/** * NXT bootstrap interface; NXT onboard flashing driver. * * Copyright 2006 David Anderson <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #define VINTPTR(addr) ((volatile unsigned int *)(addr)) #define VINT(addr) (*(VINTPTR(addr))) #define USER_PAGE VINTPTR(0x00202100) #define USER_PAGE_NUM VINT(0x00202300) #define FLASH_BASE VINTPTR(0x00100000) #define FLASH_CMD_REG VINT(0xFFFFFF64) #define FLASH_STATUS_REG VINT(0xFFFFFF68) #define OFFSET_PAGE_NUM ((USER_PAGE_NUM & 0x000003FF) << 8) #define FLASH_CMD_WRITE (0x5A000001 + OFFSET_PAGE_NUM) void do_flash_write(void) { unsigned long i; while (!(FLASH_STATUS_REG & 0x1)); for (i = 0; i < 64; i++) FLASH_BASE[(USER_PAGE_NUM*64)+i] = USER_PAGE[i]; FLASH_CMD_REG = FLASH_CMD_WRITE; while (!(FLASH_STATUS_REG & 0x1)); }
the_stack_data/48576054.c
#include <stdio.h> int main() { #if 0 // 找出数组中最大数和最小数并将其交换 int index_max, index_min, max = arr[0], min = arr[0]; for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) { if (max < arr[i]) { max = arr[i]; index_max = i; } if (min > arr[i]) { min = arr[i]; index_min = i; } } arr[index_max] = arr[index_max] ^ arr[index_min]; arr[index_min] = arr[index_max] ^ arr[index_min]; arr[index_max] = arr[index_max] ^ arr[index_min]; for (int i = 0; i < 11; i++) { printf ("%d ", arr[i]); } printf("\n"); #endif #if 0 //冒泡排序 int arr[] = {3,2,1,6,7,9,5,6,2,8,10}; int n; n = sizeof(arr) / sizeof(arr[0]); for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { printf("%d ", arr[j+1]); if (arr[j] > arr[j+1]) { arr[j] = arr[j] ^ arr[j+1]; arr[j+1] = arr[j] ^ arr[j+1]; arr[j] = arr[j] ^ arr[j+1]; } } } for (int i = 0; i < n; i++) { printf ("%d ", arr[i]); } printf("\n"); #endif #if 0 //选择排序 int arr[] = {3,2,1,6,7,9,5,6,2,8,10,0}; int n; n = sizeof(arr) / sizeof(arr[0]); for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (arr[i] > arr[j]) { arr[i] = arr[i] ^ arr[j]; arr[j] = arr[i] ^ arr[j]; arr[i] = arr[i] ^ arr[j]; } } } for (int i = 0; i < n; i++) { printf ("%d ", arr[i]); } printf("\n"); #endif //直接插入 int arr[] = {3,2,1,6,7,9,5,6,2,8,10}; int n, tmp; n = sizeof(arr) / sizeof(arr[0]); for (int i = 1; i < n; i++) { tmp = arr[i]; for (int j = i - 1; j >= 0; j--) { if (arr[j] > tmp) { arr[j+1] = arr[j]; if (j == 0) arr[j] = tmp; } else { arr[j+1] = tmp; break; } printf("arr j :%d ", arr[j]); } /* * for (int j = i - 1; j >= 0; j--) * { * if (arr[j] > tmp) * { * arr[j+1] = arr[j]; * } * else * break; * } * arr[j+1] = tmp; * * */ for (int i = 0; i < n; i++) { printf ("%d ", arr[i]); } printf("\n"); } return 0; }
the_stack_data/121649.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* rotate_matrix.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: psprawka <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/09/29 08:11:05 by psprawka #+# #+# */ /* Updated: 2018/10/07 18:26:29 by psprawka ### ########.fr */ /* */ /* ************************************************************************** */ /* ** Rotate matrix: Given an image represented by NxN matrix, where each pixel ** of matrix is 4 bytes, write a method to rotate an image by 90 degrees. ** Can you do it in place? */ void swap_matrix(int **matrix, int n, int i, int j) { int tmp; tmp = matrix[i][j]; matrix[i][j] = matrix[n - j][i]; matrix[n - j][i] = matrix[n - i][n - j]; matrix[n - i][n - j] = matrix[j][n - i]; matrix[j][n - i] = tmp; } void rotate_matrix(int **matrix, int n) { int tmp; for (int i = 0; i < n - i; i++) { for (int j = i; j < n - i - 1; j++) swap_matrix(matrix, n - 1, i, j); } }