unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* New warning in indent.c
@ 2020-04-16  8:59 Juanma Barranquero
  2020-04-16 10:09 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Juanma Barranquero @ 2020-04-16  8:59 UTC (permalink / raw)
  To: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 420 bytes --]

This warning appeared a while ago. A quick perusal didn't find an obvious
recent commit changing indent.c, though I supposed I missed it.

indent.c: In function 'Fvertical_motion':
indent.c:2284:4: warning: 'lcols' may be used uninitialized in this
function [-Wmaybe-uninitialized]
 2284 |    window_column_x (w, window, extract_float (lcols), lcols)
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[-- Attachment #2: Type: text/html, Size: 490 bytes --]

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

* Re: New warning in indent.c
  2020-04-16  8:59 New warning in indent.c Juanma Barranquero
@ 2020-04-16 10:09 ` Eli Zaretskii
  2020-04-16 16:27   ` Paul Eggert
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2020-04-16 10:09 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: emacs-devel

> From: Juanma Barranquero <lekktu@gmail.com>
> Date: Thu, 16 Apr 2020 10:59:40 +0200
> 
> This warning appeared a while ago. A quick perusal didn't find an obvious recent commit changing indent.c,
> though I supposed I missed it.
> 
> indent.c: In function 'Fvertical_motion':
> indent.c:2284:4: warning: 'lcols' may be used uninitialized in this function [-Wmaybe-uninitialized]
>  2284 |    window_column_x (w, window, extract_float (lcols), lcols)
>       |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Stupid GCC.  I guess the "change" which triggered this was a newer GCC
version.

Should be fixed now.



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

* Re: New warning in indent.c
  2020-04-16 10:09 ` Eli Zaretskii
@ 2020-04-16 16:27   ` Paul Eggert
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Eggert @ 2020-04-16 16:27 UTC (permalink / raw)
  To: Eli Zaretskii, Juanma Barranquero; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 472 bytes --]

On 4/16/20 3:09 AM, Eli Zaretskii wrote:

> I guess the "change" which triggered this was a newer GCC version.

Yes, most likely. However, the warning was a symptom of an underlying problem: 
the code wasn't checking the type of 'lcols' early enough. I fixed the 
underlying problem via the attached patch, and this should remove the need for 
pacifying GCC. In some sense I suppose we should be grateful for GCC's silly 
warning here, as it pointed out the awkward code.

[-- Attachment #2: 0001-Fix-type-checking-bug-in-vertical-motion.patch --]
[-- Type: text/x-patch, Size: 1984 bytes --]

From 20bbe91ce7f3abd510a5f4b0ef29eb01d5e7e0e2 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 16 Apr 2020 09:22:42 -0700
Subject: [PATCH] Fix type-checking bug in vertical-motion

* src/indent.c (Fvertical_motion): Fix bug where the type of lcols
was checked too late.
---
 src/indent.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/indent.c b/src/indent.c
index dd81b983d4..06f11a251e 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -2091,19 +2091,17 @@ DEFUN ("vertical-motion", Fvertical_motion, Svertical_motion, 1, 3, 0,
   struct it it;
   struct text_pos pt;
   struct window *w;
-  Lisp_Object lcols;
+  Lisp_Object lcols = Qnil;
   void *itdata = NULL;
   ptrdiff_t count = SPECPDL_INDEX ();
 
   /* Allow LINES to be of the form (HPOS . VPOS) aka (COLUMNS . LINES).  */
-  bool lcols_given = CONSP (lines);
-  if (lcols_given)
+  if (CONSP (lines))
     {
       lcols = XCAR (lines);
+      CHECK_NUMBER (lcols);
       lines = XCDR (lines);
     }
-  else
-    lcols = make_fixnum (0);	/* shut up stupid GCC warning */
 
   CHECK_FIXNUM (lines);
   w = decode_live_window (window);
@@ -2281,9 +2279,9 @@ DEFUN ("vertical-motion", Fvertical_motion, Svertical_motion, 1, 3, 0,
 
 	  overshoot_handled = 1;
 	}
-      if (lcols_given)
+      if (!NILP (lcols))
 	to_x =
-	  window_column_x (w, window, extract_float (lcols), lcols)
+	  window_column_x (w, window, XFLOATINT (lcols), lcols)
 	  + lnum_pixel_width;
       if (nlines <= 0)
 	{
@@ -2334,7 +2332,7 @@ DEFUN ("vertical-motion", Fvertical_motion, Svertical_motion, 1, 3, 0,
       /* Move to the goal column, if one was specified.  If the window
 	 was originally hscrolled, the goal column is interpreted as
 	 an addition to the hscroll amount.  */
-      if (lcols_given)
+      if (!NILP (lcols))
 	{
 	  move_it_in_display_line (&it, ZV, first_x + to_x, MOVE_TO_X);
 	  /* If we find ourselves in the middle of an overlay string
-- 
2.17.1


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

end of thread, other threads:[~2020-04-16 16:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-16  8:59 New warning in indent.c Juanma Barranquero
2020-04-16 10:09 ` Eli Zaretskii
2020-04-16 16:27   ` Paul Eggert

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