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

Bug#523690: std::map<>::erase(map.end()) should be a no-op



Package: libstdc++6
Version: 4.3.3-3
Severity: normal

Hello,

The std::map::erase(iterator) method in libstdc++6 cannot deal with the case 
that it is called with the end() iterator:

$ cat foo.cc
#include <map>
int main(int, char**) {
  std::map<int,int> m;
  m[1] = 2;
  m[3] = 4;
  m.erase(m.find(5)); // 5 not found, so find() returns end()
}
$ g++ -O2 -Wall -o foo foo.cc
$ $ ./foo 
*** glibc detected *** ./foo: free(): invalid pointer: 0xbfc25c24 ***
======= Backtrace: =========
/lib/i686/cmov/libc.so.6[0xb7cd81e4]
[snip backtrace]

I do not have a copy of the standard itself, but in C++ 3rd ed, section 
17.4.1.7, page 489, Stroustrup says simply "Erasing end() is harmless", which 
I interpret as "it has no effect".

Cheers,

  Richard

-- System Information:
Debian Release: squeeze/sid
  APT prefers testing
  APT policy: (990, 'testing')
Architecture: i386 (i686)

Kernel: Linux 2.6.28.7
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages libstdc++6 depends on:
ii  gcc-4.3-base                  4.3.3-3    The GNU Compiler Collection (base 
ii  libc6                         2.9-4      GNU C Library: Shared libraries
ii  libgcc1                       1:4.3.3-3  GCC support library

libstdc++6 recommends no packages.

libstdc++6 suggests no packages.

-- no debconf information



Reply to: