P
Pep
I have been investigating a piece of code that deals with buffers and have
the real possibility that after a convoluted algorithm to determine the
length of the desired buffer is executed, the applcation could attempt to
allocate a buffer of zero size!
Could you tell me the effects of the following piece of code?
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc, char** argv)
{
char* ptr0 = new (char([0]));
char* ptr100 = new (char([100]));
cout << "ptr100 [" << ptr100 << "] ptr0 [" << ptr0 << "]" << endl;
sprintf(ptr100, "this is ptr100");
cout << "ptr100 " << ptr100 << endl;
sprintf(ptr0, "this is ptr0");
cout << "ptr0 " << ptr0 << endl;
printf("ptr100 [%p] ptr0 [%p]\n", ptr100, ptr0);
return(0);
}
This is the output of the applicattion
ptr100 [] ptr0 []
ptr100 this is ptr100
ptr0 this is ptr0
ptr100 [0x804a018] ptr0 [0x804a008]
the real possibility that after a convoluted algorithm to determine the
length of the desired buffer is executed, the applcation could attempt to
allocate a buffer of zero size!
Could you tell me the effects of the following piece of code?
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc, char** argv)
{
char* ptr0 = new (char([0]));
char* ptr100 = new (char([100]));
cout << "ptr100 [" << ptr100 << "] ptr0 [" << ptr0 << "]" << endl;
sprintf(ptr100, "this is ptr100");
cout << "ptr100 " << ptr100 << endl;
sprintf(ptr0, "this is ptr0");
cout << "ptr0 " << ptr0 << endl;
printf("ptr100 [%p] ptr0 [%p]\n", ptr100, ptr0);
return(0);
}
This is the output of the applicattion
ptr100 [] ptr0 []
ptr100 this is ptr100
ptr0 this is ptr0
ptr100 [0x804a018] ptr0 [0x804a008]