Re: Size of malloc'd?
bwaichu@xxxxxxxxx wrote:
How do I determine the size of a previously malloc'd buffer?
char *buffer;
buffer = calloc(18, sizeof *buffer);
I cannot do a sizeof(buffer) since it would only return the size of the
pointer. I cannot do sizeof *buffer since it would only return the
size of the pointer type. Is there a right way to do this? Do I need
to manage this information in the program?
This is covered by questions 7.27 and 7.28 in the FAQ list.
Basically, yes, you need to keep track of this for yourself.
--
.
Relevant Pages
- Re: return string
... the const tells you that the field name is not going to be modified, the CString & ... is your responsibility to make sure you do not exceed the buffer size. ... use the obsolete data type 'char' for any purpose ... NEVER pass a pointer to a buffer without passing the size!!!!! ... (microsoft.public.vc.mfc) - How to get the PID and VID of a USB Mass Storage Device
... char driveName; ... memset (buffer, 0, sizeof (buffer)); ... char serialNumber; ... (microsoft.public.development.device.drivers) - some unanswered questions on C
... but what exactly is an uninitialised pointer? ... what i want to ask is that when i declare my buffer for fgets as ... my seg fault disappears... ... if the man page says that strcat returns a 'char *' and since the name ... (comp.unix.programmer) - Re: unusual behaviour of program under linux....
... but what exactly is an uninitialised pointer? ... what i want to ask is that when i declare my buffer for fgets as ... my seg fault disappears... ... if the man page says that strcat returns a 'char *' and since the name ... (comp.unix.programmer) - EXPLOIT Re: Pavuk Digest Authentication Buffer Overflow
... char *method; ... * the auth_digest pointer, the user pointer, and the buf pointer. ... * used as the strings that get printed into buffer. ... int conn ... (Bugtraq) |
|