Jump to content
  • Advertisement
Sign in to follow this  
Zanthos

stl map is eating away at my data!

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok.. here's the relevant code..
typedef std::map<int,SockBuffer*> SocketBuffers;
...
...
SocketBuffers mSockSocketBuffers;
...
...
if ((size == 0) || (!buffer))
 return false;
SockBuffer* newBuffer = new SockBuffer(buffer,size);
newBuffer->DebugDUMP(); // First debug output
mSockBuffers[clientsocket.GetSocketID()] = newBuffer;
newBuffer->DebugDUMP(); // Second debug output

First debug output:
elem[0] = asc:72(H)
elem[1] = asc:69(E)
elem[2] = asc:76(L)
elem[3] = asc:76(L)
elem[4] = asc:79(O)
elem[5] = asc:32( )
elem[6] = asc:83(S)
elem[7] = asc:65(A)
elem[8] = asc:73(I)
elem[9] = asc:68(D)
elem[10] = asc:32( )
elem[11] = asc:84(T)
elem[12] = asc:72(H)
elem[13] = asc:69(E)
elem[14] = asc:32( )
elem[15] = asc:80(P)
elem[16] = asc:67(C)
)lem[17] = asc:13(
elem[18] = asc:10(
)
elem[19] = asc:84(T)
elem[20] = asc:79(O)
elem[21] = asc:32( )
elem[22] = asc:84(T)
elem[23] = asc:72(H)
elem[24] = asc:69(E)
elem[25] = asc:32( )
elem[26] = asc:67(C)
elem[27] = asc:79(O)
elem[28] = asc:68(D)
elem[29] = asc:69(E)
elem[30] = asc:82(R)
)lem[31] = asc:13(
elem[32] = asc:10(
)
Second debug output:
elem[0] = asc:72(H)
elem[1] = asc:69(E)
elem[2] = asc:76(L)
elem[3] = asc:76(L)
elem[4] = asc:79(O)
elem[5] = asc:32( )
elem[6] = asc:83(S)
elem[7] = asc:65(A)
elem[8] = asc:73(I)
elem[9] = asc:68(D)
elem[10] = asc:32( )
elem[11] = asc:84(T)
elem[12] = asc:72(H)
elem[13] = asc:69(E)
elem[14] = asc:32( )
elem[15] = asc:80(P)
elem[16] = asc:67(C)
)lem[17] = asc:13(
elem[18] = asc:10(
)
elem[19] = asc:84(T)
elem[20] = asc:79(O)
elem[21] = asc:32( )
elem[22] = asc:84(T)
elem[23] = asc:72(H)
elem[24] = asc:69(E)
elem[25] = asc:32( )
elem[26] = asc:67(C)
elem[27] = asc:79(O)
elem[28] = asc:68(D)
elem[29] = asc:69(E)
elem[30] = asc:82(R)
)lem[31] = asc:13(
elem[32] = asc:4(♦)
For some reason, after I add the object to the map.. the last element is trashed, and I don't have a clue why :( It also only happens a block of text 33 bytes long, for any other size, it's ok. Does anybody have any ideas about what on earth is going on?

Share this post


Link to post
Share on other sites
Advertisement


int size = 10;
char* myBuffer = new char[size-1];
// You idiat! parameter for new is not upper array index. But ACTUAL
// size of array.


Ladies and Gentlemen.. I present..

THE GODFORSAKEN OFF BY 1 ERROR!

Share this post


Link to post
Share on other sites
Quote:
Original post by Zanthos
THE GODFORSAKEN OFF BY 1 ERROR!


O.B.ONE trained you well...

Share this post


Link to post
Share on other sites
Quote:
Original post by Fruny
Quote:
Original post by Zanthos
THE GODFORSAKEN OFF BY 1 ERROR!


O.B.ONE trained you well...


That's truly awesome, did you just made that up?

Share this post


Link to post
Share on other sites
Quote:
Original post by Hedos
That's truly awesome, did you just made that up?


No. The Obi-Wan error is an old joke.

Share this post


Link to post
Share on other sites
Quote:
Original post by Shannon Barber
Use std::string or std::vector<char> and resize/copy or insert.


I agree, why bother to use a base array type and risk the 'curse of O.B.ONE'?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!