public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/45249]  New: Indirect variable parameters sometimes cause segmentation fault
@ 2010-08-10 21:55 rogerio at rilhas dot com
  2010-08-10 22:03 ` [Bug c++/45249] " rogerio at rilhas dot com
                   ` (57 more replies)
  0 siblings, 58 replies; 59+ messages in thread
From: rogerio at rilhas dot com @ 2010-08-10 21:55 UTC (permalink / raw)
  To: gcc-bugs

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


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

end of thread, other threads:[~2010-08-12 10:18 UTC | newest]

Thread overview: 59+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-10 21:55 [Bug c++/45249] New: Indirect variable parameters sometimes cause segmentation fault rogerio at rilhas dot com
2010-08-10 22:03 ` [Bug c++/45249] " rogerio at rilhas dot com
2010-08-10 22:04 ` rogerio at rilhas dot com
2010-08-10 22:04 ` rogerio at rilhas dot com
2010-08-10 22:07 ` pinskia at gcc dot gnu dot org
2010-08-10 22:33 ` rogerio at rilhas dot com
2010-08-10 22:36 ` rogerio at rilhas dot com
2010-08-10 23:08 ` pinskia at gcc dot gnu dot org
2010-08-11  0:55 ` rogerio at rilhas dot com
2010-08-11  0:58 ` pinskia at gcc dot gnu dot org
2010-08-11  1:57 ` rogerio at rilhas dot com
2010-08-11  3:52 ` pinskia at gcc dot gnu dot org
2010-08-11 11:21 ` rogerio at rilhas dot com
2010-08-11 11:21 ` rogerio at rilhas dot com
2010-08-11 11:22 ` rogerio at rilhas dot com
2010-08-11 11:37 ` rguenth at gcc dot gnu dot org
2010-08-11 11:41 ` rguenth at gcc dot gnu dot org
2010-08-11 11:55 ` redi at gcc dot gnu dot org
2010-08-11 13:12 ` rogerio at rilhas dot com
2010-08-11 14:10 ` redi at gcc dot gnu dot org
2010-08-11 16:11 ` matz at gcc dot gnu dot org
2010-08-11 17:04 ` rogerio at rilhas dot com
2010-08-11 17:15 ` rogerio at rilhas dot com
2010-08-11 17:49 ` pinskia at gcc dot gnu dot org
2010-08-11 17:57 ` redi at gcc dot gnu dot org
2010-08-11 19:51 ` rogerio at rilhas dot com
2010-08-11 19:54 ` pinskia at gcc dot gnu dot org
2010-08-11 20:04 ` rogerio at rilhas dot com
2010-08-11 20:07 ` rogerio at rilhas dot com
2010-08-11 20:33 ` rguenth at gcc dot gnu dot org
2010-08-11 20:58 ` rogerio at rilhas dot com
2010-08-11 21:02 ` pinskia at gcc dot gnu dot org
2010-08-11 21:12 ` rogerio at rilhas dot com
2010-08-11 21:16 ` pinskia at gcc dot gnu dot org
2010-08-11 21:27 ` redi at gcc dot gnu dot org
2010-08-11 22:17 ` rogerio at rilhas dot com
2010-08-11 22:27 ` rguenth at gcc dot gnu dot org
2010-08-11 22:31 ` rguenth at gcc dot gnu dot org
2010-08-11 22:35 ` rogerio at rilhas dot com
2010-08-11 22:37 ` rogerio at rilhas dot com
2010-08-11 22:48 ` rguenth at gcc dot gnu dot org
2010-08-11 22:50 ` rogerio at rilhas dot com
2010-08-11 22:51 ` rogerio at rilhas dot com
2010-08-11 22:52 ` rogerio at rilhas dot com
2010-08-11 22:53 ` rogerio at rilhas dot com
2010-08-11 22:54 ` rogerio at rilhas dot com
2010-08-11 22:54 ` rogerio at rilhas dot com
2010-08-11 22:55 ` rogerio at rilhas dot com
2010-08-11 22:58 ` pinskia at gcc dot gnu dot org
2010-08-11 23:22 ` rogerio at rilhas dot com
2010-08-11 23:43 ` rogerio at rilhas dot com
2010-08-12  2:08 ` rogerio at rilhas dot com
2010-08-12  2:10 ` rogerio at rilhas dot com
2010-08-12  2:11 ` rogerio at rilhas dot com
2010-08-12  2:12 ` rogerio at rilhas dot com
2010-08-12  2:13 ` rogerio at rilhas dot com
2010-08-12  8:20 ` jakub at gcc dot gnu dot org
2010-08-12 10:17 ` rogerio at rilhas dot com
2010-08-12 10:18 ` paolo dot carlini at oracle dot com

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).