Hello
I have the following "easy" problem. I have a string which contains
1000 chars.
Now my task is to cut the string at his 650 position. I tried strcpy,
to copy the first 650 chars into another string but I got a memory
access error. I have heard that i can use this function only to copy
500 chars is that true? What other options do i have?
Best Regards
Patrick 44 1910
In article <11**********************@g43g2000cwa.googlegroups .com>,
Patrick <gr********@yahoo.de> wrote: I have the following "easy" problem. I have a string which contains 1000 chars. Now my task is to cut the string at his 650 position. I tried strcpy, to copy the first 650 chars into another string but I got a memory access error. I have heard that i can use this function only to copy 500 chars is that true? What other options do i have?
No, that is NOT true. strcpy's lower limits are in the gigabyte range
when there are any limits at all. [After a few gigabytes, you
start overflowing 32 bit pointers...]
Note that if you only want to copy the leading part of a string,
strcpy is not the right function to use. I suggest you reexamine
the documentation for functions that have the letter 'n' in their
names.
--
This signature intentionally left... Oh, darn!
I tried it with strncpy but i get again a memory access violation....
Patrick wrote: Hello
I have the following "easy" problem. I have a string which contains 1000 chars. Now my task is to cut the string at his 650 position. I tried strcpy, to copy the first 650 chars into another string but I got a memory access error. I have heard that i can use this function only to copy 500 chars is that true? What other options do i have?
Best Regards Patrick
char *strncpy(char * restrict s1, const char * restrict s2, size_t n)
Make sure that you understand the function correctly.
Krishanu
Will you please write how your program exactly looks like?
Patrick wrote: I tried it with strncpy but i get again a memory access violation....
Patrick wrote: I tried it with strncpy but i get again a memory access violation....
1. Quote context.
2. Are you sure you are allocating memory before calling str*cpy()?
And, remember, you need to allocate strlen(whatever) + 1 chars, to make
room for the terminating null character. Also, post the offending code.
Am Mon, 15 Aug 2005 23:56:01 -0700 schrieb Patrick: Hello
I have the following "easy" problem. I have a string which contains 1000 chars. Now my task is to cut the string at his 650 position.
string[650] = '\0';
I tried strcpy, to copy the first 650 chars into another string but I got a memory access error.
man strncpy
Does the second string have enough memory?
I have heard that i can use this function only to copy 500 chars is that true?
The length of a character array is determined by NULL. The limitation is
the free heap space.
What other options do i have?
Read a good C book.
Best Regards,
Stefan
Patrick wrote: Hello
I have the following "easy" problem. I have a string which contains 1000 chars. Now my task is to cut the string at his 650 position. I tried strcpy, to copy the first 650 chars into another string but I got a memory access error. I have heard that i can use this function only to copy 500 chars is that true? What other options do i have?
Best Regards Patrickint
I think the following code solves ur problem...
main()
{
char st1[1000],st2[650];
int i;
for (i = 0; i < 1000; i++)
st1[i] = 'a';
st1[i] = '\0';
strncpy(st2,st1,sizeof(st2));
st2[650] = '\0';
for (i = 0; st2[i] != '\0'; i++)
printf("%d\t%c\n",i,st2[i]);
printf("%d",i);
}
Coder wrote: Patrick wrote:
Hello
I have the following "easy" problem. I have a string which contains 1000 chars. Now my task is to cut the string at his 650 position. I tried strcpy, to copy the first 650 chars into another string but I got a memory access error. I have heard that i can use this function only to copy 500 chars is that true? What other options do i have?
Best Regards Patrickint
I think the following code solves ur problem...
When you answer, try to be sure that what you are proposing works ok...
main() {
Shoyld always be
int main(void)
{
char st1[1000],st2[650]; int i;
for (i = 0; i < 1000; i++) st1[i] = 'a';
st1[i] = '\0';
You have already passed the limits of your st1... You try to access
st1[1000] which is wrong and produces an error in a well-written system.. strncpy(st2,st1,sizeof(st2)); st2[650] = '\0';
Same mistake here. Moreover, strncpy() does copy the ending '\0' so
there is no need for the erroneous st2[650] = '\0'; for (i = 0; st2[i] != '\0'; i++) printf("%d\t%c\n",i,st2[i]);
printf("%d",i);
And add a
return 0;
}
--
one's freedom stops where other's begin
Giannis Papadopoulos http://dop.users.uth.gr/
University of Thessaly
Computer & Communications Engineering dept.
Coder wrote: Patrick wrote: Hello
I have the following "easy" problem. I have a string which contains 1000 chars. Now my task is to cut the string at his 650 position. I tried strcpy, to copy the first 650 chars into another string but I got a memory access error. I have heard that i can use this function only to copy 500 chars is that true? What other options do i have?
Best Regards Patrickint I think the following code solves ur problem...
No. It doesn't.
To start with, you need a few basic headers:
#include <stdio.h>
#include <string.h>
main()
So, what did you say, your code compiled on?
Use
int main() { char st1[1000],st2[650]; int i;
for (i = 0; i < 1000; i++) st1[i] = 'a';
st1[i] = '\0';
i is now thousand, and accessing out-of-bounds isn't correct.
I warned about *this* thing only in my previous post, please
take the time out to read the whole thread. Please! strncpy(st2,st1,sizeof(st2)); st2[650] = '\0';
for (i = 0; st2[i] != '\0'; i++) printf("%d\t%c\n",i,st2[i]);
Indentation is most welcome, btw.
printf("%d",i);
Hm. No \n at end of printf(). You sure you know what you are
doing?
Also a little
return 0;
wouldn't hurt. }
Giannis Papadopoulos wrote: Coder wrote: Patrick wrote:
<snip>
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. http://www.eskimo.com/~scs/C-faq/q13.2.html
Krishanu
"Patrick" <gr********@yahoo.de> wrote:
# Hello
#
# I have the following "easy" problem. I have a string which contains
# 1000 chars.
# Now my task is to cut the string at his 650 position. I tried strcpy,
# to copy the first 650 chars into another string but I got a memory
# access error. I have heard that i can use this function only to copy
Did you allocate enough space? Malloc for a copy of string s is like
malloc(strlen(s)+1)
The +1 being space for the zero byte terminator.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
Mention something out of a Charleton Heston movie, and suddenly
everybody's a theology scholar.
Krishanu Debnath wrote: Giannis Papadopoulos wrote:
Coder wrote:
Patrick wrote:
<snip> 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.
http://www.eskimo.com/~scs/C-faq/q13.2.html
Krishanu
My mistake.. I should have said that it copies the '\0' when it reaches
it at the end of the word...
However, st2[650] = '\0' is bad....
--
one's freedom stops where other's begin
Giannis Papadopoulos http://dop.users.uth.gr/
University of Thessaly
Computer & Communications Engineering dept.
Suman wrote: Coder wrote: Patrick wrote: Hello
I have the following "easy" problem. I have a string which contains 1000 chars. Now my task is to cut the string at his 650 position. I tried strcpy, to copy the first 650 chars into another string but I got a memory access error. I have heard that i can use this function only to copy 500 chars is that true? What other options do i have?
Best Regards Patrickint
I think the following code solves ur problem... No. It doesn't.
To start with, you need a few basic headers:
#include <stdio.h> #include <string.h>
main()
So, what did you say, your code compiled on? Use
int main() { char st1[1000],st2[650]; int i;
for (i = 0; i < 1000; i++) st1[i] = 'a';
st1[i] = '\0';
i is now thousand, and accessing out-of-bounds isn't correct. I warned about *this* thing only in my previous post, please take the time out to read the whole thread. Please!
strncpy(st2,st1,sizeof(st2)); st2[650] = '\0';
for (i = 0; st2[i] != '\0'; i++) printf("%d\t%c\n",i,st2[i]);
Indentation is most welcome, btw.
printf("%d",i);
Hm. No \n at end of printf(). You sure you know what you are doing?
Also a little return 0; wouldn't hurt. }
missing int in front of main and missing return are cut-copy-paste
errors ... i posted the code in haste sorrt for that . Anyway thanks
for pointing other errors ... does accessing 1000th element produce
out-of-bounds error ? If u declare a 1000 byte long string u can store
1000 characters from 0th element to 999th element and 1000th element
contains a NULL.Since I used a loop to store thousand 'a's I used a
NULL in 1000 th element to terminate the string.Isn't that acceptable ?
Coder wrote: missing int in front of main and missing return are cut-copy-paste errors ... i posted the code in haste sorrt for that . Anyway thanks for pointing other errors ... does accessing 1000th element produce out-of-bounds error ?
No, it procedures undefined behaviour.
If u declare a 1000 byte long string u can store
"you". Not "u".
You can't "declare a 1000 byte long string" in C. You can
declare a character array of 1000 elements, if you like ...
1000 characters from 0th element to 999th element and 1000th element contains a NULL.
.... but that has elements 0..999 only.
--
Chris "electric hedgehog" Dollin
Stross won one! Farah won one! Langford won TWO!
Suman wrote: Coder wrote: main()
So, what did you say, your code compiled on? Use
int main()
No. Use int main(void).
Denis Kasak wrote: Suman wrote: Coder wrote: >> main()
So, what did you say, your code compiled on? Use
int main()
No. Use int main(void).
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.
Suman wrote: Denis Kasak wrote: Suman wrote: Coder wrote: >> > main()
So, what did you say, your code compiled on? Use
int main()
No. Use int main(void).
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.
--
pete
Patrick wrote: I tried it with strncpy but i get again a memory access violation....
Please include context in your replies. Google's interface is broken by
default. Others here have posted how to do it correctly. Search the
archives.
In any case, if you're still getting access violations, then you're
doing something wrong. Post a sample of code that fails.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Suman wrote: 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.
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.
-- Denis
On 16 Aug 2005 01:25:29 -0700, in comp.lang.c , "Coder"
<ra**********@gmail.com> wrote: char st1[1000],st2[650];
st2[650] = '\0';
st2 doesn't have a 651st element, so this will cause a crash of some
sort.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
pete wrote: Suman wrote: Denis Kasak wrote: Suman wrote: > Coder wrote: >> >> main() > > So, what did you say, your code compiled on? > Use > > int main()
No. Use int main(void).
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.
Thanks, pete. I'll keep that in mind.
Stefan Klemm <st**********@mra.man.de> writes:
[...] The length of a character array is determined by NULL.
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.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mark McIntyre <ma**********@spamcop.net> writes: On 16 Aug 2005 01:25:29 -0700, in comp.lang.c , "Coder" <ra**********@gmail.com> wrote:
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.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Denis Kasak wrote: Suman wrote: 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.
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.
Concur. I took a little liberty ... ;)
Keith Thompson wrote: Stefan Klemm <st**********@mra.man.de> writes: [...] The length of a character array is determined by NULL.
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.
-- Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst> San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst> We must do something. This is something. Therefore, we must do this.
Thanks Keith for enlightening me on the difference between a null
character and a NULL macro.
Chris Dollin wrote: Coder wrote:
missing int in front of main and missing return are cut-copy-paste errors ... i posted the code in haste sorrt for that . Anyway thanks for pointing other errors ... does accessing 1000th element produce out-of-bounds error ?
No, it procedures undefined behaviour.
Hell's teeth, what an ... interesting ... piece of autotypoing.
"produces".
--
Chris "proofreading?" Dollin
Stross won one! Farah won one! Langford won TWO!
On Wed, 17 Aug 2005 05:11:49 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote: Mark McIntyre <ma**********@spamcop.net> writes: On 16 Aug 2005 01:25:29 -0700, in comp.lang.c , "Coder" <ra**********@gmail.com> wrote:
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.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mark McIntyre wrote: On Wed, 17 Aug 2005 05:11:49 GMT, in comp.lang.c , Keith Thompson <ks***@mib.org> wrote: 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.
That's not any definition of "crash" in computer terms that I've ever
heard.
Brian
Mark McIntyre <ma**********@spamcop.net> writes: On Wed, 17 Aug 2005 05:11:49 GMT, in comp.lang.c , Keith Thompson <ks***@mib.org> wrote:
Mark McIntyre <ma**********@spamcop.net> writes: On 16 Aug 2005 01:25:29 -0700, in comp.lang.c , "Coder" <ra**********@gmail.com> wrote:
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.
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.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
In article <ha********************************@4ax.com>,
Mark McIntyre <ma**********@spamcop.net> wrote: 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?
-- Richard
Richard Tobin wrote:
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.
--
pete
On Thu, 18 Aug 2005 00:43:44 +0000, pete wrote: Richard Tobin wrote:
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.
Did you direct them to the microwave?
-- http://members.dodo.com.au/~netocrat
Giannis Papadopoulos wrote: Krishanu Debnath wrote: Giannis Papadopoulos wrote: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...
It doesn't exactly do that either. When it reaches the end of the
source, it zero-fills the rest of the target buffer. If it doesn't
reach the end of the source, no zeroes get written at all.
On 17 Aug 2005 22:59:51 GMT, in comp.lang.c , "Default User"
<de***********@yahoo.com> wrote: Mark McIntyre wrote:
On Wed, 17 Aug 2005 05:11:49 GMT, in comp.lang.c , Keith Thompson <ks***@mib.org> wrote:
> 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.
That's not any definition of "crash" in computer terms that I've ever heard.
*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 McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
On Wed, 17 Aug 2005 23:05:11 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote: I don't call that a crash, and I don't think most people do either.
And this matters because?
Regardless of terminology, the distinction is an important one. A buffer overflow doesn't necessarily result in a visible failure.
Sure. Your app silently crashed, and is now no longer actually
operating properly...
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mark McIntyre <ma**********@spamcop.net> writes: On 17 Aug 2005 22:59:51 GMT, in comp.lang.c , "Default User" <de***********@yahoo.com> wrote:
Mark McIntyre wrote:
On Wed, 17 Aug 2005 05:11:49 GMT, in comp.lang.c , Keith Thompson <ks***@mib.org> wrote:
> 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.
That's not any definition of "crash" in computer terms that I've ever heard.
*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?
Certainly a silent failure is bad -- typically worse than a visible
failure such the program dying wit a segmentation fault.
My point was simply that I found your use of the term "crash"
confusing. As I understand the term, if the program quietly continues
running incorrectly, it hasn't "crashed"; a "crash" is a very visible
failure. (At least one other person made the same point.)
This usage of the term is consistent with the older real-world
meaning. If I'm driving down the highway and my brakes fail, the car
is not operating correctly -- but it hasn't "crashed" until it
actually runs into something.
If everybody but me uses the term your way, I'll have to be more
careful about how I use it.
Conversely, if everybody but you uses the term my way -- well, I'll
leave the corollary to the reader.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mark McIntyre wrote: On 17 Aug 2005 22:59:51 GMT, in comp.lang.c , "Default User" <de***********@yahoo.com> wrote:
Mark McIntyre wrote:
I define that as a crash. It may be invisible, buy nevertheless you're >> off the rails. That's not any definition of "crash" in computer terms that I've ever heard.
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?
I'm wondering what your point is, redefining terms to something odd and
unnatural.
A crash is a crash, and a silent overwrite of memory ain't a crash. It
may lead to one down the line, but that's another tale.
Brian
On Thu, 18 Aug 2005 23:13:48 +0100, Mark McIntyre
<ma**********@spamcop.net> wrote: On Wed, 17 Aug 2005 23:05:11 GMT, in comp.lang.c , Keith Thompson <ks***@mib.org> wrote:
I don't call that a crash, and I don't think most people do either.
And this matters because?
Because, presumably, you were trying to communicate something to the
rest of us? Else why bother posting?
--
Al Balmer
Balmer Consulting re************************@att.net
On Thu, 18 Aug 2005 16:06:42 -0700, in comp.lang.c , Alan Balmer
<al******@att.net> wrote: On Thu, 18 Aug 2005 23:13:48 +0100, Mark McIntyre <ma**********@spamcop.net> wrote:
On Wed, 17 Aug 2005 23:05:11 GMT, in comp.lang.c , Keith Thompson <ks***@mib.org> wrote:
I don't call that a crash, and I don't think most people do either.
And this matters because? Because, presumably, you were trying to communicate something to the rest of us? Else why bother posting?
Actually I was trying to communicate with the OP, and frankly I think
keith was being extremely anal. I assume we don't disagree that
scribbling over memory that doesn't belong to you is a Bad Thing, and
that its most likely to cause your app to start misbehaving.
Furthermore, any sensible OS would immediately complain if you did it,
and try to terminate your app. If you and others choose to apply the
word "crash" only to cases where the app visibly falls over or
generates bluescreens or whatever, thats your privilege.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
On Thu, 18 Aug 2005 22:44:04 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote: My point was simply that I found your use of the term "crash" confusing. As I understand the term, if the program quietly continues running incorrectly, it hasn't "crashed"; a "crash" is a very visible failure. (At least one other person made the same point.)
This usage of the term is consistent with the older real-world meaning. If I'm driving down the highway and my brakes fail, the car is not operating correctly -- but it hasn't "crashed" until it actually runs into something.
I've several times encountered systems which were still running, but
no longer responsive to user input, didn't do what they were supposed
to, or otherwise behaved unsuitably. As far as I'm concerned, the app
had crashed, the fact that it didn't pop up a bluescreen, produce a
coredump or advise me via cutesy dialogs didn't make it any the less
crashed.
But whatever. Its amazing that a throwaway remark can generate such
sound and fury, and still signify nothing. Here's what I originally
said, and which has stirred up such ire: char st1[1000],st2[650];
.. st2[650] = '\0';
st2 doesn't have a 651st element, so this will cause a crash of some sort.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mark McIntyre <ma**********@spamcop.net> writes:
[snip] But whatever. Its amazing that a throwaway remark can generate such sound and fury, and still signify nothing. Here's what I originally said, and which has stirred up such ire:
char st1[1000],st2[650]; . st2[650] = '\0';
st2 doesn't have a 651st element, so this will cause a crash of some sort.
And my point is that it's just as likely to quietly do just what it
would have done if st2 actually had 651 elements. It's undefined
behavior; it may or may not cause any misbehavior at all, visible or
otherwise.
If you write past the end of an array, you *might* step on memory that
your process doesn't own, but it's just as likely to step on memory
that's part of another variable (with arbitrarily bad consequences) or
on a gap between variables (with, most likely, no consequences at
all).
Try this program:
#include <stdio.h>
int main(void)
{
char st1[1000],st2[650];
st2[650] = '\0';
printf("st2[650] = %d\n", st2[650]);
return 0;
}
For me, it simply printed "st2[650] = 0" followed by a newline. Does
it "crash" when you run it?
If you invoke undefined behavior, you cannot depend on the
implementation to catch it for you.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
On Fri, 19 Aug 2005 19:40:31 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote: Mark McIntyre <ma**********@spamcop.net> writes:st2 doesn't have a 651st element, so this will cause a crash of some sort. And my point is that it's just as likely to quietly do just what it would have done if st2 actually had 651 elements.
Unfortunately however, your point came across (to me) as:
"Ha, I'm feeling excessively pedantic and will make a big thing of the
fact that it needn't actually terminate your app" but perhaps I too
was feeling overly sensitive.
For me, it simply printed "st2[650] = 0" followed by a newline.
How do you know that this is all it did? Perhaps that byte was used by
a daemon which is now quietly writing logs to "\0ogfile.log". Or
perhaps your password is now "passw\0rd"....
Does it "crash" when you run it?
FWIW, where did I say that the app itself would crash? Of course, this
is just me being pedantic too.
If you invoke undefined behavior, you cannot depend on the implementation to catch it for you.
Absolutely.
It seems to me however that your statement about what it simply did
for you, is kinda assuming /your/ OS has done just that !
End of pedanticism and anality I hope...
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mark McIntyre <ma**********@spamcop.net> writes: On Fri, 19 Aug 2005 19:40:31 GMT, in comp.lang.c , Keith Thompson <ks***@mib.org> wrote:Mark McIntyre <ma**********@spamcop.net> writes:st2 doesn't have a 651st element, so this will cause a crash of some sort. And my point is that it's just as likely to quietly do just what it would have done if st2 actually had 651 elements.
Unfortunately however, your point came across (to me) as: "Ha, I'm feeling excessively pedantic and will make a big thing of the fact that it needn't actually terminate your app" but perhaps I too was feeling overly sensitive.
I genuinely did not understand what you meant, and I don't believe I'm
the only one. The plain meaning of what you originally wrote, as I
understood it, was that the program would certainly fail in some
visible way. I understand now that that's not what you meant. For me, it simply printed "st2[650] = 0" followed by a newline.
How do you know that this is all it did? Perhaps that byte was used by a daemon which is now quietly writing logs to "\0ogfile.log". Or perhaps your password is now "passw\0rd"....
Because I know enough about the system I'm using to be reasonably
confident that things like that are extremly unlikely consequences of
that particular instance of undefined behavior. This knowledge is
off-topic, of course; the C standard makes no such guarantees. Does it "crash" when you run it?
FWIW, where did I say that the app itself would crash? Of course, this is just me being pedantic too.
Ok, you said "this will cause a crash of some sort". Did it do so? If you invoke undefined behavior, you cannot depend on the implementation to catch it for you.
Absolutely.
It seems to me however that your statement about what it simply did for you, is kinda assuming /your/ OS has done just that !
I don't follow your reasoning. Neither the OS, the C implementation,
nor the program itself "caught" the undefined behavior. The program
(I'm reasonably sure) simpy wrote a value to an unused byte. Are you
using "catch" in some sense that I'm not familiar with?
End of pedanticism and anality I hope...
I hope not. 8-)}
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
On Mon, 22 Aug 2005 22:42:37 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote: I genuinely did not understand what you meant, and I don't believe I'm the only one.
For which my apologies.
The plain meaning of what you originally wrote, as I understood it, was that the program would certainly fail in some visible way. I understand now that that's not what you meant.
Actually what I meant was "hey, don't do that, if you persist to do
it I guarantee at some time in your career, you'll become highly
embarassed, unemployed or possibly even dead, depending on the nature
of the crash and the circumstances surrounding it"
Ok, you said "this will cause a crash of some sort". Did it do so?
I've no idea as I'm not sitting in front of your computer. Have you
checked your phone bill yet? Is the digital TV playing up? Are you
being followed by the FBI? End of pedanticism and anality I hope...
I hope not. 8-)}
Well, at least in this context !
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =---- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Charles Herman |
last post by:
I am using push_back to place a class object into a vector. This class
contains data members that are pointers to a char string. When I use
push_back, I believe a copy of the object is first made,...
|
by: Edward Diener |
last post by:
Coming from the C++ world I can not understand the reason why copy
constructors are not used in the .NET framework. A copy constructor creates
an object from a copy of another object of the same...
|
by: Matt Garman |
last post by:
What is the "best" way to copy a vector of strings to an array of
character strings? By "best", I mean most elegantly/tersely written,
but without any sacrifice in performance.
I'm writing an...
|
by: SIgnOff |
last post by:
What the fastest way to copy strings from file to a vector in STL?
|
by: Simon Schaap |
last post by:
Hello,
I have encountered a strange problem and I hope you can help me to
understand it. What I want to do is to pass an array of chars to a
function that will split it up (on every location where...
|
by: DumberThanSnot |
last post by:
is there a faster way to copy an ArrayList of strings to a string other than
a tight loop.
In it's most simple terms, I'm currently using something like this...
----------------------------
...
|
by: Desmond Cassidy |
last post by:
Hi,
I'm sure this has been asked several times before but I'll risk it ;-)
If I wish to save an Arraylist to another Arraylist and work on te
original without affecting the contents of the new...
|
by: Fred |
last post by:
Hi:
I've got the following request: (suppose the required head file
is included)
vector<stringvec;
// ..........
// push some items into vec
string str; // here I want to
copy some range...
|
by: Jeffrey Barish |
last post by:
(Pdb) myclass
MyClass( 0, 0, 'A string', 123.45)
(Pdb) copy.copy(myclass)
*** TypeError: TypeError('__new__() takes at least 4 arguments (2 given)',)
I see 4 arguments (actually, 5 because...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |