help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] Re: 64-bit weirdness with STL?


From: Robert Heller
Subject: [SOLVED] Re: 64-bit weirdness with STL?
Date: Sat, 27 Feb 2010 07:00:42 -0600

At Sat, 27 Feb 2010 12:36:47 +0800 Michael Tsang <miklcct@gmail.com> wrote:

> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Robert Heller wrote:
> 
> > I have some code that is crashing with bad pointer problems.  The code,
> > as far as I can tell, is not doing anything that is wrong.  The code
> > compiles and runs just fine on a 32-bit system (same compiler, same
> > version of libstdc++).  It compiles just fine on the 64-bit machine, but
> > crashes somewhat randomly with pointer problems.  The problem seems to
> > be specific to the basic_string template class.
> > 
> > I am using CentOS 5.4 on both machines:
> > 
> > gollum.deepsoft.com% uname -a
> > Linux gollum.deepsoft.com 2.6.18-164.11.1.el5 #1 SMP Wed Jan 20 07:39:04
> > EST 2010 i686 i686 i386 GNU/Linux
> > sauron.deepsoft.com% uname -a
> > Linux sauron.deepsoft.com 2.6.18-164.11.1.el5xen #1 SMP Wed Jan 20
> > 08:06:04 EST 2010 x86_64 x86_64 x86_64 GNU/Linux
> > 
> > And the same *stock* CentOS C++ compiler and STL library:
> > 
> > gollum.deepsoft.com% rpm -q --qf '%{NAME}-%{VERSION}.%{RELEASE}.%{ARCH}\n'
> > gcc-c++ libstdc++ libstdc++-devel gcc-c++-4.1.2.46.el5_4.2.i386
> > libstdc++-4.1.2.46.el5_4.2.i386
> > libstdc++-devel-4.1.2.46.el5_4.2.i386
> > sauron.deepsoft.com% rpm -q --qf '%{NAME}-%{VERSION}.%{RELEASE}.%{ARCH}\n'
> > gcc-c++ libstdc++ libstdc++-devel gcc-c++-4.1.2.46.el5_4.2.x86_64
> > libstdc++-4.1.2.46.el5_4.2.x86_64
> > libstdc++-4.1.2.46.el5_4.2.i386
> > libstdc++-devel-4.1.2.46.el5_4.2.x86_64
> > 
> > Is there something I should *specificly* look for?
> > 
> > I changed
> > 
> > line += ","+trim(buffer);
> > to
> > line = line + "," + trim(buffer);
> > 
> > In one place (it seemed that the += operator for string was misbehaving).
> > This only delayed the crash to later in the code.
> > 
> > line and buffer are basic_string objects.  Trim is:
> > 
> > /*
> >  * Trim excess whitespace characters from both ends of a string.
> >  */
> >              
> > const string System::whitespace = " \t\r\n";
> >  
> > string System::trim(string line) const {
> >         string::size_type pos1, pos2;
> >         for (pos1 = 0; pos1 < line.size() &&
> >                        whitespace.find(line[pos1]) != string::npos;pos1++)
> >                        ;
> >         for (pos2 = line.size();
> >              pos2 > pos1 &&
> >              whitespace.find(line[pos2-1]) != string::npos;pos2--) ;
> >         return line.substr(pos1,pos2-pos1);
> > }
> > 
> > I have these additional functions which seem to be involved somehow:
> > 
> > /*
> >  * Read the next line from a datafile, skipping any intervening comment
> >  lines.
> >  * Save the line of text and return true if successfull.  If EOF reached,
> >  * generate and error and return false.
> >  *
> >  */
> > 
> > bool System::SkipCommentsGets(istream &stream,string& buffer,const char
> > *message, char **outmessage) {
> > #ifdef DEBUG
> > cerr << "*** System::SkipCommentsGets()" << endl;
> > #endif
> > string trimString;
> > while (getline(stream,buffer,'\n')) {
> > #ifdef DEBUG
> > cerr << "*** System::SkipCommentsGets: buffer = {" << buffer << "}" <<
> > endl;
> > #endif
> > trimString = trim(buffer);
> > #ifdef DEBUG
> > cerr << "*** System::SkipCommentsGets: trimString = {" << trimString <<
> > "}" << endl;
> > #endif
> > if (trimString.size() > 0 && trimString[0] != '\'') return true;
> > }
> > if (outmessage != NULL) {
> > *outmessage = new char[strlen(message)+1];
> > strcpy(*outmessage,message);
> > }
> > return false;
> > }
> > 
> > /*
> >  * Split a string on the specified delimeter and return a vector of
> >  strings. */
> > 
> > vector<string> System::split(string s,char delimiter) const
> > {
> > vector<string> result;
> > string::size_type start, end;
> > #ifdef DEBUG
> > cerr << "*** System::split(" << s << "," << delimiter << ")" << endl;
> > #endif
> > for (start = 0;start != string::npos;start = end+1) {
> > end = s.find(delimiter,start);
> > #ifdef DEBUG
> > cerr << "*** System::split: start = " << start << ", end = " << end <<
> > endl;
> > #endif
> > if (end == string::npos) {
> > result.push_back(s.substr(start));
> > return result;
> > } else {
> > result.push_back(s.substr(start,end-start));
> > }
> > }
> > return result;
> > }
> > 
> > In all cases I am careful to use the proper types (eg
> > string::size_type) and whatnot as provided by the headers and I'm not
> > casting between pointers and ints (of any size!).
> > 
> Can you provide a complete program that has the problem?

I solved the problem: I was using a 64-bit TclKit that was built against
libstdc++.so.5 with C++ code built against libstdc++.so.6.  What was
truely weird was the the version of Tcl in the 64-bit TclKit was
actually *newer* than the the version of Tcl in the 32-bit TclKit was
newer (and the date on the 64-bit tclkit was more recent than the 32-bit
tclkit).  Strange...  I just downloaded an even newer 64-bit tclkit and
all works just fine now. (The above statement got me thinking...)

> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> 
> iEYEARECAAYFAkuIoWAACgkQm4klUUKw07AryQCggzEZLAxsMncxja7qhxRi5rwY
> 4bcAn2FwnyoNkFeGJhPhuJYKhjjxYTEj
> =CUMY
> -----END PGP SIGNATURE-----
> 
>                           

-- 
Robert Heller             -- Get the Deepwoods Software FireFox Toolbar!
Deepwoods Software        -- Linux Installation and Administration
http://www.deepsoft.com/  -- Web Hosting, with CGI and Database
heller@deepsoft.com       -- Contract Programming: C/C++, Tcl/Tk

                          


reply via email to

[Prev in Thread] Current Thread [Next in Thread]