After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 791973 - printf appears to crash when passed too may args
printf appears to crash when passed too may args
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: general
0.36.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2017-12-27 02:52 UTC by oliver.steven
Modified: 2018-01-17 19:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Generated C code (27.65 KB, application/zip)
2017-12-27 02:52 UTC, oliver.steven
Details
backtrace (25.28 KB, text/plain)
2018-01-09 16:59 UTC, oliver.steven
Details
backtrace (11.73 KB, text/plain)
2018-01-09 18:57 UTC, oliver.steven
Details

Description oliver.steven 2017-12-27 02:52:37 UTC
Created attachment 365996 [details]
Generated C code

This commit is now causing my application to crash:
https://github.com/steveno/balistica/commit/061a28e98f3c4468b4465e580ada78f11eec4461?diff=unified

I don't understand what changed in that commit that breaks the
application with my version of Vala versus the one I had on 16.04, but
I managed to trace it down to two lines (511 & 513) in
src/balistica_application.vala (which aren't changed in the diff !!).
If you comment out those two lines it will compile and produce the
drag calculation as expected.

I also figured out that if you change those two lines so that the
printf functions don't format more than two entries, it will also
compile and produce the expected output. With a third entry, though,
it seg faults trying to print the calculation results.

Will Seg Fault:
txtViewDragResults.buffer.text += ("Initial Velocity: %.2f ft/s Zero
Range: %.2f yards Shooting Angle: %.2f degrees\n").printf (lsln.getMv
(), lsln.getZerorange (), lsln.getAngle ()) ;

Will print as expected:
txtViewDragResults.buffer.text += ("Initial Velocity: %.2f ft/s Zero
Range: %.2f yards\n").printf (lsln.getMv (), lsln.getZerorange ()) ;

I have attached the C code that is generated.
Comment 1 Rico Tzschichholz 2017-12-28 13:13:50 UTC
Could you elaborate "with my version of Vala"?

Better use an official vala release or vala git master.

Are you able to boil down this problem in a less complex example? Or provide specific steps (input and gui interactions) to reproduce the problem with your application.
Comment 2 Rico Tzschichholz 2017-12-28 13:27:12 UTC
Fails to build without:

--- a/src/gui/DragBox.vala
+++ b/src/gui/DragBox.vala
@@ -316,7 +316,7 @@ public class Balistica.DragBox : Gtk.Box {
 
 	  // Create a save as dialog
 	  Gtk.FileChooserDialog save_dialog = new Gtk.FileChooserDialog ("Save As",
-																	 Application.main_window as Gtk.Window,
+																	 ((Application) GLib.Application.get_default ()).main_window as Gtk.Window,
 																	 Gtk.FileChooserAction.SAVE,
 																	 "Cancel",
 																	 Gtk.ResponseType.CANCEL,
Comment 3 oliver.steven 2018-01-06 02:55:44 UTC
I'm using valac 0.36.6

I've spent about an hour or so trying to come up with a minimal example, but I can't seem to reproduce it. I will provide more specific instructions in another message.
Comment 4 Rico Tzschichholz 2018-01-06 14:24:26 UTC
@oliver: Please upgrade to a more recent release like 0.36.8
Comment 5 oliver.steven 2018-01-09 15:20:48 UTC
I upgraded to Vala 0.39.4.7-57a54 and it's still crashing for me.
Comment 6 Al Thomas 2018-01-09 16:33:38 UTC
(In reply to oliver.steven from comment #5)
> I upgraded to Vala 0.39.4.7-57a54 and it's still crashing for me.

Maybe a backtrace would help? 

If you don't already know: compile with --debug option for valac, start gdb with `gdb ballistica`, then use `run` and when it seg faults, use `bt` to get the backtrace.
Comment 7 oliver.steven 2018-01-09 16:58:32 UTC
@Al Thomas, did not know that. Thank you!

Backtrace:

Starting program: /home/steveno/Projects/balistica/build/balistica 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffebf88700 (LWP 21829)]
[New Thread 0x7fffeb787700 (LWP 21830)]
[New Thread 0x7fffead79700 (LWP 21831)]
[New Thread 0x7fffe9b4c700 (LWP 21832)]
[New Thread 0x7fffe934b700 (LWP 21833)]
[Thread 0x7fffe9b4c700 (LWP 21832) exited]

Thread 1 "balistica" received signal SIGSEGV, Segmentation fault.
0x00007ffff784f531 in gtk_widget_style_get () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
(gdb) bt
  • #0 gtk_widget_style_get
  • #1 0x00007ffff777d648 in
  • #2 0x00007ffff777f703 in
  • #3 0x00007ffff7631333 in
  • #4 0x00007ffff76354f1 in
  • #5 0x00007ffff777ba06 in
  • #6 0x00007ffff7795254 in
  • #7 0x00007ffff7795aec in
  • #8 gtk_widget_get_preferred_height_and_baseline_for_width
  • #9 0x00007ffff7795f33 in
  • #10 0x00007ffff762a436 in
  • #11 0x00007ffff6c1e0e0 in
  • #12 g_signal_emit_valist
  • #13 g_signal_emit
  • #14 0x00007ffff777f22b in
  • #15 0x00007ffff76358c6 in
  • #16 0x00007ffff777bb6a in
  • #17 gtk_widget_size_allocate_with_baseline
  • #18 0x00007ffff762a4c9 in
  • #19 0x00007ffff6c1e0e0 in
  • #20 g_signal_emit_valist
  • #21 g_signal_emit
  • #22 0x00007ffff777f22b in
  • #23 0x00007ffff76358c6 in
  • #24 0x00007ffff777bb6a in
  • #25 gtk_widget_size_allocate_with_baseline
  • #26 0x00007ffff762a4c9 in
  • #27 0x00007ffff6c1e0e0 in
  • #28 g_signal_emit_valist
  • #29 g_signal_emit
  • #30 0x00007ffff777f22b in
  • #31 0x00007ffff76358c6 in
  • #32 0x00007ffff777bb6a in
  • #33 gtk_widget_size_allocate_with_baseline
  • #34 0x00007ffff762a4c9 in
  • #35 0x00007ffff6c1e0e0 in
  • #36 g_signal_emit_valist
  • #37 g_signal_emit
  • #38 0x00007ffff777f22b in
  • #39 0x00007ffff76358c6 in
  • #40 0x00007ffff777bb6a in
  • #41 gtk_widget_size_allocate_with_baseline
  • #42 0x00007ffff762a4c9 in
  • #43 0x00007ffff6c1e0e0 in
  • #44 g_signal_emit_valist
  • #45 g_signal_emit
  • #46 0x00007ffff777f22b in
  • #47 0x00007ffff76358c6 in
  • #48 0x00007ffff777bb6a in
  • #49 gtk_widget_size_allocate_with_baseline
  • #50 0x00007ffff762a4c9 in
  • #51 0x00007ffff6c1e0e0 in
  • #52 g_signal_emit_valist
  • #53 g_signal_emit
  • #54 0x00007ffff777f22b in
  • #55 0x00007ffff76358c6 in
  • #56 0x00007ffff777bb6a in
  • #57 gtk_widget_size_allocate_with_baseline
  • #58 0x00007ffff762a4c9 in
  • #59 0x00007ffff6c1e0e0 in
  • #60 g_signal_emit_valist
  • #61 g_signal_emit
  • #62 0x00007ffff777f22b in
  • #63 0x00007ffff76358c6 in
  • #64 0x00007ffff777bb6a in
  • #65 gtk_widget_size_allocate_with_baseline
  • #66 0x00007ffff762a4c9 in
  • #67 0x00007ffff6c1e0e0 in
  • #68 g_signal_emit_valist
  • #69 g_signal_emit
  • #70 0x00007ffff777f22b in
  • #71 0x00007ffff76358c6 in
  • #72 0x00007ffff777bb6a in
  • #73 gtk_widget_size_allocate_with_baseline
  • #74 0x00007ffff762a4c9 in
  • #75 0x00007ffff6c1e0e0 in
  • #76 g_signal_emit_valist
  • #77 g_signal_emit
  • #78 0x00007ffff777f22b in
  • #79 0x00007ffff76358c6 in
  • #80 0x00007ffff777bb6a in
  • #81 gtk_widget_size_allocate_with_baseline
  • #82 0x00007ffff762a4c9 in
  • #83 0x00007ffff6c1e0e0 in
  • #84 g_signal_emit_valist
  • #85 g_signal_emit
  • #86 0x00007ffff777f22b in
  • #87 0x00007ffff76358c6 in
  • #88 0x00007ffff777bb6a in
  • #89 gtk_widget_size_allocate_with_baseline
  • #90 0x00007ffff762a4c9 in
  • #91 0x00007ffff6c1e0e0 in
  • #92 g_signal_emit_valist
  • #93 g_signal_emit
  • #94 0x00007ffff777f22b in
  • #95 0x00007ffff76358c6 in
  • #96 0x00007ffff777bb6a in
  • #97 gtk_widget_size_allocate_with_baseline
  • #98 0x00007ffff762a4c9 in
  • #99 0x00007ffff6c1e0e0 in
  • #100 g_signal_emit_valist
  • #101 g_signal_emit
  • #102 0x00007ffff777f22b in
  • #103 0x00007ffff76358c6 in
  • #104 0x00007ffff777bb6a in
  • #105 gtk_widget_size_allocate_with_baseline
  • #106 0x00007ffff762a4c9 in
  • #107 0x00007ffff6c1e0e0 in
  • #108 g_signal_emit_valist
  • #109 g_signal_emit
  • #110 0x00007ffff777f22b in
  • #111 0x00007ffff76358c6 in
  • #112 0x00007ffff777bb6a in
  • #113 gtk_widget_size_allocate_with_baseline
  • #114 0x00007ffff762a4c9 in
  • #115 0x00007ffff6c1e0e0 in
  • #116 g_signal_emit_valist
  • #117 g_signal_emit
  • #118 0x00007ffff777f22b in
  • #119 0x00007ffff76358c6 in
  • #120 0x00007ffff777bb6a in
  • #121 gtk_widget_size_allocate_with_baseline
  • #122 0x00007ffff762a4c9 in
  • #123 0x00007ffff6c1e0e0 in
  • #124 g_signal_emit_valist
  • #125 g_signal_emit
  • #126 0x00007ffff777f22b in
  • #127 0x00007ffff76358c6 in
  • #128 0x00007ffff777bb6a in
  • #129 gtk_widget_size_allocate_with_baseline
  • #130 0x00007ffff762a4c9 in
  • #131 0x00007ffff6c1e0e0 in
  • #132 g_signal_emit_valist
  • #133 g_signal_emit
  • #134 0x00007ffff777f22b in
  • #135 0x00007ffff76358c6 in
  • #136 0x00007ffff777bb6a in
  • #137 gtk_widget_size_allocate_with_baseline
  • #138 0x00007ffff762a4c9 in
  • #139 0x00007ffff6c1e0e0 in
  • #140 g_signal_emit_valist
  • #141 g_signal_emit
  • #142 0x00007ffff777f22b in
  • #143 0x00007ffff76358c6 in
  • #144 0x00007ffff777bb6a in
  • #145 gtk_widget_size_allocate_with_baseline
  • #146 0x00007ffff762a4c9 in
  • #147 0x00007ffff6c1e0e0 in
  • #148 g_signal_emit_valist
  • #149 g_signal_emit
  • #150 0x00007ffff777f22b in
  • #151 0x00007ffff76358c6 in
  • #152 0x00007ffff777bb6a in
  • #153 gtk_widget_size_allocate_with_baseline
  • #154 0x00007ffff762a4c9 in
  • #155 0x00007ffff6c1e0e0 in
  • #156 g_signal_emit_valist
  • #157 g_signal_emit
  • #158 0x00007ffff777f22b in
  • #159 0x00007ffff76358c6 in
  • #160 0x00007ffff777bb6a in
  • #161 gtk_widget_size_allocate_with_baseline
  • #162 0x00007ffff762a4c9 in
  • #163 0x00007ffff6c1e0e0 in
  • #164 g_signal_emit_valist
  • #165 g_signal_emit
  • #166 0x00007ffff777f22b in
  • #167 0x00007ffff76358c6 in
  • #168 0x00007ffff777bb6a in
  • #169 gtk_widget_size_allocate_with_baseline
  • #170 0x00007ffff762a4c9 in
  • #171 0x00007ffff6c1e0e0 in
  • #172 g_signal_emit_valist
  • #173 g_signal_emit
  • #174 0x00007ffff777f22b in
  • #175 0x00007ffff76358c6 in
  • #176 0x00007ffff777bb6a in
  • #177 gtk_widget_size_allocate_with_baseline
  • #178 0x00007ffff762a4c9 in
  • #179 0x00007ffff6c1e0e0 in
  • #180 g_signal_emit_valist
  • #181 g_signal_emit
  • #182 0x00007ffff777f22b in
  • #183 0x00007ffff76358c6 in
  • #184 0x00007ffff777bb6a in
  • #185 gtk_widget_size_allocate_with_baseline
  • #186 0x00007ffff762a4c9 in
  • #187 0x00007ffff6c1e0e0 in
  • #188 g_signal_emit_valist
  • #189 g_signal_emit
  • #190 0x00007ffff777f22b in
  • #191 0x00007ffff76358c6 in
  • #192 0x00007ffff777bb6a in
  • #193 gtk_widget_size_allocate_with_baseline
  • #194 0x00007ffff762a4c9 in
  • #195 0x00007ffff6c1e0e0 in
  • #196 g_signal_emit_valist
  • #197 g_signal_emit
  • #198 0x00007ffff777f22b in
  • #199 0x00007ffff76358c6 in
  • #200 0x00007ffff777bb6a in
  • #201 gtk_widget_size_allocate_with_baseline
  • #202 0x00007ffff762a4c9 in
  • #203 0x00007ffff6c1e0e0 in
  • #204 g_signal_emit_valist
  • #205 g_signal_emit
  • #44046 0x00007ffff777f22b in
  • #44047 0x00007ffff76358c6 in
  • #44048 0x00007ffff777bb6a in
  • #44049 gtk_widget_size_allocate_with_baseline
  • #44050 0x00007ffff762a4c9 in
  • #44051 0x00007ffff6c1e0e0 in
  • #44052 g_signal_emit_valist
  • #44053 g_signal_emit
  • #44054 0x00007ffff777f22b in
  • #44055 0x00007ffff76358c6 in
  • #44056 0x00007ffff777bb6a in
  • #44057 gtk_widget_size_allocate_with_baseline
  • #44058 0x00007ffff762a4c9 in
  • #44059 0x00007ffff6c1e0e0 in
  • #44060 g_signal_emit_valist
  • #44061 g_signal_emit
  • #44062 0x00007ffff777f22b in
  • #44063 0x00007ffff76358c6 in
  • #44064 0x00007ffff777bb6a in
  • #44065 gtk_widget_size_allocate_with_baseline
  • #44066 0x00007ffff762a4c9 in
  • #44067 0x00007ffff6c1e0e0 in
  • #44068 g_signal_emit_valist
  • #44069 g_signal_emit
  • #44070 0x00007ffff777f22b in
  • #44071 0x00007ffff76358c6 in
  • #44072 0x00007ffff777bb6a in
  • #44073 gtk_widget_size_allocate_with_baseline
  • #44074 0x00007ffff762a4c9 in
  • #44075 0x00007ffff6c1e0e0 in
  • #44076 g_signal_emit_valist
  • #44077 g_signal_emit
  • #44078 0x00007ffff777f22b in
  • #44079 0x00007ffff76358c6 in
  • #44080 0x00007ffff777bb6a in
  • #44081 gtk_widget_size_allocate_with_baseline
  • #44082 0x00007ffff762a4c9 in
  • #44083 0x00007ffff6c1e0e0 in
  • #44084 g_signal_emit_valist
  • #44085 g_signal_emit
  • #44086 0x00007ffff777f22b in
  • #44087 0x00007ffff76358c6 in
  • #44088 0x00007ffff777bb6a in
  • #44089 gtk_widget_size_allocate_with_baseline
  • #44090 0x00007ffff762a4c9 in
  • #44091 0x00007ffff6c1e0e0 in
  • #44092 g_signal_emit_valist
  • #44093 g_signal_emit
  • #44094 0x00007ffff777f22b in
  • #44095 0x00007ffff76358c6 in
  • #44096 0x00007ffff777bb6a in
  • #44097 gtk_widget_size_allocate_with_baseline
  • #44098 0x00007ffff762a4c9 in
  • #44099 0x00007ffff6c1e0e0 in
  • #44100 g_signal_emit_valist
  • #44101 g_signal_emit
  • #44102 0x00007ffff7842502 in
  • #44103 0x00007ffff775912c in
  • #44104 0x00007ffff775921c in
  • #44105 g_closure_invoke
  • #44106 0x00007ffff6c30cde in
  • #44107 g_signal_emit_valist
  • #44108 g_signal_emit
  • #44109 0x00007ffff6c21e0e in
  • #44110 g_object_set_valist
  • #44111 g_object_set
  • #44112 0x00007ffff77db736 in
  • #44113 0x00007ffff77e2e48 in
  • #44114 gtk_widget_size_allocate_with_baseline
  • #44115 0x00007ffff7848c44 in
  • #44116 0x00007ffff777c933 in
  • #44117 0x00007ffff7848bfe in
  • #44118 0x00007ffff762a498 in
  • #44119 0x00007ffff6c1e1d6 in
  • #44120 g_signal_emit_valist
  • #44121 g_signal_emit
  • #44122 0x00007ffff7842502 in
  • #44123 0x00007ffff77e83b1 in
  • #44124 0x00007ffff76f830d in
  • #44125 0x00007ffff6c1e1d6 in
  • #44126 g_signal_emit_valist
  • #44127 g_signal_emit
  • #44128 0x00007ffff77e19b3 in
  • #44129 0x00007ffff77e2543 in
  • #44130 0x00007ffff77e2989 in
  • #44131 0x00007ffff5ee9090 in
  • #44132 g_main_context_dispatch
  • #44133 0x00007ffff69451f0 in
  • #44134 g_main_context_iteration
  • #44135 g_application_run
  • #44136 _vala_main
  • #44137 main

Comment 8 oliver.steven 2018-01-09 16:59:48 UTC
Created attachment 366564 [details]
backtrace
Comment 9 oliver.steven 2018-01-09 17:00:16 UTC
I added the backtrace as an attachment because pasting in the comments ended up being a bad idea. Sorry about that.
Comment 10 Al Thomas 2018-01-09 18:19:18 UTC
Hmm, I wasn't expecting that: gtk_widget_style_get ()
Out of general interest, was the backtrace created with -DCMAKE_BUILD_TYPE=Debug as per https://mail.gnome.org/archives/vala-list/2015-February/msg00004.html ?

From your first comment the relevant C code from your first attachment seems to be:

	_tmp78_ = self->priv->drag_results;
	_tmp79_ = gtk_text_view_get_buffer (_tmp78_);
	_tmp80_ = _tmp79_;
	g_object_get (_tmp80_, "text", &_tmp81_, NULL);
	_tmp82_ = _tmp81_;
	_tmp83_ = _tmp82_;
	_tmp84_ = self->priv->lsln;
	_tmp85_ = lib_balistica_solution_getMv (_tmp84_);
	_tmp86_ = self->priv->lsln;
	_tmp87_ = lib_balistica_solution_getZerorange (_tmp86_);
	_tmp88_ = self->priv->lsln;
	_tmp89_ = lib_balistica_solution_getAngle (_tmp88_);
	_tmp90_ = g_strdup_printf ("Initial Velocity: %.2f ft/s  Zero Range: %.2f yards  Shooting Angle %." \
"2f degrees\n", _tmp85_, _tmp87_, _tmp89_);
	_tmp91_ = _tmp90_;
	_tmp92_ = g_strconcat (_tmp83_, _tmp91_, NULL);
	_tmp93_ = _tmp92_;
	g_object_set (_tmp80_, "text", _tmp93_, NULL);
	_g_free0 (_tmp93_);
	_g_free0 (_tmp91_);
	_g_free0 (_tmp83_);


The only thing that looks a bit odd if the line continuation breaking up the last %.2f. I'm not sure how that affects things. I've found https://stackoverflow.com/questions/1752079/in-c-can-a-long-printf-statement-be-broken-up-into-multiple-lines that has some useful comments, but that's as far as I've got.
Comment 11 oliver.steven 2018-01-09 18:57:11 UTC
Created attachment 366573 [details]
backtrace

This time with --debug to valac and with -DCMAKE_BUILD_TYPE=Debug.
Comment 12 Al Thomas 2018-01-09 23:36:14 UTC
(In reply to oliver.steven from comment #11)
> This time with --debug to valac and with -DCMAKE_BUILD_TYPE=Debug.

Thanks, I wondered why the Vala line numbers and arguments were missing, e.g. it now shows:

  • #44136 _vala_main
    at /home/steveno/Projects/balistica/src/main.vala line 21
  • #44137 main
    at /home/steveno/Projects/balistica/src/main.vala line 19

You could try doing a backtrace for all threads with the command:
thread apply all bt 

There might be a few more tips here:
https://wiki.gnome.org/Community/GettingInTouch/Bugzilla/GettingTraces/Details

I've not debugged GTK+ apps in this much detail, but I'm surprised there are 44000+ stack frames shown in the GTK thread. It seems to follow a pattern of calling gtk_widget_size_allocate_with_baseline () and then emitting a signal. The docs for gtk_widget_size_allocte_with_baseline () say "In this function, the allocation and baseline may be adjusted. It will be forced to a 1x1 minimum size, and the adjust_size_allocation virtual and adjust_baseline_allocation methods on the child will be used to adjust the allocation and baseline. Standard adjustments include removing the widget's margins, and applying the widget’s “halign” and “valign” properties". So you might want to check that area of your code, so see if you are adjusting properties when you don't need to.
Comment 13 Rico Tzschichholz 2018-01-10 15:04:53 UTC
I still can't find a correlation of the problem with vala.

I assume this is somehow caused by gtk+ while your application worked on Xenial/16.04 with gtk+ 3.18.9 it fails with a newer ones. So this seems to hit the GtkTextView nested in the GtkScrolledWindow in some weird way.

Even replacing the multiple settings of TextBuffer's text-property with a StringBuilder didn't work.
Comment 14 Al Thomas 2018-01-10 19:09:41 UTC
(In reply to oliver.steven from comment #0)
> Will Seg Fault:
> txtViewDragResults.buffer.text += ("Initial Velocity: %.2f ft/s Zero
> Range: %.2f yards Shooting Angle: %.2f degrees\n").printf (lsln.getMv
> (), lsln.getZerorange (), lsln.getAngle ()) ;
> 
> Will print as expected:
> txtViewDragResults.buffer.text += ("Initial Velocity: %.2f ft/s Zero
> Range: %.2f yards\n").printf (lsln.getMv (), lsln.getZerorange ()) ;

Just a thought: is the string line length too long for a single line in the text box and that triggers some weird bug in GTK+?
Comment 15 oliver.steven 2018-01-10 21:04:35 UTC
(In reply to Al Thomas from comment #14)
> Just a thought: is the string line length too long for a single line in the
> text box and that triggers some weird bug in GTK+?

I tested this theory already. The box will take significantly longer lines than the one being generated.
Comment 16 oliver.steven 2018-01-17 19:42:35 UTC
I figured out how to fix my issue, but I still don't really understand why this was a problem in the first place.

I pruned down my project to the bare necessities I needed to create the issue. This included removing whole source code files, modifying the remaining source code files, and even removing objects from my Glade UI files. After all of that was done, the program was still crashing.

Finally, I started playing around in Glade to see if there was another way to display my results besides a text view. While trying to add back my text view to another object I found I could use a ViewPort instead of a ScrolledWindow. I have no idea how I stumbled upon that. Anyway, replacing the ScrolledWindow with ViewPort appears to have fixed my issue!

Perhaps Rico Tzschichholz was correct, this is some of king of obscure GTK bug and not a Vala issue.