Re: style question,itoa
- From: Rainer Weikusat <rweikusat@xxxxxxxxxxx>
- Date: Thu, 24 Jan 2008 15:06:15 +0100
Syren Baran <sbaran@xxxxxxxxxxxxxxx> writes:
Robert Latest schrieb:
Syren Baran wrote:
David Schwartz schrieb:That's puzzling.
The caller has to 'free' 'retval' when it's done.Its intended that way.
It might be moreDont intend to change that. I´m comfortable with that.
sensible to have the caller pass in a buffer. This will allow the
caller to use a buffer on its stack if that makes the most sense for
it.
Not really. I dont like using arrays on the stack unless
i can know for certain they cant overflow. But thats my personal
style.
In this case, the conversion code wouldn't be using a stack allocated
value but the code calling it. Coincendetally, that would be the code
'knowing' what storage management requirements have to be met while
the called code (of a 'library-type' subroutine) cannot.
It is decidedly not 'your personal style' to write code with lots of
technically useless malloc and free calls, this is common for
'OOP'-programmers not usually working in memory-limited environment or
on performance, safety or security criticial code. The only real
accomplishments by doing so are slowing the code down without a gain,
inserting additional points of 'random'[*] failures and enabling
certain types of (malloc-implementation-based) exploits.
[*] Supposed to mean 'failing because of not easily
observable, dynamically changing external circumstances'.
..But you still need to add code that checks for malloc()s retun value.Theoreticly, yes.
No, practically, yes. malloc can and does fail and invocation of a
library-type subroutine should certainly not lead to
program-termination-by-SIGSEV at random. Instead, the caller should
have the ablity to deal with the failure.
Since the program i´ll use it cant eat up memory at an alarming rate i
prefer manual intervention (being able to tell the program not to
accecpt further connections and deny further functions calls that can
allocate memory).
Since the OS used to run your program manages the available RAM, no
matter how hard you try to ignore that, there is no way to determine a
priori when memory allocations would fail.
Aside from that even a nun-NULL return value from malloc does not
garantee that memory is available on Linux (see man 3 malloc).
But a NULL return values 'guarantees' that memory is not available.
.
- Follow-Ups:
- Re: style question,itoa
- From: Syren Baran
- Re: style question,itoa
- References:
- style question,itoa
- From: Syren Baran
- Re: style question,itoa
- From: David Schwartz
- Re: style question,itoa
- From: Syren Baran
- Re: style question,itoa
- From: Robert Latest
- Re: style question,itoa
- From: Syren Baran
- style question,itoa
- Prev by Date: Re: Can I run some root-priority-things within a shell script.
- Next by Date: Re: SCTP reference implementation
- Previous by thread: Re: style question,itoa
- Next by thread: Re: style question,itoa
- Index(es):
Relevant Pages
|