View Single Post
Old Feb 10th, 2008, 12:30 PM   #6
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
Re: Code Segfaults when compiled with optimizations, doesn't in arbitrary situations

I believe you're wrong, Sane.

c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. #include <boost/foreach.hpp>
  4.  
  5. int main() {
  6. const int numbs[] = { 1, 2, 3, 4, 5 };
  7.  
  8. BOOST_FOREACH ( int n, numbs ) {
  9. std::cout << n << std::endl;
  10. }
  11. }

$ valgrind ./example
==11578== Memcheck, a memory error detector.
==11578== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==11578== Using LibVEX rev 1804, a library for dynamic binary translation.
==11578== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==11578== Using valgrind-3.3.0, a dynamic binary instrumentation framework.
==11578== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==11578== For more details, rerun with: -v
==11578== 
1
2
3
4
5
==11578== 
==11578== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 19 from 1)
==11578== malloc/free: in use at exit: 0 bytes in 0 blocks.
==11578== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
==11578== For counts of detected errors, rerun with: -v
==11578== All heap blocks were freed -- no leaks are possible.

It is able to do this was some automagic templates of some kind.

I am also unable to reproduce the original bug when I test the specific conditions in a seperate file and compilation. I'm guessing the bug (if it exists) only occurs when very specific conditions are true.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote