Package: libstdc++6
Version: 4.4.5-6
Severity: normal
The following code segfaults when copying rhs in cmp::operator()
because it's a dangling reference. it appends at the 2nd iteration.
It worked previously but I can't say since how long it does not work,
recently I guess.
Yet it should be possible to manipulate the vector during the comparison
if we take care to do so outside the limits imposed by the iterators.
Best regards,
Guillaume
---------8<--------------
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
class cmp : binary_function<bool,string,string> {
vector<string>& vec;
public:
cmp(vector<string>& v) : vec(v) {}
bool operator()(const string& lhs, const string& rhs) {
vec.push_back("ping");vec.push_back("pong");
vec.pop_back();vec.pop_back();
return lhs<rhs;
}
};
int main(int argc, char **argv) {
vector<string> vec;
vec.push_back("lundi"); vec.push_back("mardi");
vec.push_back("mercredi"); vec.push_back("jeudi");
vec.push_back("vendredi"); vec.push_back("samedi");
vec.push_back("dimanche");
sort(vec.begin(),vec.end(),cmp(vec));
return 0;
}
-- System Information:
Debian Release: squeeze/sid
APT prefers testing
APT policy: (990, 'testing'), (500, 'unstable'), (500, 'stable'), (1,
'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.34-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages libstdc++6 depends on:
ii gcc-4.4-base 4.4.5-6 The GNU Compiler Collection
(base
ii libc6 2.11.2-7 Embedded GNU C Library:
Shared lib
ii libgcc1 1:4.4.5-6 GCC support library
libstdc++6 recommends no packages.
libstdc++6 suggests no packages.
-- no debconf information
--
To UNSUBSCRIBE, email to debian-gcc-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/4cdb25ef.7010...@free.fr