This is the mail archive of the gdb-prs@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/1147: segfault dereferencing a reference to a pointer


>Number:         1147
>Category:       c++
>Synopsis:       segfault dereferencing a reference to a pointer
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 19 19:38:02 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     kraftche at cae dot wisc dot edu
>Release:        5.3
>Organization:
>Environment:
linux, gcc 2.95.4
>Description:
gdb passes bad "this" pointer to a class method called
through a reference to a poitner.

>How-To-Repeat:
#!/bin/bash

file=gdb-ref2.cpp

cat > $file <<ENDOFSOURCE
#include <iostream>

class Integer {
  public:
    Integer(int i = 0 ) : value(i) {}
    void print() const { std::cout << value << std::endl; }
  private:
    int value;
};

void make_positive_integer( int value, Integer*& result )
{
  result = 0;
  if ( value >= 0 )
    result = new Integer(value);

  if ( result )
    result->print();
}

int main()
{
  Integer *int1;
  make_positive_integer( 5, int1 );
  
  return 0;
}
ENDOFSOURCE

g++ -g $file -o ${file}.x
gdb ${file}.x <<ENDOFGDB

b 17
r
p *result
call result->print()
ENDOFGDB
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]