TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: JOHN DUMAS
from: GEORGE WHITE
date: 1998-03-08 22:18:00
subject: Re: Avoid disaster

Hi John,
You asked:
JD> JD> I am making a C DLL and have been wondering how I can tell if a 
assed
JD> JD> pointer has enough memory allocated to have it carry back my string.
JD> DM> If you cannot control the API to your DLL, you can't.  If you can
JD>     For still learning programmers like myself the self made bug that
JD>     drives me to distraction is intermittantly over filling or over
JD>     reading an array or string.
That is definitely your problem. C will not protect the programmer from
himself!
JD>     char string[4];
JD>     string="OUCH";
JD>     char array[3][4];
JD>     printf( " %s ",array[4] );
JD>     I need a function put in C like.
JD>     char string[4];
JD>     if( CheckLimit( string,lenstr("OUCH"))
JD>         ^^^^^^^^^^
if (sizeof(string) > strlen("OUCH"))
JD>     string="OUCH";
JD>     else
JD>     error;
JD>     I guessing but since there is a free command the size of the
JD>     variables must be held somwhere. Where?
free() only works against memory that has been allocated using malloc().
The heap management routines maintain internal information about the
size of the block of data used (which is _always_ greater than the size
requested as it includes the control data & is rounded to position the
blocks on data boundaries giving efficient access) but I don't believe
there is any official way to access the information.
George
 * SLMR 2.1a * All Trademarks acknowledged (just in case ).
--- Maximus/2 3.01
---------------
* Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.