Re: [Dev-C++] address 0x33313031 out of bounds
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2002-12-12 07:57:48
|
Only, only, only use strcpy when you KNOW that your receiving buffer is
big enough. Are you sure that argv[1] only contains 2 characters? If not,
the copy to type will use unallocated stack space. As soon as you call
func(), the end of the string will be lost.
/Per W
On Thu, 12 Dec 2002 ma...@mm... wrote:
> i'm having a bit of a problem. i get to a particular line in my program and
> i crashes no matter how i try and get it to work. the relevant code
> basically goes.....
>
> void func (char *type)
> {
> char key[10];
>
> printf("type is currently %s", type);
>
> sprintf(key, "last%s", type); //crashes at this point
> printf("key is currently %s", key);
> }
>
> int main (int argc, char *argv[])
> {
> char type[3];
> strcpy(type,argv[1]);
> func(type);
> }
>
> if i watch type, after it crashes it tells me that address 0x33313031 is
> out of bounds. i can't see that i'm doing anything wrong. what does the
> error actually mean?
>
> thanx in advance
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:
> With Great Power, Comes Great Responsibility
> Learn to use your power at OSDN's High Performance Computing Channel
> http://hpc.devchannel.org/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|