Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: passing uninitialised data |
| Date | 2012-09-14 16:45 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <50539778.9080204@verizon.net> (permalink) |
| References | <k2vhbd$fhj$1@speranza.aioe.org> <slrnk56vs4.7fv.angel+news@pearlgates.net> <50538247.40507@verizon.net> <slrnk574o8.7fv.angel+news@pearlgates.net> |
On 09/14/2012 04:26 PM, Angel wrote: > On 2012-09-14, James Kuyper <jameskuyper@verizon.net> wrote: >> On 09/14/2012 03:03 PM, Angel wrote: >>> On 2012-09-14, Mark <mark_cruzNOTFORSPAM@hotmail.com> wrote: >>>> Hello, >>>> >>>> I have quite a generic question. Suppose we work with fwrite(), or sendto() >>>> (not C standard function, but I'll assume everyone knows it) or any other >>>> API that takes a pointer to a buffer to transmit. When such a buffer is >>>> unititialised, does it in some ways impose undefined behaviour? >>> >>> Passing a pointer to a function that expects such is well defined, no >>> matter if the object the pointer points to is initialized or not. >> >> There's a reason why valgrind is giving him warning messages about this. >> It's quite trivial to write code that has undefined behavior when passed >> a pointer to an uninitialized buffer. What precisely is encompassed by >> the phrase "that expects such"? > > I mean that passing a pointer to a function that requires a pointer > argument is well-defined. (Assuming that the pointer is of a compatible > type, of course.) Maybe my wording is unclear; sorry about that. > English is not my first language. Sure, passing the pointer is itself well defined. Whether the behavior of the function is well defined when passed a pointer to uninitialized data is a very different question. > What I mean to say is that > > void f(int *arg1); > int x; > > f(&x); > > by itself does not cause undefined behaviour even though x is not > initialized. But if the function f() dereferences that pointer argument > and tries to something with the uninitialized integer object (increment > it by one, for example), that might cause undefined behaviour. > > I don't think we disagree here, do we? Again, sorry if I was unclear. He was asking about the behavior of executing the function, not just the behavior of the function call itself, and he was asking very specifically about functions which will dereference the pointer. fwrite() certainly does so; and the function named sendto() that's available on my desktop does as well. The fact that he bothered to ask about it suggests that his sendto() probably does so as well, even if it's a different from the one on my machine. As a result, your answer was, at best, incomplete, almost to the point of uselessness. However, since they dereference the pointers using lvalues of character type, the behavior is well-defined, at least according to my understanding. Ben's take on that issue is a bit closer to yours.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
passing uninitialised data "Mark" <mark_cruzNOTFORSPAM@hotmail.com> - 2012-09-14 11:09 -0400
Re: passing uninitialised data Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-14 11:45 -0400
Re: passing uninitialised data James Kuyper <jameskuyper@verizon.net> - 2012-09-14 11:48 -0400
Re: passing uninitialised data Barry Schwarz <schwarzb@dqel.com> - 2012-09-14 10:34 -0700
Re: passing uninitialised data James Kuyper <jameskuyper@verizon.net> - 2012-09-14 14:34 -0400
Re: passing uninitialised data Barry Schwarz <schwarzb@dqel.com> - 2012-09-14 15:26 -0700
Re: passing uninitialised data James Kuyper <jameskuyper@verizon.net> - 2012-09-17 12:18 -0400
Re: passing uninitialised data Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-17 11:52 -0800
Re: passing uninitialised data pete <pfiland@mindspring.com> - 2012-12-17 16:21 -0500
Re: passing uninitialised data Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-20 10:23 -0800
Re: passing uninitialised data pete <pfiland@mindspring.com> - 2012-12-20 21:17 -0500
Re: passing uninitialised data Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-21 09:20 -0800
Re: passing uninitialised data pete <pfiland@mindspring.com> - 2012-12-21 14:52 -0500
Re: passing uninitialised data glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-21 21:19 +0000
Re: passing uninitialised data Shao Miller <sha0.miller@gmail.com> - 2012-12-17 19:45 -0500
Re: passing uninitialised data Angel <angel+news@spamcop.net> - 2012-09-14 19:03 +0000
Re: passing uninitialised data James Kuyper <jameskuyper@verizon.net> - 2012-09-14 15:15 -0400
Re: passing uninitialised data Angel <angel+news@spamcop.net> - 2012-09-14 20:26 +0000
Re: passing uninitialised data James Kuyper <jameskuyper@verizon.net> - 2012-09-14 16:45 -0400
Re: passing uninitialised data Kaz Kylheku <kaz@kylheku.com> - 2012-09-14 21:19 +0000
csiph-web