unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#8215: possibly uninitialized variable lower_xoff in produce_glyphless_glyph
@ 2011-03-09 22:00 Paul Eggert
  2021-06-02  8:06 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Eggert @ 2011-03-09 22:00 UTC (permalink / raw)
  To: 8215

I found this problem by compiling Emacs with GCC's -Wuninitialized flag.

The following code in the Emacs trunk src/xdisp.c's
produce_glyphless_glyph function might be using an uninitialized
variable:

       if (base_width >= width)
	{
	  /* Align the upper to the left, the lower to the right.  */
	  it->pixel_width = base_width;
	  lower_xoff = base_width - 2 - metrics_lower.width;
	}
       else
	{
	  /* Center the shorter one.  */
	  it->pixel_width = width;
	  if (metrics_upper.width >= metrics_lower.width)
	    lower_xoff = (width - metrics_lower.width) / 2;
	  else
	    upper_xoff = (width - metrics_upper.width) / 2;
	}
   ...
   if (it->glyph_row)
     append_glyphless_glyph (it, face_id, for_no_font, len,
			    upper_xoff, upper_yoff,
			    lower_xoff, lower_yoff);

The last call uses lower_xoff, but the last "else" does not initialize
lower_xoff.  The bug cannot occur if it->glyph_row is NULL, but I
don't see why that would necessarily be.  So I'm filing a bug report
so that someone who is more expert in this code can take a look at it.
In the meantime, I plan to work around the problem by initializing
lower_xoff to 0, with a FIXME explaining the situation: this shouldn't
introduce a bug, because at worst it will replace undefined behavior
with defined behavior.

I'm CC'ing this to Kenichi Handa, who committed the code in question.





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

* bug#8215: possibly uninitialized variable lower_xoff in produce_glyphless_glyph
  2011-03-09 22:00 bug#8215: possibly uninitialized variable lower_xoff in produce_glyphless_glyph Paul Eggert
@ 2021-06-02  8:06 ` Lars Ingebrigtsen
  2021-06-02 13:17   ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-02  8:06 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8215, Kenichi Handa

Paul Eggert <eggert@cs.ucla.edu> writes:

> In the meantime, I plan to work around the problem by initializing
> lower_xoff to 0, with a FIXME explaining the situation: this shouldn't
> introduce a bug, because at worst it will replace undefined behavior
> with defined behavior.

It looks like this code is still in place now, ten years later:

diff --git a/src/xdisp.c b/src/xdisp.c
index 44cb713011..44a317b578 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -22292,7 +22292,13 @@ produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym)
 	  if (metrics_upper.width >= metrics_lower.width)
 	    lower_xoff = (width - metrics_lower.width) / 2;
 	  else
-	    upper_xoff = (width - metrics_upper.width) / 2;
+	    {
+	      /* FIXME: This code doesn't look right.  It formerly was
+		 missing the "lower_xoff = 0;", which couldn't have
+		 been right since it left lower_xoff uninitialized.  */
+	      lower_xoff = 0;
+	      upper_xoff = (width - metrics_upper.width) / 2;
+	    }
 	}
 
       /* +5 is for horizontal bars of a box plus 1-pixel spaces at

Anybody have any insight into whether this is correct or not now?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#8215: possibly uninitialized variable lower_xoff in produce_glyphless_glyph
  2021-06-02  8:06 ` Lars Ingebrigtsen
@ 2021-06-02 13:17   ` Eli Zaretskii
  2021-06-06  9:00     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2021-06-02 13:17 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Kenichi Handa, eggert, 8215

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Wed, 02 Jun 2021 10:06:29 +0200
> Cc: 8215@debbugs.gnu.org, Kenichi Handa <handa@m17n.org>
> 
> Paul Eggert <eggert@cs.ucla.edu> writes:
> 
> > In the meantime, I plan to work around the problem by initializing
> > lower_xoff to 0, with a FIXME explaining the situation: this shouldn't
> > introduce a bug, because at worst it will replace undefined behavior
> > with defined behavior.
> 
> It looks like this code is still in place now, ten years later:
> 
> diff --git a/src/xdisp.c b/src/xdisp.c
> index 44cb713011..44a317b578 100644
> --- a/src/xdisp.c
> +++ b/src/xdisp.c
> @@ -22292,7 +22292,13 @@ produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym)
>  	  if (metrics_upper.width >= metrics_lower.width)
>  	    lower_xoff = (width - metrics_lower.width) / 2;
>  	  else
> -	    upper_xoff = (width - metrics_upper.width) / 2;
> +	    {
> +	      /* FIXME: This code doesn't look right.  It formerly was
> +		 missing the "lower_xoff = 0;", which couldn't have
> +		 been right since it left lower_xoff uninitialized.  */
> +	      lower_xoff = 0;
> +	      upper_xoff = (width - metrics_upper.width) / 2;
> +	    }
>  	}
>  
>        /* +5 is for horizontal bars of a box plus 1-pixel spaces at
> 
> Anybody have any insight into whether this is correct or not now?

I fixed this (and removed the FIXME with the incorrect
initialization).  Bottom line: it was a typo.





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

* bug#8215: possibly uninitialized variable lower_xoff in produce_glyphless_glyph
  2021-06-02 13:17   ` Eli Zaretskii
@ 2021-06-06  9:00     ` Lars Ingebrigtsen
  2021-06-06  9:13       ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-06  9:00 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Kenichi Handa, eggert, 8215

Eli Zaretskii <eliz@gnu.org> writes:

> I fixed this (and removed the FIXME with the incorrect
> initialization).  Bottom line: it was a typo.

Nice catch.  :-)  I tried reading that function for a couple of minutes
to try to make sense how lower_xoff should have been initialised, but I
had to admit defeat.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#8215: possibly uninitialized variable lower_xoff in produce_glyphless_glyph
  2021-06-06  9:00     ` Lars Ingebrigtsen
@ 2021-06-06  9:13       ` Eli Zaretskii
  0 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2021-06-06  9:13 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: handa, eggert, 8215

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: eggert@cs.ucla.edu,  8215@debbugs.gnu.org,  Kenichi Handa <handa@gnu.org>
> Date: Sun, 06 Jun 2021 11:00:04 +0200
> 
> Nice catch.  :-)  I tried reading that function for a couple of minutes
> to try to make sense how lower_xoff should have been initialised, but I
> had to admit defeat.

The reason we didn't have the fix earlier is that the problem is only
visible when the default face's font is variable-pitch, otherwise the
offending code is never executed.  So it was hard to understand what
that "workaround" initialization caused.

Let me know if I should add some comments there to make the code's
intent and purpose more clear.





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

end of thread, other threads:[~2021-06-06  9:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-09 22:00 bug#8215: possibly uninitialized variable lower_xoff in produce_glyphless_glyph Paul Eggert
2021-06-02  8:06 ` Lars Ingebrigtsen
2021-06-02 13:17   ` Eli Zaretskii
2021-06-06  9:00     ` Lars Ingebrigtsen
2021-06-06  9:13       ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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