I have a code where i compile & load it in vxworks machine, i see the buffer overflow.
#include<strstream>
#include<iostream>
#include<sstream>
using namespace std;
ostrstream *strm = 0;
int newcout()
{
if(strm == 0)
{
strm = new ostrstream();
}
while(1)
{
(*strm)<<".VXworks_print"<<endl;
}
return 0;
}
The problem here is, the memory request keeps on doublingfor every loop in while.
[maxBlock = 8497968/ allocSize = 12700]
[maxBlock = 8485176/ allocSize = 25500]
[maxBlock = 8459584/ allocSize = 51100]
[maxBlock = 8408392/ allocSize = 102300]
[maxBlock = 8306000/ allocSize = 204700]
[maxBlock = 8101208/ allocSize = 409500]
[maxBlock = 7691616/ allocSize = 819100]
[maxBlock = 7086744/ allocSize = 1638300]
[maxBlock = 7086744/ allocSize = 3276700]
[maxBlock = 7086744/ allocSize = 6553500]
[maxBlock = 8497288/ allocSize = 13107100]
when the alllocation request is going beyond max available block, it is resulting in trap.
I think we are seeing this behavior because of re-using ostrstream object.
How to correct this behavior?