bug-commoncpp
[Top][All Lists]
Advanced

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

Segmentation fault


From: Behrang Gilanpour
Subject: Segmentation fault
Date: Sat, 10 Feb 2001 13:33:44 +0100 (CET)

Hi!

the code below code segfaults... ive been staring at it for quite a bit
now, and i cant seem to see the problem. I would be really happy if you could
give me hints or atleast say whats wrong :)

Everything works fine with the first iterator... but when I try to do
_anything_ with the i2 it segfaults ...   even that cout << *i2
segfaults and i dont see why the first one works and not the second one :(
To me it seems like something goes very wrong in the
StringTokenizer::iterator  .. but i dunno... maybe my code is wrong some
how. Anyway, I would really appreciate some guidance...

Best regards,
  Behrang

(check below for gdb backtrace and my method's code)
(btw, you should change in your README file, it says address@hidden
 instead of address@hidden (bug-commonc++ is not deliverable))

this is from gdb:

Program received signal SIGSEGV, Segmentation fault.
0x40159b5b in chunk_alloc (ar_ptr=0x401ec280, nb=16) at malloc.c:2893
2893    malloc.c: No such file or directory.
Current language:  auto; currently c
(gdb) bt
#0  0x40159b5b in chunk_alloc (ar_ptr=0x401ec280, nb=16) at malloc.c:2893
#1  0x40159234 in __libc_malloc (bytes=4) at malloc.c:2714
#2  0x400a3979 in __builtin_new () from /usr/lib/libstdc++-libc6.1-2.so.3
#3  0x400a3b5f in __builtin_vec_new () from /usr/lib/libstdc++-libc6.1-2.so.3
#4  0x40025278 in StringTokenizer::iterator::operator* (this=0xbffff92c)
    at keydata.cpp:482
#5  0x804cb1e in myClass::PASV (this=0x8050390) at test.cpp:171

..... StringTokenizer::iterator::operator*  getting used by my method

----------------------------------------------
void myClass::PASV() {
  tcp << "PASV" << endl;     // tcp is tcpstream, created earlier
  tcp.getline(output,512);   // output is also allocated earlier
  // output == 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)

  StringTokenizer st(output, " ");
  StringTokenizer::iterator i;
  i = st.begin();
  ++i; ++i; ++i; ++i;
  char temp[35];
  strcpy(temp,*i);
  *(temp+(strlen(temp))-2) = '\0';  // temp == (h1,h2,h3,h4,p1,p2

  // temp+1 == h1,h2,h3,h4,p1,p2
  StringTokenizer st2(temp+1, ",");
  StringTokenizer::iterator i2;
  i2 = st2.begin();

  cout << *i2 << endl;  // Here's where it crashes, i never get the cout
}

-----------------------------------------------




reply via email to

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