Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > a bug in g++ std::map implementation?

Reply
Thread Tools

a bug in g++ std::map implementation?

 
 
Fei Liu
Guest
Posts: n/a
 
      01-18-2007
Hello, I am getting something really wierd out of this source code, can
you please verify if you also get segmentation fault (memory failure)?

http_form.h: (sorry about the line wrapping, email client problem)
#ifndef HTTP_FORM_H
#define HTTP_FORM_H

#include <map>
#include <string>
#include <iostream>

namespace feiliu{
template <typename value_type>
class http_form{
public:
http_form();
~http_form();
void add_entry(const std:air<std::string, value_type> &
entry){
entries.insert(entry);
}
void add_entry(const std::string & key, const value_type &
value){
entries.insert(std:air<std::string, value_type>(key,
value));
}
std::string get_form_data();
private:
std::map<std::string, value_type> entries;
};

template <typename value_type>
std::string http_form<value_type>::get_form_data(){
typename std::map<std::string, value_type>::iterator iter =
entries.begin();
std::cout << "size of map: " << entries.size() << '\n';
for(int i = 0; i < entries.size(); i ++){
std::cout << "key = " << iter->first << " value = " <<
iter->second << '\n';
++ iter;
}
for(iter = entries.begin(); iter != entries.end(); ++ iter)
std::cout << "key = " << iter->first << " value = " <<
iter->second << '\n';
}
}



#endif

http_form.cpp:
#include "http_form.h"
template <typename value_type>
feiliu::http_form<value_type>::http_form(){
}

//std::string http_form::get_form_data(){
template <typename value_type>
feiliu::http_form<value_type>::~http_form(){
entries.clear();
}

#ifdef TEST_HTTP_FORM
using std::string;
int main(){
feiliu::http_form<string> form;
form.add_entry("hello", "world");
form.add_entry("foo", "bar");
form.get_form_data();
}
#endif

compile: g++ -DTEST_HTTP_FORM -g -O0 -o tf http_form.cpp
run: ./tf
size of map: 2
key = foo value = bar
key = hello value = world
key = foo value = bar
key = hello value = world
Segmentation fault


Apparently, there is something wrong with iterator using begin() and
end()...Any help is appreciated. Thanks,

Fei
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      01-18-2007
* Fei Liu:
>
> compile: g++ -DTEST_HTTP_FORM -g -O0 -o tf http_form.cpp


Add options to up the warning level. Presumably the compiler will then
complain about a missing return statement.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
 
 
 
Fei Liu
Guest
Posts: n/a
 
      01-19-2007

Alf P. Steinbach wrote:
> * Fei Liu:
> >
> > compile: g++ -DTEST_HTTP_FORM -g -O0 -o tf http_form.cpp

>
> Add options to up the warning level. Presumably the compiler will then
> complain about a missing return statement.
>


Ah, that did the trick, adding return "" stopped the compiler from
generating bad assembly. Thanks,

Fei

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
ASP.NET Login control bug or SQL 2005 bug? RedEye ASP .Net 2 12-13-2005 10:57 AM
Re: BUG? OR NOT A BUG? John ASP .Net 2 09-21-2005 10:31 AM
Bug Parade Bug 4953793 Michel Joly de Lotbiniere Java 4 12-02-2003 05:05 AM
how to report bug to g++ ? got a bug and fixed up source code DarkSpy C++ 4 06-27-2003 09:05 AM



Advertisments