/*
* Duplicate a string into dynamic memory.
* Fread_strings are read-only and shared.
*/
char *str_dup( const char *str )
{
char *str_new = NULL;
if ( str[0] == '\0' )
return &str_empty[0];
if ( str >= string_space && str < top_string )
{
/*
* return str;
*/
return ( char * ) ( size_t ) str;
/*
* I can't believe I just did that cast… EVIL!
*/
}
str_new = ( char * ) alloc_mem( strlen( str ) + 1 );
strcpy( str_new, str );
return str_new;
}
void *alloc_mem( size_t sMem )
{
void *pMem = NULL;
size_t *magic = NULL;
int iList = 0;
sMem += sizeof( *magic );
for ( iList = 0; iList < MAX_MEM_LIST; iList++ )
{
if ( sMem <= rgSizeList[iList] )
break;
}
if ( iList == MAX_MEM_LIST )
{
proper_exit( MUD_HALT, "Alloc_mem: size %zd too large.", sMem );
}
if ( rgFreeList[iList] == NULL )
{
pMem = alloc_perm( rgSizeList[iList] );
}
else
{
pMem = rgFreeList[iList];
rgFreeList[iList] = *( ( void ** ) rgFreeList[iList] );
}
magic = ( size_t * ) pMem;
*magic = MAGIC_NUM;
pMem = ( void * ) ( ( size_t ) pMem + ( size_t ) ( sizeof( *magic ) ) );
return pMem;
}
magic = ( size_t * ) pMem;:thinking:
*magic = MAGIC_NUM;
magic = ( size_t * ) pMem;:thinking:
*magic = MAGIC_NUM;
I noticed they used free_string on the pointer, but wouldn't it be destroyed once it's out of scope anyway? Or would it just sit there, inaccessible, until the program shut down?