M
Mark McIntyre
char st1[1000],st2[650];
st2[650] = '\0';
st2 doesn't have a 651st element, so this will cause a crash of some
sort.
char st1[1000],st2[650];
st2[650] = '\0';
pete said:Suman said:In C, empty parentheses in the DEFINITION of a function
indicate that it takes no parameters. This definition would
provide a declaration, but not a prototype, for the defined function.
N869
Introduction
[#2] Certain features are obsolescent, which means that they
may be considered for withdrawal in future revisions of this
International Standard. They are retained because of their
widespread use, but their use in new implementations (for
implementation features) or new programs (for language
[6.11] or library features [7.26]) is discouraged.
6.11 Future language directions
6.11.4 Function declarators
[#1] The use of function declarators with empty parentheses
(not prototype-format parameter type declarators) is an
obsolescent feature.
6.11.5 Function definitions
[#1] The use of function definitions with separate parameter
identifier and declaration lists (not prototype-format
parameter type and identifier declarators) is an obsolescent
feature.
Stefan Klemm said:The length of a character array is determined by NULL.
Mark McIntyre said:char st1[1000],st2[650];st2[650] = '\0';
st2 doesn't have a 651st element, so this will cause a crash of some
sort.
Denis said:Defining functions in this way is deprecated and is still maintained
only for compatibility with old code. There is no good reason for not
using prototypes. Furthermore, adding 'void' improves consistency, since
a function _declaration_ with empty parentheses means a completely
different thing from a function _definition_ defined in this way.
Keith said:The length of a character array is determined by the length of the array.
The length of a string is determined by the position of the first null
character (if it doesn't have one, it's not a string). A null
character is sometimes referred to as NUL. NULL is (a macro that
expands to) a null pointer constant, which is a very different thing.
Chris said:No, it procedures undefined behaviour.
Mark McIntyre said:char st1[1000],st2[650];st2[650] = '\0';
st2 doesn't have a 651st element, so this will cause a crash of some
sort.
st2 doesn't have a 651st element, but this very likely *won't* cause a
crash. It's more likely to quietly write over some other piece of
memory, which may or may not be part of some other variable.
Mark said:On Wed, 17 Aug 2005 05:11:49 GMT, in comp.lang.c , Keith Thompson
I define that as a crash. It may be invisible, buy nevertheless you're
off the rails.
Mark McIntyre said:Mark McIntyre said:On 16 Aug 2005 01:25:29 -0700, in comp.lang.c , "Coder"
char st1[1000],st2[650];
st2[650] = '\0';
st2 doesn't have a 651st element, so this will cause a crash of some
sort.
st2 doesn't have a 651st element, but this very likely *won't* cause a
crash. It's more likely to quietly write over some other piece of
memory, which may or may not be part of some other variable.
I define that as a crash. It may be invisible, buy nevertheless you're
off the rails.
[/QUOTE]st2 doesn't have a 651st element, but this very likely *won't* cause a
crash. It's more likely to quietly write over some other piece of
memory, which may or may not be part of some other variable.
I define that as a crash. It may be invisible, buy nevertheless you're
off the rails.
Do you have some other term for what most other
people refer to as a crash?
At one place that I worked, they were very particular
and used the word "frozen" to describe what I call a "crash".
If I said my computer "crashed", they'd tell me where the broom was
and if I said my computer was "locked up", they'd ask me if I had a key.
Giannis said:Krishanu said:Giannis said:Coder wrote:
Patrick wrote:st2[650] = '\0';
Same mistake here. Moreover, strncpy() does copy the ending '\0' so
there is no need for the erroneous st2[650] = '\0';
No, not always. Read FAQ.
My mistake.. I should have said that it copies the '\0' when it reaches
it at the end of the word...
That's not any definition of "crash" in computer terms that I've ever
heard.
I don't call that a crash, and I don't think most people do either.
Regardless of terminology, the distinction is an important one.
A buffer overflow doesn't necessarily result in a visible failure.
Mark McIntyre said:*shrug* I can't be responsible for what you've heard.
I'm wondering what your point is - do you disagree that writing over
memory not belonging to you is a Bad Thing, and that it'll most likely
cause your app to fail in some way?
Mark said:shrug I can't be responsible for what you've heard.
I'm wondering what your point is - do you disagree that writing over
memory not belonging to you is a Bad Thing, and that it'll most likely
cause your app to fail in some way?
Because, presumably, you were trying to communicate something to theAnd this matters because?
Because, presumably, you were trying to communicate something to the
rest of us? Else why bother posting?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.