SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef UNICODE
  2. #define UNICODE
  3. #endif
  4.  
  5. #include <iostream>
  6. #include <Windows.h>
  7. #include <queue>
  8.  
  9. using namespace std;
  10.  
  11. void addSomeContent(queue<TCHAR*> &s)
  12. {
  13.     static int counter=0;
  14.     TCHAR* buffer;
  15.  
  16.     buffer = new TCHAR[250];
  17.  
  18.     wsprintf(buffer,TEXT("foo%d"),counter++);
  19.  
  20.     s.push(buffer);
  21.  
  22.     if(counter < 100000)
  23.         addSomeContent(s);
  24.     //breakpoint placed here is never reached
  25. }
  26.  
  27. int main (void)
  28. {
  29.     queue<TCHAR*> strings;
  30.  
  31.     addSomeContent(strings); //crash point
  32.  
  33.     while(!strings.empty())
  34.     {  
  35.         wcout<<strings.front()<<endl;
  36.         delete [] strings.front();
  37.         strings.pop();
  38.     }
  39.  
  40.     wcout<<TEXT("Finish!n");
  41.  
  42.     system("pause");
  43.     return (0);
  44. }
  45.    
  46. #include <iostream>
  47. #include <queue>
  48. #include <cstdio>
  49.  
  50. using namespace std;
  51.  
  52. void addSomeContent(queue<char*> &s)
  53. {
  54.     static int counter = 0;
  55.     char *buffer = new char[250];
  56.  
  57.     sprintf(buffer, "foo%d", counter++);
  58.  
  59.     s.push(buffer);
  60.  
  61.     if (counter < 100000)
  62.         addSomeContent(s);
  63. }
  64.  
  65. int main(void)
  66. {
  67.     queue<char*> strings;
  68.  
  69.     addSomeContent(strings);
  70.  
  71.     while (!strings.empty())
  72.     {
  73.         cout << strings.front() << endl;
  74.         delete[] strings.front();
  75.         strings.pop();
  76.     }
  77.  
  78.     cout << "Finish!" << endl;
  79.  
  80.     return 0;
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top