GNU bug report logs - #44724
Uninitialised variables in syntax.c cause trouble.

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Wed, 18 Nov 2020 17:39:01 UTC

Severity: normal

Tags: notabug

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 44724 in the body.
You can then email your comments to 44724 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#44724; Package emacs. (Wed, 18 Nov 2020 17:39:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 18 Nov 2020 17:39:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Uninitialised variables in syntax.c cause trouble.
Date: Wed, 18 Nov 2020 17:38:34 +0000
Hello, Emacs.

On the master branch.

In src/syntax.c, there are several uninitialised static variables, one of
which is find_start_value.

It is used in function find_defun_start before being initialised.  The
first use is at L.14 of the function, this:

      && pos >= find_start_value

.  This has the effect of causing a certain (forward-comment -1) (which
calls back_comment, which calls find_defun_start) to fail.

In my test setup (I am writing tests for syntax.c), find_start_value's
value at loading time was randomly 1270, which was spuriously inside the
comment I was trying to scan backwards over.  back_comment thus failed to
recognise the comment, and returned failed.

All these variables need initialising to something if the code in
syntax.c is to work properly.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44724; Package emacs. (Wed, 18 Nov 2020 17:58:02 GMT) Full text and rfc822 format available.

Message #8 received at 44724 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Alan Mackenzie <acm <at> muc.de>, 44724 <at> debbugs.gnu.org
Subject: Re: bug#44724: Uninitialised variables in syntax.c cause trouble.
Date: Wed, 18 Nov 2020 18:57:37 +0100
> In src/syntax.c, there are several uninitialised static variables, one of
> which is find_start_value.
>
> It is used in function find_defun_start before being initialised.  The
> first use is at L.14 of the function, this:
>
>        && pos >= find_start_value
>
> .  This has the effect of causing a certain (forward-comment -1) (which
> calls back_comment, which calls find_defun_start) to fail.
>
> In my test setup (I am writing tests for syntax.c), find_start_value's
> value at loading time was randomly 1270, which was spuriously inside the
> comment I was trying to scan backwards over.  back_comment thus failed to
> recognise the comment, and returned failed.

Just curious: Did current_buffer == find_start_buffer really succeed
in your scenario?

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44724; Package emacs. (Wed, 18 Nov 2020 20:27:02 GMT) Full text and rfc822 format available.

Message #11 received at 44724 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 44724 <at> debbugs.gnu.org
Subject: Re: bug#44724: Uninitialised variables in syntax.c cause trouble.
Date: Wed, 18 Nov 2020 20:26:10 +0000
Hello, Martin.

On Wed, Nov 18, 2020 at 18:57:37 +0100, martin rudalics wrote:
>  > In src/syntax.c, there are several uninitialised static variables, one of
>  > which is find_start_value.

>  > It is used in function find_defun_start before being initialised.  The
>  > first use is at L.14 of the function, this:

>  >        && pos >= find_start_value

>  > .  This has the effect of causing a certain (forward-comment -1) (which
>  > calls back_comment, which calls find_defun_start) to fail.

>  > In my test setup (I am writing tests for syntax.c), find_start_value's
>  > value at loading time was randomly 1270, which was spuriously inside the
>  > comment I was trying to scan backwards over.  back_comment thus failed to
>  > recognise the comment, and returned failed.

> Just curious: Did current_buffer == find_start_buffer really succeed
> in your scenario?

Yes it did.  All four comparisons in that block of code succeeded,
causing a spurious value to be returned by find_defun_start.

But now I think that that value was a previously valid one which just
hadn't been updated on buffer changes.

I don't think there's any cache invalidation code associated with this
cache, and I think that's why it gave an invalid result.

> martin

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44724; Package emacs. (Thu, 19 Nov 2020 08:27:02 GMT) Full text and rfc822 format available.

Message #14 received at 44724 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 44724 <at> debbugs.gnu.org
Subject: Re: bug#44724: Uninitialised variables in syntax.c cause trouble.
Date: Thu, 19 Nov 2020 09:25:50 +0100
>> Just curious: Did current_buffer == find_start_buffer really succeed
>> in your scenario?
>
> Yes it did.  All four comparisons in that block of code succeeded,
> causing a spurious value to be returned by find_defun_start.

Isn't the probability for such a thing to be caused by uninitialized
variables lower than that of the Emacs tagging scheme to fail as a
whole?

> But now I think that that value was a previously valid one which just
> hadn't been updated on buffer changes.
>
> I don't think there's any cache invalidation code associated with this
> cache,

MODIFF == find_start_modiff

> and I think that's why it gave an invalid result.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44724; Package emacs. (Thu, 19 Nov 2020 16:31:01 GMT) Full text and rfc822 format available.

Message #17 received at 44724 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 44724 <at> debbugs.gnu.org
Subject: Re: bug#44724: Uninitialised variables in syntax.c cause trouble.
Date: Thu, 19 Nov 2020 16:30:32 +0000
Hello, Martin.

On Thu, Nov 19, 2020 at 09:25:50 +0100, martin rudalics wrote:
>  >> Just curious: Did current_buffer == find_start_buffer really succeed
>  >> in your scenario?

>  > Yes it did.  All four comparisons in that block of code succeeded,
>  > causing a spurious value to be returned by find_defun_start.

> Isn't the probability for such a thing to be caused by uninitialized
> variables lower than that of the Emacs tagging scheme to fail as a
> whole?

Yes.

>  > But now I think that that value was a previously valid one which just
>  > hadn't been updated on buffer changes.

>  > I don't think there's any cache invalidation code associated with this
>  > cache,

> MODIFF == find_start_modiff

Yes, thanks, I was wrong there.

>  > and I think that's why it gave an invalid result.

I've found out what my problem is.  find_defun_start, unless one takes
precautions against it, calls syntax-ppss, which in my situation was
uninitialised.  There is nothing in Emacs to cause the initialisation of
syntax-ppss when, say, the syntax-table is changed.  It all needs to be
done by hand.

I'll close this bug as not a bug.

Thanks for all the help!

> martin

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44724; Package emacs. (Tue, 24 Nov 2020 08:03:01 GMT) Full text and rfc822 format available.

Message #20 received at 44724 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: martin rudalics <rudalics <at> gmx.at>, 44724 <at> debbugs.gnu.org
Subject: Re: bug#44724: Uninitialised variables in syntax.c cause trouble.
Date: Tue, 24 Nov 2020 09:02:29 +0100
Alan Mackenzie <acm <at> muc.de> writes:

> I'll close this bug as not a bug.

This wasn't done, so I'm doing that now.

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




Added tag(s) notabug. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 24 Nov 2020 08:03:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 44724 <at> debbugs.gnu.org and Alan Mackenzie <acm <at> muc.de> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 24 Nov 2020 08:03:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 22 Dec 2020 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 174 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.