int tegra_dc_ext_check_windowattr(struct tegra_dc_ext *ext, struct tegra_dc_win *win) { long *addr; struct tegra_dc *dc = ext->dc; /* Check the window format */ addr = tegra_dc_parse_feature(dc, win->idx, GET_WIN_FORMATS); if (!test_bit(win->fmt, addr)) { dev_err(&dc->ndev->dev, "Color format of window %d is" " invalid.\n", win->idx); goto fail; } /* Check window size */ addr = tegra_dc_parse_feature(dc, win->idx, GET_WIN_SIZE); if (CHECK_SIZE(win->out_w, addr[MIN_WIDTH], addr[MAX_WIDTH]) || CHECK_SIZE(win->out_h, addr[MIN_HEIGHT], addr[MAX_HEIGHT])) { dev_err(&dc->ndev->dev, "Size of window %d is" " invalid.\n", win->idx); goto fail; } return 0; fail: return -EINVAL; }
int main(void) { int res = 0; #if !defined __uint128_t_defined typedef struct { uint64_t l; uint64_t h; } uint128_t; #define __uint128_t_defined #endif /* !uint128_t */ #define CHECK_SIZE(x, y) \ if (sizeof(x) != sizeof(y)) { \ fprintf( \ stderr, \ "sizeof(" #x ") -> %zu\t" \ "sizeof(" #y ") -> %zu\n", \ sizeof(x), sizeof(y)); \ res = 1; \ } CHECK_SIZE(struct dt_dt_s, uint128_t); CHECK_SIZE(struct dt_d_s, uint64_t); CHECK_SIZE(struct dt_t_s, uint64_t); CHECK_SIZE(dt_ymdhms_t, uint64_t); CHECK_SIZE(dt_sexy_t, uint64_t); return res; }
static bool nodeset_expandtofit (nodeset_t *n, uint32_t r) { uint32_t size = NS_SIZE (n); while (size <= r && CHECK_SIZE(size, size << 1)) size = size << 1; while (size <= r && CHECK_SIZE(size, size + veb_minsize)) size += veb_minsize; if (size <= r && CHECK_SIZE(size, r + 1)) size = r + 1; if (size <= r) return false; return nodeset_resize (n, size); }
static int anoubisd_msg_authverify_size(const char *buf, int buflen) { DECLARE_SIZE(); struct anoubisd_msg_authverify *verify; CAST(verify, buf, buflen); SHIFT_FIELD(verify, payload, buf, buflen); CHECK_SIZE(verify->datalen); CHECK_SIZE(verify->siglen); SHIFT_CNT(verify->datalen, buf, buflen); SHIFT_CNT(verify->siglen, buf, buflen); RETURN_SIZE(); }
static int anoubisd_msg_authchallenge_size(const char *buf, int buflen) { DECLARE_SIZE(); struct anoubisd_msg_authchallenge *challenge; CAST(challenge, buf, buflen); SHIFT_FIELD(challenge, payload, buf, buflen); CHECK_SIZE(challenge->challengelen); CHECK_SIZE(challenge->idlen); SHIFT_CNT(challenge->challengelen, buf, buflen); SHIFT_CNT(challenge->idlen, buf, buflen); RETURN_SIZE(); }
static bool test_unref_reparent(void) { void *root, *p1, *p2, *c1; printf("test: unref_reparent\n# UNREFERENCE AFTER PARENT FREED\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "orig parent"); p2 = talloc_named_const(root, 1, "parent by reference"); c1 = talloc_named_const(p1, 1, "child"); talloc_reference(p2, c1); CHECK_PARENT("unref_reparent", c1, p1); talloc_free(p1); CHECK_PARENT("unref_reparent", c1, p2); talloc_unlink(p2, c1); CHECK_SIZE("unref_reparent", root, 1); talloc_free(p2); talloc_free(root); printf("success: unref_reparent\n"); return true; }
// fall(linethickness) static Box *fall(ListBox *args) { CHECK_ATOMS(args); CHECK_SIZE(args); return new FallBox((*args)[0]->size(X)); }
// rise(linethickness) static Box *rise(ListBox *args) { CHECK_ATOMS(args); CHECK_SIZE(args); return new RiseBox((*args)[0]->size(X)); }
void str_buf_append( str_buf_t *buf, const char *str ) { int len = strlen( str ); CHECK_SIZE( buf, len ); memcpy( buf->data + buf->data_len, str, len ); buf->data_len += len; }
/* test references */ static bool test_ref3(void) { void *root, *p1, *p2, *ref, *r1; printf("test: ref3 [\nPARENT REFERENCE FREE\n]\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); p2 = talloc_named_const(root, 1, "p2"); r1 = talloc_named_const(p1, 1, "r1"); ref = talloc_reference(p2, r1); talloc_report_full(root, stderr); CHECK_BLOCKS("ref3", p1, 2); CHECK_BLOCKS("ref3", p2, 2); CHECK_BLOCKS("ref3", r1, 1); fprintf(stderr, "Freeing p1\n"); talloc_free(p1); talloc_report_full(root, stderr); CHECK_BLOCKS("ref3", p2, 2); CHECK_BLOCKS("ref3", r1, 1); fprintf(stderr, "Freeing p2\n"); talloc_free(p2); talloc_report_full(root, stderr); CHECK_SIZE("ref3", root, 0); talloc_free(root); printf("success: ref3\n"); return true; }
// vspace(box) static Box *vspace(ListBox *args) { CHECK_ATOMS(args); CHECK_SIZE(args); const Box *child = (*args)[0]; return new SpaceBox(BoxSize(0, child->size(Y))); }
// Square box from maximal height and width static Box *square(ListBox *args) { CHECK_ATOMS(args); CHECK_SIZE(args); Box *arg = (Box *)(*args)[0]; return new SquareBox(max(arg->size(X), arg->size(Y))); }
// Subtraction static Box *op_minus(ListBox *args) { CHECK_ATOMS(args); CHECK_SIZE(args); return new SpaceBox( (*args)[0]->size() - (*args)[1]->size()); }
void WRATHDefaultTextAttributePacker:: attribute_names(std::vector<std::string> &out_names, int number_custom_data) const { CHECK_SIZE(0); CHECK_SIZE(1); CHECK_SIZE(2); CHECK_SIZE(3); CHECK_SIZE(4); CHECK_SIZE(5); CHECK_SIZE(6); unsigned int N, R; N=number_custom_data/4; R=number_custom_data%4; if(R>0) { ++N; } out_names.resize(packer_attribute_names().size()+N); std::copy(packer_attribute_names().begin(), packer_attribute_names().end(), out_names.begin()); for(unsigned int i=0, k=packer_attribute_names().size(); i<N; ++i, ++k) { std::ostringstream ostr; ostr << "custom_data" << i; out_names[k]=ostr.str(); } }
// arc(start, length, linethickness) static Box *arc(ListBox *args) { CHECK_ATOMS(args); CHECK_SIZE(args); return new ArcBox((*args)[0]->size(X), (*args)[1]->size(X), (*args)[2]->size(X)); }
// Logical `not' static Box *op_not(ListBox *args) { CHECK_ATOMS(args); CHECK_SIZE(args); if ((*args)[0]->size(X) == 0) return new TrueBox; return new FalseBox; }
// Less or equal static Box *op_le(ListBox *args) { CHECK_ATOMS(args); CHECK_SIZE(args); if ((*args)[0]->size() <= (*args)[1]->size()) return new TrueBox; else return new FalseBox; }
int main(void) { int res = 0; #define CHECK_SIZE(x, y) \ if (sizeof(x) != sizeof(y)) { \ fprintf(stderr, "sizeof(" #x ") -> %zu\n", sizeof(x)); \ res = 1; \ } CHECK_SIZE(struct dt_d_s, uint64_t); CHECK_SIZE(dt_ymd_t, uint32_t); CHECK_SIZE(dt_ymcw_t, uint32_t); CHECK_SIZE(dt_bizda_t, uint32_t); CHECK_SIZE(dt_md_t, uint32_t); CHECK_SIZE(dt_daisy_t, uint32_t); return res; }
/* test references */ static bool test_ref1(void) { void *root, *p1, *p2, *ref, *r1; printf("test: ref1\n# SINGLE REFERENCE FREE\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); p2 = talloc_named_const(p1, 1, "p2"); talloc_named_const(p1, 1, "x1"); talloc_named_const(p1, 2, "x2"); talloc_named_const(p1, 3, "x3"); r1 = talloc_named_const(root, 1, "r1"); ref = talloc_reference(r1, p2); talloc_report_full(root, stderr); CHECK_BLOCKS("ref1", p1, 5); CHECK_BLOCKS("ref1", p2, 1); CHECK_BLOCKS("ref1", ref, 1); CHECK_BLOCKS("ref1", r1, 2); fprintf(stderr, "Freeing p2\n"); talloc_unlink(r1, p2); talloc_report_full(root, stderr); CHECK_BLOCKS("ref1", p1, 5); CHECK_BLOCKS("ref1", p2, 1); CHECK_BLOCKS("ref1", r1, 1); fprintf(stderr, "Freeing p1\n"); talloc_free(p1); talloc_report_full(root, stderr); CHECK_BLOCKS("ref1", r1, 1); fprintf(stderr, "Freeing r1\n"); talloc_free(r1); talloc_report_full(NULL, stderr); fprintf(stderr, "Testing NULL\n"); if (talloc_reference(root, NULL)) { return false; } CHECK_BLOCKS("ref1", root, 1); CHECK_SIZE("ref1", root, 0); talloc_free(root); printf("success: ref1\n"); return true; }
int XvdiGetVideo( ClientPtr client, DrawablePtr pDraw, XvPortPtr pPort, GCPtr pGC, INT16 vid_x, INT16 vid_y, CARD16 vid_w, CARD16 vid_h, INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h ){ DrawablePtr pOldDraw; CHECK_SIZE(drw_w, drw_h, vid_w, vid_h); /* UPDATE TIME VARIABLES FOR USE IN EVENTS */ UpdateCurrentTime(); /* CHECK FOR GRAB; IF THIS CLIENT DOESN'T HAVE THE PORT GRABBED THEN INFORM CLIENT OF ITS FAILURE */ if (pPort->grab.client && (pPort->grab.client != client)) { XvdiSendVideoNotify(pPort, pDraw, XvBusy); return Success; } /* CHECK TO SEE IF PORT IS IN USE; IF SO THEN WE MUST DELIVER INTERRUPTED EVENTS TO ANY CLIENTS WHO WANT THEM */ pOldDraw = pPort->pDraw; if ((pOldDraw) && (pOldDraw != pDraw)) { XvdiSendVideoNotify(pPort, pPort->pDraw, XvPreempted); } (void) (* pPort->pAdaptor->ddGetVideo)(client, pDraw, pPort, pGC, vid_x, vid_y, vid_w, vid_h, drw_x, drw_y, drw_w, drw_h); if ((pPort->pDraw) && (pOldDraw != pDraw)) { pPort->client = client; XvdiSendVideoNotify(pPort, pPort->pDraw, XvStarted); } pPort->time = currentTime; return (Success); }
METHOD(array, Binary_encode, KeyPair) { CHECK_SIZE(args, 2); CHECK_TYPE(args.ptr[0], MSGPACK_OBJECT_BIN); CHECK_TYPE(args.ptr[1], MSGPACK_OBJECT_BIN); msgpack_object_bin secret_key = args.ptr[0].via.bin; msgpack_object_bin public_key = args.ptr[1].via.bin; CHECK_SIZE(secret_key, 32); CHECK_SIZE(public_key, 32); SUCCESS { uint8_t data[64]; memcpy(data, secret_key.ptr, 32); memcpy(data + 32, public_key.ptr, 32); msgpack_pack_bin(res, 64); msgpack_pack_bin_body(res, data, 64); } return 0; }
/* test references */ static bool test_ref2(void) { void *root, *p1, *p2, *ref, *r1; printf("test: ref2\n# DOUBLE REFERENCE FREE\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); talloc_named_const(p1, 1, "x1"); talloc_named_const(p1, 1, "x2"); talloc_named_const(p1, 1, "x3"); p2 = talloc_named_const(p1, 1, "p2"); r1 = talloc_named_const(root, 1, "r1"); ref = talloc_reference(r1, p2); talloc_report_full(root, stderr); CHECK_BLOCKS("ref2", p1, 5); CHECK_BLOCKS("ref2", p2, 1); CHECK_BLOCKS("ref2", r1, 2); fprintf(stderr, "Freeing ref\n"); talloc_unlink(r1, ref); talloc_report_full(root, stderr); CHECK_BLOCKS("ref2", p1, 5); CHECK_BLOCKS("ref2", p2, 1); CHECK_BLOCKS("ref2", r1, 1); fprintf(stderr, "Freeing p2\n"); talloc_free(p2); talloc_report_full(root, stderr); CHECK_BLOCKS("ref2", p1, 4); CHECK_BLOCKS("ref2", r1, 1); fprintf(stderr, "Freeing p1\n"); talloc_free(p1); talloc_report_full(root, stderr); CHECK_BLOCKS("ref2", r1, 1); fprintf(stderr, "Freeing r1\n"); talloc_free(r1); talloc_report_full(root, stderr); CHECK_SIZE("ref2", root, 0); talloc_free(root); printf("success: ref2\n"); return true; }
/* test steal */ static bool test_steal(void) { void *root, *p1, *p2; printf("test: steal\n# STEAL\n"); root = talloc_new(NULL); p1 = talloc_array(root, char, 10); CHECK_SIZE("steal", p1, 10); p2 = talloc_realloc(root, NULL, char, 20); CHECK_SIZE("steal", p1, 10); CHECK_SIZE("steal", root, 30); torture_assert("steal", talloc_steal(p1, NULL) == NULL, "failed: stealing NULL should give NULL\n"); torture_assert("steal", talloc_steal(p1, p1) == p1, "failed: stealing to ourselves is a nop\n"); CHECK_BLOCKS("steal", root, 3); CHECK_SIZE("steal", root, 30); talloc_steal(NULL, p1); talloc_steal(NULL, p2); CHECK_BLOCKS("steal", root, 1); CHECK_SIZE("steal", root, 0); talloc_free(p1); talloc_steal(root, p2); CHECK_BLOCKS("steal", root, 2); CHECK_SIZE("steal", root, 20); talloc_free(p2); CHECK_BLOCKS("steal", root, 1); CHECK_SIZE("steal", root, 0); talloc_free(root); p1 = talloc_size(NULL, 3); talloc_report_full(NULL, stderr); CHECK_SIZE("steal", NULL, 3); talloc_free(p1); printf("success: steal\n"); return true; }
// Addition static Box *op_plus(ListBox *args) { CHECK_ATOMS(args); CHECK_SIZE(args); BoxSize sum(0,0); for (ListBox *b = args; !b->isEmpty(); b = b->tail()) { Box *box = b->head(); sum += box->size(); } return new SpaceBox(sum); }
// Multiplication static Box *op_mult(ListBox *args) { CHECK_ATOMS(args); CHECK_SIZE(args); BoxSize product(1,1); for (ListBox *b = args; !b->isEmpty(); b = b->tail()) { Box *box = b->head(); product *= box->size(); } return new SpaceBox(product); }
// Remainder static Box *op_mod(ListBox *args) { CHECK_ATOMS(args); CHECK_SIZE(args); if ((*args)[1]->size(X) == 0 || (*args)[1]->size(Y) == 0) { VSLLib::eval_error("division by zero"); return 0; } return new SpaceBox( (*args)[0]->size() % (*args)[1]->size()); }
/* test talloc_realloc_fn */ static bool test_realloc_fn(void) { void *root, *p1; printf("test: realloc_fn\n# talloc_realloc_fn\n"); root = talloc_new(NULL); p1 = talloc_realloc_fn(root, NULL, 10); CHECK_BLOCKS("realloc_fn", root, 2); CHECK_SIZE("realloc_fn", root, 10); p1 = talloc_realloc_fn(root, p1, 20); CHECK_BLOCKS("realloc_fn", root, 2); CHECK_SIZE("realloc_fn", root, 20); p1 = talloc_realloc_fn(root, p1, 0); CHECK_BLOCKS("realloc_fn", root, 1); CHECK_SIZE("realloc_fn", root, 0); talloc_free(root); printf("success: realloc_fn\n"); return true; }
static int anoubisd_msg_eventask_size(const char *buf, int buflen) { struct anoubisd_msg_eventask *msg; struct buf_offset offs[5]; int i, j, total = 0; DECLARE_SIZE(); CAST(msg, buf, buflen); /* Detect offset overlaps */ ADDOFFSET(0, csum); ADDOFFSET(1, path); ADDOFFSET(2, ctxcsum); ADDOFFSET(3, ctxpath); ADDOFFSET(4, ev); for (i=0; i<5; ++i) { int s1, e1; if (offs[i].len == 0) continue; s1 = offs[i].off; e1 = s1 + offs[i].len; if (e1 > total) total = e1; for (j=0; j<i; ++j) { int s2, e2; if (offs[j].len == 0) continue; s2 = offs[j].off; e2 = s2 + offs[j].len; if (s2 < e1 && s1 < e2) return -1; } } SHIFT_FIELD(msg, payload, buf, buflen); if (total > buflen) return -1; ADD_SIZE(total); if (msg->pathlen) CHECK_STRING(buf+msg->pathoff, msg->pathlen); if (msg->ctxpathlen) CHECK_STRING(buf+msg->ctxpathoff, msg->ctxpathlen); if (msg->evlen) { int size = eventdev_hdr_size(buf+msg->evoff, msg->evlen); CHECK_SIZE(size); } RETURN_SIZE(); }
status_t BackupDataReader::skip_padding() { ssize_t amt; ssize_t paddingSize; paddingSize = padding_extra(m_pos); if (paddingSize > 0) { uint32_t padding; amt = read(m_fd, &padding, paddingSize); CHECK_SIZE(amt, paddingSize); m_pos += amt; } return NO_ERROR; }
/* Copy to source to stream. */ void stream_put (struct stream *s, void *src, size_t size) { CHECK_SIZE(s, size); if (src) memcpy (s->data + s->putp, src, size); else memset (s->data + s->putp, 0, size); s->putp += size; if (s->putp > s->endp) s->endp = s->putp; }