When using variable parameters indirectly (the variable-parameter function calls another function to format its parameters giving it the original address of the format string), the results are usually ok for non-optimized builds and cause segmentation faults in optimized builds.
In a large project I also detected that unoptimized builds would cause segmentation faults if the variable-parameter function declared a char buffer, and would not fail if it declared an int buffer of the same total size. However this is difficult to reproduce, so the test case I send you does not show this. In the code I send you you can see "main" calling "format_direct" to format some variable parameters, which in turn calls "format_indirect" to do the actual work. This is a pattern I use a lot and for which I never had a problem under Windows with any of Microsoft's Visual Studio versions (I'm fairly new to LINUX, this is my first software port project). If this test case is compiled with "g++ -v -save-temps gcc_bug_format_indirect.cpp -o gcc_bug_format_indirect.exe.ok" then it works ok, but if it is compiled with "g++ -v -save-temps -O2 gcc_bug_format_indirect.cpp -o gcc_bug_format_indirect.exe.ko" it causes a segmentation fault (at least on my system it does, when it doesn't cause a segmentation fault the results are just wrong). I attach the preprocessed file, the source file, and the compilation script I used. -- Summary: Indirect variable parameters sometimes cause segmentation fault Product: gcc Version: 4.3.3 Status: UNCONFIRMED Severity: blocker Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rogerio at rilhas dot com GCC build triplet: i686-virtualboxvm-ubuntu? GCC host triplet: i686-virtualboxvm-ubuntu? GCC target triplet: i686-virtualboxvm-ubuntu? http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45249