static void __resizeList( iOListData data ) { if( data->size + 1 > data->allocsize ) { int newsize = data->size + LIST_MINSIZE; data->objList = reallocMem( data->objList, newsize * sizeof( obj ) ); data->allocsize = newsize; } else if( data->size < data->allocsize - LIST_MINSIZE && data->size >= 2*LIST_MINSIZE ) { int newsize = data->allocsize - LIST_MINSIZE; data->objList = reallocMem( data->objList, newsize * sizeof( obj ) ); data->allocsize = newsize; } }
void enqueue(const T &elem) { if(aSize==aCapasity) { reallocMem(); } arElem[aSize]=elem; aSize++; }
int rocs_scanDir(const char *dirname, const char* extension, iDirEntry** namelist) { struct _finddata_t c_file; long hFile; int found = 0; int done = 0; char* search = StrOp.fmt( "%s%c*%s", dirname, SystemOp.getFileSeparator(), extension!=NULL?extension:".*" ); hFile = _findfirst( search, &c_file ); StrOp.free( search ); if( hFile == -1L ) return found; do { if( namelist != NULL ) { iDirEntry dir = allocIDMem( sizeof( struct DirEntry ), RocsDirID ); *namelist = reallocMem( *namelist, (found+1)*sizeof(iDirEntry) ); dir->name = StrOp.dupID( c_file.name, RocsDirID ); dir->mtime = c_file.time_write; (*namelist)[found] = dir; } found++; done = _findnext( hFile, &c_file ); } while( !done ); _findclose(hFile); return found; }
void push_back(const T &elem) { if(aSize==aCapasity) { reallocMem(); } arElem[aSize]=elem; aSize++; }
void insert(const TKeys &key, const TData &data) { if(aSize==aCapasity) { reallocMem(); } arElemKeys[aSize]=key; arElemData[aSize]=data; aSize++; }
T& operator[] (const int i) { if(i>=aSize) { aSize=i+1; while(aSize>aCapasity) reallocMem(); } return arElem[i]; }
static void printChar // PRINT A CHARACTER ( char chr ) // - to be printed { if( chr == '\n' ) { printCtl.buffer[ printCtl.index ] = '\0'; printIDE( printCtl.buffer ); printCtl.index = 0; } else { printCtl.buffer[ printCtl.index ] = chr; ++ printCtl.index; if( printCtl.index >= printCtl.size_buf ) { unsigned old_size = printCtl.size_buf; printCtl.size_buf += 32; printCtl.buffer = reallocMem( printCtl.buffer , old_size , printCtl.size_buf ); } } }
static void jdwp_vm_classpaths(jdwp_command_packet cmd) { char *finger = (char*)system_vm_args->classpath; char *next; char **array; int fsrootlen = strlen(fsroot); int i; int l; int n; woempa(7, "Base dir = %s\n", jdwp_base_directory); // baseDir jdwp_put_cstring(&reply_grobag, jdwp_base_directory, strlen(jdwp_base_directory)); if (fsroot[fsrootlen - 1] == '/') { --fsrootlen; } woempa(7, "fsroot = %s\n", fsroot); woempa(7, "Classpath = %s\n", system_vm_args->classpath); n = 0; while (finger) { n++; finger = strstr(++finger, ":"); } woempa(7, "Classpath has %d components\n", n); array = allocMem(n * sizeof(char*)); finger = (char*)system_vm_args->classpath; i = 0; while (finger) { next = strstr(finger, ":"); l = next ? next - finger : (int)strlen(finger); if (l >= 3 && finger[0] == '{' && finger[1] == '}' && finger[2] == '/') { array[i] = allocMem(l + fsrootlen); strcpy(array[i], fsroot); memcpy(array[i] + fsrootlen, finger + 2, l); array[i][fsrootlen + l - 2] = 0; } else { array[i] = allocMem(l + 1); strcpy(array[i], finger); } woempa(7, " %s\n", array[i]); ++i; finger = next ? next + 1 : NULL; } // classpaths jdwp_put_u4(&reply_grobag, n); for (i = 0; i < n; ++i) { woempa(7, " %s\n", array[i]); jdwp_put_cstring(&reply_grobag, array[i], strlen(array[i])); releaseMem(array[i]); } finger = bootclasspath; woempa(7, "Bootclasspath = %s\n", bootclasspath); n = 0; while (finger) { n++; finger = strstr(++finger, ":"); } woempa(7, "Bootclasspath has %d components\n", n); array = reallocMem(array, n * sizeof(char*)); finger = bootclasspath; i = 0; while (finger) { next = strstr(finger, ":"); l = next ? next - finger : (int)strlen(finger); if (l >= 3 && finger[0] == '{' && finger[1] == '}' && finger[2] == '/') { array[i] = allocMem(l + fsrootlen); strcpy(array[i], fsroot); memcpy(array[i] + fsrootlen, finger + 2, l); array[i][fsrootlen + l - 2] = 0; } else { array[i] = allocMem(l + 1); strcpy(array[i], finger); } woempa(7, " %s\n", array[i]); ++i; finger = next ? next + 1 : NULL; } // bootclasspaths jdwp_put_u4(&reply_grobag, n); for (i = 0; i < n; ++i) { woempa(7, " %s\n", array[i]); jdwp_put_cstring(&reply_grobag, array[i], strlen(array[i])); releaseMem(array[i]); } releaseMem(array); jdwp_send_reply(cmd->id, &reply_grobag, jdwp_err_none); }
static t_block reallocate_block(t_mchecker mc, t_block list, t_block block, x_size new_size) { t_block new_block; x_size old_size = block->size; x_ubyte pattern = block->pattern; x_ubyte * data; x_size which = x_random() % 5; x_size orsize; x_size nrsize; w_chunk chunk; x_mutex_lock(test_mutex, x_eternal); x_list_remove(block); chunk = block2chunk(block); orsize = x_mem_size(chunk); /* ** Use 'which' to bring some variation in the __LINE__ number. */ if (which == 0) { new_block = reallocMem(block, sizeof(t_Block) + new_size); } else if (which == 1) { new_block = reallocMem(block, sizeof(t_Block) + new_size); } else if (which == 2) { new_block = reallocMem(block, sizeof(t_Block) + new_size); } else if (which == 3) { new_block = reallocMem(block, sizeof(t_Block) + new_size); } else { new_block = reallocMem(block, sizeof(t_Block) + new_size); } if (new_block == NULL) { x_list_insert(list, block); x_mutex_unlock(test_mutex); return NULL; } else { chunk = block2chunk(new_block); nrsize = x_mem_size(chunk); new_block->size = new_size; change_count(orsize, nrsize, new_block, old_size, new_size); } x_list_insert(list, new_block); /* ** If the block has grown, fill the new room with the pattern data. */ if (old_size < new_size) { data = & new_block->data[old_size]; set_data(data, new_size - old_size, pattern); growed += 1; } else { shrinked += 1; } x_mutex_unlock(test_mutex); return new_block; }
char *reallocString(void *p, size_t n) { return (char *)reallocMem(p, n); } /* reallocString */
/* Read a file into memory, mime encode it, * and return the type of encoding and the encoded data. * Last three parameters are result parameters. * If ismail is nonzero, the file is the mail, not an attachment. * In fact ismail indicates the line that holds the subject. * If ismail is negative, then -ismail indicates the subject line, * and the string file is not the filename, but rather, the mail to send. */ bool encodeAttachment(const char *file, int ismail, bool webform, const char **type_p, const char **enc_p, char **data_p) { char *buf; char c; bool longline; char *s, *t, *v; char *ct, *ce; /* content type, content encoding */ int buflen, i, cx; int nacount, nullcount, nlcount; if (ismail < 0) { buf = cloneString(file); buflen = strlen(buf); ismail = -ismail; file = EMPTYSTRING; } else { if (!ismc && (cx = stringIsNum(file)) >= 0) { static char newfilename[16]; if (!unfoldBuffer(cx, false, &buf, &buflen)) return false; if (!buflen) { if (webform) { empty: buf = EMPTYSTRING; ct = "text/plain"; ce = "7bit"; goto success; } setError(MSG_BufferXEmpty, cx); goto freefail; } sprintf(newfilename, "<buffer %d>", cx); file = newfilename; if (sessionList[cx].lw->fileName) file = sessionList[cx].lw->fileName; } else { if (!fileIntoMemory(file, &buf, &buflen)) return false; if (!buflen) { if (webform) goto empty; setError(MSG_FileXEmpty, file); goto freefail; } } } /* ismail negative or normal */ if (ismail) { /* Put newline at the end. Yes, the buffer is allocated * with space for newline and null. */ if (buf[buflen - 1] != '\n') buf[buflen++] = '\n'; /* check for subject: line */ s = buf; i = ismail; while (--i) { while (*s != '\n') ++s; ++s; } while (*s == ' ' || *s == '\t') ++s; if (!memEqualCI(s, "subject:", 8)) { setError(MSG_SubjectStart); goto freefail; } s += 8; while (*s == ' ' || *s == '\t') ++s; t = s; while (*s != '\n') ++s; v = s; while (s > t && isspaceByte(s[-1])) --s; if (s - t >= sizeof(subjectLine)) { setError(MSG_SubjectLong, sizeof(subjectLine) - 1); goto freefail; } if (s > t) memcpy(subjectLine, t, s - t); subjectLine[s - t] = 0; if (subjectLine[0]) { char *subjiso = isoEncode(subjectLine, subjectLine + strlen(subjectLine)); if (subjiso) { if (strlen(subjiso) >= sizeof(subjectLine)) { nzFree(subjiso); setError(MSG_SubjectLong, sizeof(subjectLine) - 1); goto freefail; } strcpy(subjectLine, subjiso); nzFree(subjiso); } } debugPrint(6, "subject = %s", subjectLine); /* Blank lines after subject are optional, and ignored. */ for (t = buf + buflen; v < t; ++v) if (*v != '\r' && *v != '\n') break; buflen -= (v - buf); if (buflen) memmove(buf, v, buflen); buf[buflen] = 0; if (doSignature) { /* Append .signature file. */ /* Try account specific .signature file, then fall back to .signature */ sprintf(sigFileEnd, "%d", mailAccount); c = fileTypeByName(sigFile, false); if (!c) { *sigFileEnd = 0; c = fileTypeByName(sigFile, false); } if (c != 0) { int fd, n; if (c != 'f') { setError(MSG_SigRegular); goto freefail; } n = fileSizeByName(sigFile); if (n > 0) { buf = reallocMem(buf, buflen + n + 1); fd = open(sigFile, O_RDONLY); if (fd < 0) { setError(MSG_SigAccess); goto freefail; } read(fd, buf + buflen, n); close(fd); buflen += n; buf[buflen] = 0; } } } /* .signature */ } /* Infer content type from the filename */ ct = 0; s = strrchr(file, '.'); if (s && s[1]) { ++s; if (stringEqualCI(s, "ps")) ct = "application/PostScript"; if (stringEqualCI(s, "jpeg")) ct = "image/jpeg"; if (stringEqualCI(s, "gif")) ct = "image/gif"; if (stringEqualCI(s, "wav")) ct = "audio/basic"; if (stringEqualCI(s, "mpeg")) ct = "video/mpeg"; if (stringEqualCI(s, "rtf")) ct = "text/richtext"; if (stringEqualCI(s, "htm") || stringEqualCI(s, "html") || stringEqualCI(s, "shtm") || stringEqualCI(s, "shtml") || stringEqualCI(s, "asp")) ct = "text/html"; } /* Count the nonascii characters */ nacount = nullcount = nlcount = 0; longline = false; s = 0; for (i = 0; i < buflen; ++i) { c = buf[i]; if (c == '\0') ++nullcount; if (c < 0) ++nacount; if (c != '\n') continue; ++nlcount; t = buf + i; if (s && t - s > 120) longline = true; if (!s && i > 120) longline = true; s = t; } t = buf + i; if (s && t - s > 120) longline = true; if (!s && i > 120) longline = true; debugPrint(6, "attaching %s length %d nonascii %d nulls %d longline %d", file, buflen, nacount, nullcount, longline); nacount += nullcount; /* Set the type of attachment */ if (buflen > 20 && nacount * 5 > buflen) { if (!ct) ct = "application/octet-stream"; /* default type for binary */ } if (!ct) ct = "text/plain"; /* Criteria for base64 encode. * files uploaded from a web form need not be encoded, unless they contain * nulls, which is a quirk of my slapped together software. */ if (!webform && (buflen > 20 && nacount * 5 > buflen) || webform && nullcount) { if (ismail) { setError(MSG_MailBinary, file); goto freefail; } s = base64Encode(buf, buflen, true); nzFree(buf); buf = s; ce = "base64"; goto success; } if (!webform) { /* Switch to unix newlines - we'll switch back to dos later. */ v = buf + buflen; for (s = t = buf; s < v; ++s) { c = *s; if (c == '\r' && s < v - 1 && s[1] == '\n') continue; *t++ = c; } buflen = t - buf; /* Do we need to use quoted-printable? */ /* Perhaps this hshould read (nacount > 0) */ if (nacount * 20 > buflen || nullcount || longline) { char *newbuf; int l, colno = 0, space = 0; newbuf = initString(&l); v = buf + buflen; for (s = buf; s < v; ++s) { c = *s; /* do we have to =expand this character? */ if (c < '\n' && c != '\t' || c == '=' || c == '\xff' || (c == ' ' || c == '\t') && s < v - 1 && s[1] == '\n') { char expand[4]; sprintf(expand, "=%02X", (uchar) c); stringAndString(&newbuf, &l, expand); colno += 3; } else { stringAndChar(&newbuf, &l, c); ++colno; } if (c == '\n') { colno = space = 0; continue; } if (c == ' ' || c == '\t') space = l; if (colno < 72) continue; if (s == v - 1) continue; /* If newline's coming up anyways, don't force another one. */ if (s[1] == '\n') continue; i = l; if (!space || space == i) { stringAndString(&newbuf, &l, "=\n"); colno = space = 0; continue; } colno = i - space; stringAndString(&newbuf, &l, "**"); /* make room */ while (i > space) { newbuf[i + 1] = newbuf[i - 1]; --i; } newbuf[space] = '='; newbuf[space + 1] = '\n'; space = 0; } /* loop over characters */ nzFree(buf); buf = newbuf; ce = "quoted-printable"; goto success; } } buf[buflen] = 0; ce = (nacount ? "8bit" : "7bit"); success: debugPrint(6, "encoded %s %s length %d", ct, ce, strlen(buf)); *enc_p = ce; *type_p = ct; *data_p = buf; return true; freefail: nzFree(buf); return false; } /* encodeAttachment */
w_int loadSuperClasses(w_clazz clazz, w_thread thread) { w_clazz super; w_int i; w_int n; w_int result = CLASS_LOADING_DID_NOTHING; #ifndef NO_FORMAT_CHECKS if (isNotSet(clazz->flags, CLAZZ_IS_TRUSTED) && !clazz->temp.super_index) { throwException(thread, clazzVerifyError, "Class %k has no superclass", clazz); return CLASS_LOADING_FAILED; } #endif clazz->supers = allocMem(MAX_SUPER_CLASSES * sizeof(w_clazz)); if (!clazz->supers) { return CLASS_LOADING_FAILED; } super = clazz; n = MAX_SUPER_CLASSES; for (i = 0; i < MAX_SUPER_CLASSES; ++i) { if (!super->temp.super_index) { woempa(1, "Reached top of hierarchy after %d class(es): %k\n", i, super); n = i; break; } #ifndef NO_FORMAT_CHECKS if (isNotSet(super->flags, CLAZZ_IS_TRUSTED) && !isClassConstant(super, super->temp.super_index)) { throwException(thread, clazzClassFormatError, "Superclass of %k is not a class constant (is %02x)", super, super->tags[super->temp.super_index]); return CLASS_LOADING_FAILED; } #endif super = getClassConstant(super, super->temp.super_index, thread); if (!super) { throwException(thread, clazzLinkageError, "Cannot resolve superclass of %k", clazz); return CLASS_LOADING_FAILED; } clazz->supers[i] = super; woempa(1, "Class %k supers[%d] = %k\n", clazz, i, super); if (getClazzState(super) >= CLAZZ_STATE_SUPERS_LOADED) { woempa(1, "Class %k is already supersLoaded, has %d superclasses => depth of %k is %d\n", super, super->numSuperClasses, clazz, i + super->numSuperClasses + 1); n = i + super->numSuperClasses + 1; break; } } if (n == MAX_SUPER_CLASSES) { wabort(ABORT_WONKA, "Class %k has too many superclasses", clazz); } for (i= i + 1; i < n; ++i) { woempa(1, "Copying %k (superclass[%d] of %k) as superclass[%d] of %k\n", super->supers[i - n + super->numSuperClasses], i - n + super->numSuperClasses, super, i, clazz); clazz->supers[i] = super->supers[i - n + super->numSuperClasses]; } woempa(1, "Class %k has total of %d superclasses\n", clazz, n); clazz->supers = reallocMem(clazz->supers, n * sizeof(w_clazz)); if (!clazz->supers) { return CLASS_LOADING_FAILED; } clazz->numSuperClasses = n; super = clazz->supers[0]; #ifndef NO_HIERARCHY_CHECKS if (isNotSet(super->flags, CLAZZ_IS_TRUSTED)) { if (isSet(clazz->flags, ACC_INTERFACE) && super != clazzObject) { throwException(thread, clazzIncompatibleClassChangeError, "Superclass %k of %k is an interface", super, clazz); return CLASS_LOADING_FAILED; } if (isSet(super->flags, ACC_FINAL)) { woempa(9, "Violation of J+JVM Constraint 4.1.1, item 2\n"); throwException(thread, clazzIncompatibleClassChangeError, "Superclass %k of %k is final", super, clazz); return CLASS_LOADING_FAILED; } if (isNotSet(super->flags, ACC_PUBLIC) && !sameRuntimePackage(clazz, super)) { woempa(9, "Violation of J+JVM Constraint 4.1.4\n"); throwException(thread, clazzIncompatibleClassChangeError, "Superclass %k of %k is not accessible", super, clazz); return CLASS_LOADING_FAILED; } } #endif for (i = n - 1; i >= 0; --i) { result |= mustBeSupersLoaded(clazz->supers[i]); if (result == CLASS_LOADING_FAILED || exceptionThrown(thread)) { return CLASS_LOADING_FAILED; } } clazz->flags |= super->flags & CLAZZ_HERITABLE_FLAGS; return CLASS_LOADING_SUCCEEDED; }