]> git.donarmstrong.com Git - lilypond.git/blob - debian/patches/Issue-4814-grob.cc-segfaults-with-gcc6
Cherrypick fix for upstream issue 4814 which fixes segfaults in grob.cc in newer...
[lilypond.git] / debian / patches / Issue-4814-grob.cc-segfaults-with-gcc6
1 From b0dce76daf27721ba157cd2ac5d7662d4c8d75f8 Mon Sep 17 00:00:00 2001
2 From: Guido Aulisi <guido.aulisi@gmail.com>
3 Date: Fri, 22 Jul 2016 15:26:29 +0200
4 Subject: [PATCH] Issue 4814: grob.cc segfaults with gcc6
5
6 From the release notes of GCC 6:
7
8     Optimizations remove null pointer checks for this
9
10     When optimizing, GCC now assumes the this pointer can never be null,
11     which is guaranteed by the language rules. Invalid programs which
12     assume it is OK to invoke a member function through a null
13     pointer (possibly relying on checks like this != NULL) may crash or
14     otherwise fail at run time if null pointer checks are optimized
15     away. With the -Wnull-dereference option the compiler tries to warn
16     when it detects such invalid code.
17
18     If the program cannot be fixed to remove the undefined behavior then
19     the option -fno-delete-null-pointer-checks can be used to disable
20     this optimization. That option also disables other optimizations
21     involving pointers, not only those involving this.
22
23 As a consequence, we cannot call a member function on a prospective null
24 pointer (which actually is a bad idea for a number of other reasons,
25 like when anything tries accessing the vtable) and then try sorting out
26 the condition in the routine itself.
27
28 This problem was first observed with Fedora 24.  The Ubuntu GCC6
29 prerelease does not show this problem; presumably the respective
30 optimization has been disabled in the Ubuntu/Debian packaging because of
31 affecting other programs.
32
33 Commit-message-by: David Kastrup <dak@gnu.org>
34 Signed-off-by: David Kastrup <dak@gnu.org>
35 ---
36  lily/grob.cc | 5 +++--
37  1 file changed, 3 insertions(+), 2 deletions(-)
38
39 diff --git a/lily/grob.cc b/lily/grob.cc
40 index 7ce89d5015..eafa66288e 100644
41 --- a/lily/grob.cc
42 +++ b/lily/grob.cc
43 @@ -333,7 +333,7 @@ Real
44  Grob::relative_coordinate (Grob const *refp, Axis a) const
45  {
46    /* eaa - hmmm, should we do a programming_error() here? */
47 -  if ((this == NULL) || (refp == this))
48 +  if (refp == this)
49      return 0.0;
50  
51    /* We catch PARENT_L_ == nil case with this, but we crash if we did
52 @@ -342,7 +342,8 @@ Grob::relative_coordinate (Grob const *refp, Axis a) const
53    if (refp == dim_cache_[a].parent_)
54      return off;
55  
56 -  off += dim_cache_[a].parent_->relative_coordinate (refp, a);
57 +  if (dim_cache_[a].parent_ != NULL)
58 +    off += dim_cache_[a].parent_->relative_coordinate (refp, a);
59  
60    return off;
61  }
62 -- 
63 2.11.0
64