int UCS2ToAscii( _In_z_ const wchar_t *input, _Outptr_result_z_ char **output) { size_t inputLen; size_t xCount = 0; char *incInput = (char*) input; char *incOutput; inputLen = wcslen(input); *output = (char*) PAL_Malloc(inputLen + 1 ); if( *output == NULL ) { return -1; } incOutput = *output; for( xCount = 0; xCount < inputLen; xCount++) { if( input[xCount] > 128 ) { PAL_Free(*output); return -1; } incOutput[xCount] = *incInput; incInput +=2; } incOutput[inputLen] = '\0'; return 0; }
void* MOF_Malloc(MOF_Heap* self, size_t size) { MOF_Block* p; if (!self) return NULL; p = (MOF_Block*)PAL_Malloc(sizeof(MOF_Block) + size); if (!p) return NULL; if (self->head) { p->prev = NULL; p->next = self->head; self->head->prev = p; self->head = p; } else { p->prev = NULL; p->next = NULL; self->head = p; } p->magic = MAGIC; p->size = (unsigned int)size; /* Fill memory with a non-zero character */ memset(p + 1, 0xAA, size); return p + 1; }
static CachedLock_Pool* Pool_New() { CachedLock_Pool* pool; ptrdiff_t buffer; /* The pool and all the latch lines are one block. */ pool = (CachedLock_Pool*)PAL_Malloc(POOL_SIZE); if (pool == NULL) return NULL; /* buffer contains an extra cache line for manual alignment. */ buffer = (ptrdiff_t)(pool + 1); buffer = ALIGN(buffer, CACHE_LINE_SIZE); pool->latches = (ptrdiff_t*)buffer; pool->mask = 0; return pool; }
static int _EnsureMatchState( size_t stringLength, unsigned char** matchState) { size_t buffersize; _FinalizeMatchState(matchState); /* allocate buffer, which is 2 times (the string length + 1) */ buffersize = (stringLength + 1) << 1; *matchState = PAL_Malloc(buffersize * sizeof(unsigned char)); if ( *matchState == NULL ) return MI_FALSE; /* cleanup the memory */ memset(*matchState, 0, sizeof(unsigned char) * buffersize); /* start from [0,0], which is always matched */ (*matchState)[0] = MATCHED_WITH_ONE_CHAR; return MI_TRUE; }
PAL_Char* Shlib_Err() { #if defined(_MSC_VER) PAL_Char* err = NULL; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_FROM_SYSTEM| FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&err, 0, NULL); return err; #else char* err = dlerror(); size_t len = strlen(err) + 1; PAL_Char* copy = PAL_Malloc(len * sizeof(PAL_Char)); TcsStrlcpy(copy, err, len); return copy; #endif }