Energon
04-28-2001, 09:41 PM
I'm doing some messing around with strings... filling buffers with various things, etc... so I have something like this:
char buf[256];
memset((void*)buf, 0, strlen(buf));
sprintf(buf, "my name\n");
printf("%s", buf);
memset((void*)buf, 0, strlen(buf));
sprintf(buf, "this is not longer my name\n");
printf("%s", buf);
and after that second sprintf, the memory is still all 0s... do I need to, instead work with dynamic allocation instead of static? Since in what I'm working on is using the same buffer for a send() and a recv() call and I'm trying to 0 out the memory before I bring in the next buffer so in case it's smaller, it doesn't keep the old junk in there... it's just not quite working right...
I'm also having some problems with using strlen() in the size of the buffer to 0 out (it's overwriting memory it shouldn't be in the stack) if I use the Debug version in Windows (it's code that runs in both Linux and Windows)... does MSVC do something different in the debug version with memory allocation that causes this kind of problem?
char buf[256];
memset((void*)buf, 0, strlen(buf));
sprintf(buf, "my name\n");
printf("%s", buf);
memset((void*)buf, 0, strlen(buf));
sprintf(buf, "this is not longer my name\n");
printf("%s", buf);
and after that second sprintf, the memory is still all 0s... do I need to, instead work with dynamic allocation instead of static? Since in what I'm working on is using the same buffer for a send() and a recv() call and I'm trying to 0 out the memory before I bring in the next buffer so in case it's smaller, it doesn't keep the old junk in there... it's just not quite working right...
I'm also having some problems with using strlen() in the size of the buffer to 0 out (it's overwriting memory it shouldn't be in the stack) if I use the Debug version in Windows (it's code that runs in both Linux and Windows)... does MSVC do something different in the debug version with memory allocation that causes this kind of problem?