char* DStrAppendStr(DStr_p strdes, char* newpart) { long newlen, newmem; assert(strdes); assert(newpart); newlen = strlen(newpart); newmem = strdes->mem; while(strdes->len+newlen >= newmem) /* I expect this loop to be computed at most once in the average case, so it should be more efficient than the direct computation (which requires a division. */ { newmem += DSTRGROW; } if(newmem > strdes->mem) { strdes->string = SecureRealloc(strdes->string, newmem); strdes->mem = newmem; strdes->string[strdes->len] = '\0'; } strcat(strdes->string+strdes->len, newpart); strdes->len += newlen; return strdes->string; }
char* DStrAppendChar(DStr_p strdes, char newch) { assert(strdes); if(strdes->len+1 >= strdes->mem) { strdes->string = SecureRealloc(strdes->string, strdes->len+DSTRGROW); strdes->mem = strdes->len+DSTRGROW; } strdes->string[strdes->len] = newch; strdes->len++; strdes->string[strdes->len] = '\0'; return strdes->string; }
void DStrMinimize(DStr_p strdes) { assert(strdes); if(strdes->string) { if(strdes->len) { strdes->string = SecureRealloc(strdes->string, strdes->len+1); strdes->mem = strdes->len+1; } else { FREE(strdes->string); strdes->mem = 0; } } }
void GenDistribSizeAdjust(GenDistrib_p gd, Sig_p sig) { long new_size; FunCode i; if(sig->f_count >= gd->size) { new_size = sig->f_count+1; gd->dist_array = SecureRealloc(gd->dist_array, new_size*sizeof(FunGenCell)); for(i=gd->size; i<new_size; i++) { init_fun_gen_cell(&(gd->dist_array[i]), i); } SizeFree(gd->f_distrib, gd->size*sizeof(long)); gd->f_distrib = SizeMalloc(new_size*sizeof(long)); memset(gd->f_distrib, 0, new_size*sizeof(long)); gd->size = new_size; } }
void dpll_form_add_atom_space(DPLLFormula_p form) { long old_limit, new_limit,i; old_limit = form->atom_no; if(old_limit) { new_limit=old_limit*ATOM_GROWTH_FACTOR; } else { new_limit = DEFAULT_ATOM_NUMBER; } form->atoms = SecureRealloc(form->atoms, new_limit*sizeof(AtomCell)); for(i=old_limit; i<new_limit; i++) { form->atoms[i].pos_occur = 0; form->atoms[i].neg_occur = 0; form->atoms[i].pos_active= NULL; form->atoms[i].neg_active= NULL; } form->atom_no = new_limit; }
void CredsStoreAdd(const char *Realm, const char *User, const char *Secret) { int len; char *ptr; //Don't add if already exists ptr=CredsStoreGetSecret(Realm, User); if (ptr && (strcmp(Secret, ptr)==0)) { mprotect(CredsStore, CredsStoreSize, PROT_NONE); return; } len=CredsStoreUsed+StrLen(Realm) + StrLen(User) + StrLen(Secret) + 100; CredsStoreSize=SecureRealloc(&CredsStore, CredsStoreSize, len, SMEM_NOFORK | SMEM_NODUMP | SMEM_LOCK); mprotect(CredsStore, CredsStoreSize, PROT_WRITE); ptr=CredsStoreWrite(CredsStore+CredsStoreUsed, Realm, StrLen(Realm)); ptr=CredsStoreWrite(ptr, User, StrLen(User)); ptr=CredsStoreWrite(ptr, Secret, StrLen(Secret)); mprotect(CredsStore, CredsStoreSize, PROT_NONE); CredsStoreUsed=ptr-CredsStore; }