static void print3Columns( const char* fmt, uint l1, uint l2, uint l3, const char *c1, const char *c2, const char *c3 ) { const char *pc1=c1, *pc2=c2, *pc3=c3; char *c1buf = (char *)malloc(l1+1); char *c2buf = (char *)malloc(l2+1); char *c3buf = (char *)malloc(l3+1); if (!c1buf) outOfMemory(); if (!c2buf) outOfMemory(); if (!c3buf) outOfMemory(); do { pc1 = cutToWhiteSpace(pc1, l1, c1buf); pc2 = cutToWhiteSpace(pc2, l2, c2buf); pc3 = cutToWhiteSpace(pc3, l3, c3buf); printf(fmt, c1buf[0]!='\0'?c1buf:"", c2buf[0]!='\0'?c2buf:"", c3buf[0]!='\0'?c3buf:""); } while (pc1 || pc2 || pc3); free(c1buf); free(c2buf); free(c3buf); }
void JSRopeString::resolveRope(ExecState* exec) const { ASSERT(isRope()); if (is8Bit()) { LChar* buffer; if (RefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) { Heap::heap(this)->reportExtraMemoryCost(newImpl->cost()); m_value = newImpl.release(); } else { outOfMemory(exec); return; } resolveRopeInternal8(buffer); clearFibers(); ASSERT(!isRope()); return; } UChar* buffer; if (RefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) { Heap::heap(this)->reportExtraMemoryCost(newImpl->cost()); m_value = newImpl.release(); } else { outOfMemory(exec); return; } resolveRopeInternal16(buffer); clearFibers(); ASSERT(!isRope()); }
void JSRopeString::resolveRope(ExecState* exec) const { ASSERT(isRope()); if (is8Bit()) { LChar* buffer; if (RefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) { Heap::heap(this)->reportExtraMemoryCost(newImpl->cost()); m_value = newImpl.release(); } else { outOfMemory(exec); return; } for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { if (m_fibers[i]->isRope()) return resolveRopeSlowCase8(buffer); } LChar* position = buffer; for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { StringImpl* string = m_fibers[i]->m_value.impl(); unsigned length = string->length(); StringImpl::copyChars(position, string->characters8(), length); position += length; m_fibers[i].clear(); } ASSERT((buffer + m_length) == position); ASSERT(!isRope()); return; } UChar* buffer; if (RefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) { Heap::heap(this)->reportExtraMemoryCost(newImpl->cost()); m_value = newImpl.release(); } else { outOfMemory(exec); return; } for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { if (m_fibers[i]->isRope()) return resolveRopeSlowCase(buffer); } UChar* position = buffer; for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { StringImpl* string = m_fibers[i]->m_value.impl(); unsigned length = string->length(); StringImpl::copyChars(position, string->characters(), length); position += length; m_fibers[i].clear(); } ASSERT((buffer + m_length) == position); ASSERT(!isRope()); }
void unixArgcInterface(int argc, char **argv, char **envp) { #pragma unused(envp) if ((vmArgVec= calloc(argc + 1, sizeof(char *))) == 0) outOfMemory(); if ((squeakArgVec= calloc(argc + 1, sizeof(char *))) == 0) outOfMemory(); parseEnvironment(); parseArguments(argc, argv); }
void *safe_calloc(size_t size) { void *result = calloc(1, size); if (result == NULL) outOfMemory(); return result; }
void *myRealloc(void *ptr, size_t size) { void *result = realloc(ptr, size); if (! result) outOfMemory(); return result; }
void *rax_realloc(void *p, size_t size, boolean needsMemoryAlignment) { //it's actually not that easy to implement an aligned realloc //because we need to know the size of the array pointed to by //the pointer passed as argument //hence I added this boolean flag that should increase programmer //awareness about this issue void *ptr = (void *)NULL; if(needsMemoryAlignment) { assert(0); return (void*)NULL; } else { #ifndef WIN32 ptr = realloc(p, size); #else ptr = _aligned_realloc(p, size, BYTE_ALIGNMENT); #endif } if(ptr == (void*)NULL) { outOfMemory(); assert(0); } return ptr; }
void JSString::resolveRope(ExecState* exec) const { ASSERT(isRope()); UChar* buffer; if (PassRefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) m_value = newImpl; else { outOfMemory(exec); return; } for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { if (m_fibers[i]->isRope()) return resolveRopeSlowCase(exec, buffer); } UChar* position = buffer; for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { StringImpl* string = m_fibers[i]->m_value.impl(); unsigned length = string->length(); StringImpl::copyChars(position, string->characters(), length); position += length; m_fibers[i].clear(); } ASSERT((buffer + m_length) == position); ASSERT(!isRope()); }
void *xmalloc(size_t bytes) { void *retval = calloc(1, bytes); if (retval == NULL) outOfMemory(); return retval; } // xmalloc
void *xrealloc(void *ptr, size_t bytes) { void *retval = realloc(ptr, bytes); if (retval == NULL) outOfMemory(); return retval; } // xrealloc
void addToPassphrase(AppInfo *app, char c) { int status = append_to_buf(&(app->buf), &(app->bufSize), &(app->bufIndex), c); if (APPEND_FAILURE == status) { cleanUp(app); outOfMemory(app, __LINE__); } updateIndicators(app, 1); }
void addSymbol(pSymTabEntry pEntry) { if (SymFind(symTab, pEntry) != NULL) { reportError(CERR_REDEFN_IGNORED, pEntry->name); } else { if (!SymAdd(symTab, pEntry)) { outOfMemory(); } g_numSymbols++; // Number of symbols in symbol table } }
Body_t Body_new (char *key, char *value) { Body_t p = malloc (sizeof(*p)); if (0==p) outOfMemory(); strcpy(p->key, key); strcpy(p->value,value); return p; }
void acceptAction(AppInfo *app) { int status = append_to_buf(&(app->buf), &(app->bufSize), &(app->bufIndex), '\0'); if (APPEND_FAILURE == status) { cleanUp(app); outOfMemory(app, __LINE__); } fputs(app->buf, stdout); fputc('\n', stdout); exitApp(app, EXIT_STATUS_ACCEPT); }
pSymTabEntry createTabEntry(char *name, SymType type, void *data) { pSymTabEntry newEntry; newEntry = wicMalloc(sizeof(SymTabEntry)); newEntry->name = wicStrdup(name); if (newEntry->name == NULL) { outOfMemory(); } newEntry->type = type; newEntry->repr.data = data; return newEntry; }
static tmbstr GetAllowedValues( TidyOption topt, const OptionDesc *d ) { if (d->vals) { tmbstr val = (tmbstr)malloc(1+strlen(d->vals)); if (!val) outOfMemory(); strcpy(val, d->vals); return val; } else return GetAllowedValuesFromPick( topt ); }
ReqLine_t ReqLine_new (enum ReqKind_t kind , char *uri , enum HttpVersion_t v) { ReqLine_t p = malloc (sizeof(*p)); if (0==p) outOfMemory(); p->kind = kind; p->uri = uri; p->httpversion = v; return p; }
void BufferLoaderThread::run(){ try { DataJockey::BeatBufferPtr beat_buffer = new DataJockey::BeatBuffer(mBeatBufLoc.toStdString()); DataJockey::AudioBufferPtr audio_file = new DataJockey::AudioBuffer(mAudioBufLoc.toStdString()); emit(buffersLoaded(mIndex, mWorkId, audio_file, beat_buffer)); } catch (std::bad_alloc&) { emit(outOfMemory(mIndex, mWorkId, mAudioBufLoc, mBeatBufLoc)); } catch (std::runtime_error e){ emit(cannotLoad(mIndex, mWorkId, mAudioBufLoc, mBeatBufLoc, QString(e.what()))); } catch (int e) { std::cerr << "An exception occurred. Exception Nr. " << e << std::endl; } }
void JSRopeString::resolveRope(ExecState* exec) const { ASSERT(isRope()); if (isSubstring()) { ASSERT(!substringBase()->isRope()); m_value = substringBase()->m_value.substringSharingImpl(substringOffset(), length()); substringBase().clear(); return; } if (is8Bit()) { LChar* buffer; if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) { Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost()); m_value = WTFMove(newImpl); } else { outOfMemory(exec); return; } resolveRopeInternal8NoSubstring(buffer); clearFibers(); ASSERT(!isRope()); return; } UChar* buffer; if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) { Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost()); m_value = WTFMove(newImpl); } else { outOfMemory(exec); return; } resolveRopeInternal16NoSubstring(buffer); clearFibers(); ASSERT(!isRope()); }
RespLine_t RespLine_new(enum HttpVersion_t v , enum RespKind_t kind , char *info) { RespLine_t p = malloc (sizeof(*p)); if (0==p) outOfMemory(); p->httpversion = v; p->kind = kind; p->info = info; return p; }
/* Assumes 's' is non-NULL. */ TextObject *createTextObject(AppInfo *app, char *s) { TextObject *t = malloc(sizeof(*t)); if (NULL == t) { outOfMemory(app, __LINE__); } memset(t, 0, sizeof(*t)); if (('\n' == *s) || ('\0' == *s)) { t->text = " "; } else { t->text = s; } return(t); }
static void kb_loadKernelKeyMap(_self) { int map; debugf("loading kernel keymap\n"); if (!(self->keyMaps= (unsigned short **)calloc(MAX_NR_KEYMAPS, sizeof(unsigned short *)))) outOfMemory(); for (map= 0; map < MAX_NR_KEYMAPS; ++map) { struct kbentry kb; int key; kb.kb_index= 0; kb.kb_table= map; if (ioctl(self->fd, KDGKBENT, (unsigned long)&kb)) fatalError("KDGKBENT"); if (K_NOSUCHMAP == kb.kb_value) continue; if (!(self->keyMaps[map]= (unsigned short *)calloc(NR_KEYS, sizeof(unsigned short)))) outOfMemory(); for (key= 0; key < NR_KEYS; ++key) { kb.kb_index= key; if (ioctl(self->fd, KDGKBENT, (unsigned long)&kb)) fatalError("KDGKBENT"); self->keyMaps[map][key]= kb.kb_value; } } debugf("kernel keymap loaded\n"); }
void Assembler::emitToExecutableMemory(void *code) { assert(!outOfMemory()); uint8_t *base = reinterpret_cast<uint8_t *>(code); memcpy(base, buffer(), length()); for (size_t i = 0; i < absolute_code_refs_.length(); i++) { size_t offset = absolute_code_refs_[i]; size_t target = *reinterpret_cast<uint64_t*>(base + offset - 8); assert(target <= length()); *reinterpret_cast<void**>(base + offset - 8) = base + target; } }
//////////////////////////////////////// // http Http_t Http_new (enum HttpKind_t kind , ReqLine_t reqLine , RespLine_t respLine , Header_t headers , char *body) { Http_t p = malloc (sizeof (*p)); if (0==p) outOfMemory(); p->kind = kind; p->reqLine = reqLine; p->respLine = respLine; p->headers = headers; p->body = body; return p; }
static tmbstr get_escaped_name( ctmbstr name ) { tmbstr escpName; char aux[2]; uint len = 0; ctmbstr c; for(c=name; *c!='\0'; ++c) switch(*c) { case '<': case '>': len += 4; break; case '"': len += 6; break; default: len += 1; break; } escpName = (tmbstr)malloc(len+1); if (!escpName) outOfMemory(); escpName[0] = '\0'; aux[1] = '\0'; for(c=name; *c!='\0'; ++c) switch(*c) { case '<': strcat(escpName, "<"); break; case '>': strcat(escpName, ">"); break; case '"': strcat(escpName, """); break; default: aux[0] = *c; strcat(escpName, aux); break; } return escpName; }
TView* TProgram::validView(TView* p) { if( p == 0 ) return 0; if( lowMemory() ) { destroy( p ); outOfMemory(); return 0; } if( !p->valid( cmValid ) ) { destroy( p ); return 0; } return p; }
void TiString::resolveRope(TiExcState* exec) const { ASSERT(isRope()); UChar* buffer; if (PassRefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) m_value = newImpl; else { outOfMemory(exec); return; } RopeImpl::Fiber currentFiber = m_fibers[0]; if ((m_fiberCount > 2) || (RopeImpl::isRope(currentFiber)) || ((m_fiberCount == 2) && (RopeImpl::isRope(m_fibers[1])))) { resolveRopeSlowCase(exec, buffer); return; } UChar* position = buffer; StringImpl* string = static_cast<StringImpl*>(currentFiber); unsigned length = string->length(); StringImpl::copyChars(position, string->characters(), length); if (m_fiberCount > 1) { position += length; currentFiber = m_fibers[1]; string = static_cast<StringImpl*>(currentFiber); length = string->length(); StringImpl::copyChars(position, string->characters(), length); position += length; } ASSERT((buffer + m_length) == position); for (unsigned i = 0; i < m_fiberCount; ++i) { RopeImpl::deref(m_fibers[i]); m_fibers[i] = 0; } m_fiberCount = 0; ASSERT(!isRope()); }
void *rax_malloc( size_t size ) { #ifndef WIN32 void *ptr = (void *)NULL; int res = posix_memalign(&ptr, BYTE_ALIGNMENT, size); if(res != 0) { outOfMemory(); assert(0); } return ptr; #else return _aligned_malloc(size, BYTE_ALIGNMENT); #endif }
static tmbstr GetAllowedValuesFromPick( TidyOption topt ) { TidyIterator pos; Bool first; ctmbstr def; uint len = 0; tmbstr val; pos = tidyOptGetPickList( topt ); first = yes; while ( pos ) { if (first) first = no; else len += 2; def = tidyOptGetNextPick( topt, &pos ); len += strlen(def); } val = (tmbstr)malloc(len+1); if (!val) outOfMemory(); val[0] = '\0'; pos = tidyOptGetPickList( topt ); first = yes; while ( pos ) { if (first) first = no; else strcat(val, ", "); def = tidyOptGetNextPick( topt, &pos ); strcat(val, def); } return val; }
static tmbstr get_option_names( const CmdOptDesc* pos ) { tmbstr name; uint len = strlen(pos->name1); if (pos->name2) len += 2+strlen(pos->name2); if (pos->name3) len += 2+strlen(pos->name3); name = (tmbstr)malloc(len+1); if (!name) outOfMemory(); strcpy(name, pos->name1); if (pos->name2) { strcat(name, ", "); strcat(name, pos->name2); } if (pos->name3) { strcat(name, ", "); strcat(name, pos->name3); } return name; }