home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,360 of 33,346   
   Vaclav Haisman to All   
   Re: codecvt problem   
   05 Jun 11 21:41:54   
   
   b2562e14   
   From: v.haisman@sh.cvut.cz   
      
   RafaĊ‚ Moniuszko wrote, On 5.6.2011 15:25:   
   [...]   
   > ==9451== Conditional jump or move depends on uninitialised value(s)   
   I think that this is likely because of uninitialized mystate variable. Add   
   #include  and do std::memset (&mystate, 0, sizeof(mystate));:   
      
      
   // codecvt::out example   
   #include    
   #include    
   #include    
   #include  // XXX   
      
   using namespace std;   
      
   int main ()   
   {   
     locale mylocale;   
     mbstate_t mystate;   
      
     wstring mywstring;   
      
     const codecvt& myfacet =   
       use_facet >(mylocale);   
      
     codecvt::result myresult;   
      
     cout << "Enter sentence: ";   
     getline (wcin,mywstring);   
      
     size_t length = mywstring.length();   
     char* pstr= new char [length+1];   
      
     const wchar_t* pwc;   
     char* pc;   
      
     std::memset (&mystate, 0, sizeof(mystate)); // XXX   
     // translate characters:   
     myresult = myfacet.out (mystate,   
         mywstring.c_str(), mywstring.c_str()+length+1, pwc,   
         pstr, pstr+length+1, pc);   
      
     if ( myresult == codecvt::ok )   
   	  cout << "Translation successful: " << pstr << endl;   
     return 0;   
   }   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca