public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/10407: non-numeric assignment to for initialzation cause seg fault
@ 2003-04-14 21:56 bangerth
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2003-04-14 21:56 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, neojack99, nobody

Synopsis: non-numeric assignment to for initialzation cause seg fault

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Mon Apr 14 21:56:17 2003
State-Changed-Why:
    Not a bug. You are accessing the element one past the end:
    
    for(int i = v.size(); i >= 0 ; i--)
        cout << i + 1 << ": " << v[i] << endl;
    
    Start with i=v.size()-1 !
    
    W.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10407


^ permalink raw reply	[flat|nested] 2+ messages in thread

* c++/10407: non-numeric assignment to for initialzation cause seg fault
@ 2003-04-14 21:46 neojack99
  0 siblings, 0 replies; 2+ messages in thread
From: neojack99 @ 2003-04-14 21:46 UTC (permalink / raw)
  To: gcc-gnats


>Number:         10407
>Category:       c++
>Synopsis:       non-numeric assignment to for initialzation cause seg fault
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 14 21:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     neojack99@hotmail.com
>Release:        gcc version 3.2.2 20030322 (Gentoo Linux 1.4 3.2.2-r2)
>Organization:
>Environment:
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.2/specs
Configured with: /var/tmp/portage/gcc-3.2.2-r2/work/gcc-3.2.2/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.2 --includedir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.2/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.2 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.2/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.2/info --enable-shared --host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib --enable-languages=c,c++,ada,f77,objc,java --enable-threads=posix --enable-long-long --disable-checking --enable-cstdio=stdio --enable-clocale=generic --enable-__cxa_atexit --enable-version-specific-runtime-libs --with-gxx-include-dir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.2/include/g++-v3 --with-local-prefix=/usr/local --enable-shared --enable-nls --without-included-gettext
Thread model: posix
>Description:
the code below compiles fine, but segfaults on the for loop - particularly the "int i = non-number" part.
Compiled as:
g++ for_seg_faulter.cpp -o for_seg_faulter

* Note: itdoes not seg fault with icc.

Sample code:

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int main() {
  vector<string> v;

  ifstream in("for_seg_faulter.cpp");
  string line;
  while(getline(in, line))
    v.push_back(line); // Add the line to the end

  //
  for(int i = v.size(); i >= 0 ; i--)
 //Using the actual v.size (21) works. As it is it seg faults.
    cout << i + 1 << ": " << v[i] << endl;
}
>How-To-Repeat:

>Fix:

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-04-14 21:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-14 21:56 c++/10407: non-numeric assignment to for initialzation cause seg fault bangerth
  -- strict thread matches above, loose matches on Subject: below --
2003-04-14 21:46 neojack99

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).