unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: fabrice nicol <fabrnicol@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 47408@debbugs.gnu.org
Subject: bug#47408: [PATCH] Etags support for Mercury -- fix explicit tags for existentially-quantified procedures
Date: Mon, 14 Jun 2021 19:10:53 +0200	[thread overview]
Message-ID: <46a10b9f-91d7-63c4-1513-0af4743e0940@gmail.com> (raw)
In-Reply-To: <83lf7c5t6z.fsf@gnu.org>

Yes, I'm afraid that you missed something there this time around.

If you take a look at other languages that implement explicit tags (like 
Fortran) you will see that there are buffers coming in to avoid having 
'name' and 'linestart' (1st and 4th arguments to 'make_tag') share a 
same string pointer (here 's').

This is explained in the header comment to 'make_tag':

" 2. LINESTART contains name as either a rightmost, or rightmost but
  *     one character, substring;"

which is a bit of a convoluted constraint: better protect oneself and 
bufferize from the ground up.

In most cases (though perhaps with occasional exceptions), if I followed 
your suggestion, 'name' would be a substring with aon offset of  at 
least +2 bytes from start of string s.

When I applied you suggestion and tested, the TAGS base was as expected 
accordingly: wrong.

Fabrice


>> Thanks.  I didn't yet try to apply and run the patch, but one aspect
>> of the patch caused me to raise mu brow:
>>
>> +      char *name = xnew (pos + 1, char);
>> +      size_t namelength = position.namelength;
>> +      if (stop_at_rule && offset) --offset;
>> +
>> +      /* Left-trim type definitions.  */
>> +
>> +      while (pos > namelength + offset
>> +	     && c_isspace (s[pos - namelength - offset]))
>> +	--offset;
>> +
>> +      memcpy (name, s + pos - namelength - offset, namelength);
>> +
>> +      /* There is no need to correct namelength or call notinname.  */
>> +      name[namelength - 1] = '\0';
>> +
>> +      make_tag (name, namelength, true, s, pos, lineno, linecharno);
>> +      free (name);
> Why do you copy the identifier's name into a newly-allocated buffer,
> instead of just passing 's + pos - namelength - offset' and
> 'namelength' as the first 2 arguments of make_tag?  Isn't this
> xnew+memcpy+free dance here redundant?  Or what did I miss?





  reply	other threads:[~2021-06-14 17:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.12421.1623412982.2554.bug-gnu-emacs@gnu.org>
2021-06-14 15:10 ` bug#47408: [PATCH] Etags support for Mercury -- fix explicit tags for existentially-quantified procedures fabrice nicol
2021-06-14 16:04   ` Eli Zaretskii
2021-06-14 17:10     ` fabrice nicol [this message]
2021-06-14 17:42       ` Eli Zaretskii
2021-06-14 18:52         ` fabrice nicol
2021-06-17 10:50           ` Eli Zaretskii
2021-06-17 11:19             ` Fabrice Nicol
2021-06-17 11:42               ` Eli Zaretskii
2021-06-17 18:36                 ` fabrice nicol
2021-06-18 11:29                   ` Eli Zaretskii
2021-06-18 11:54                     ` Francesco Potortì
2021-06-18 12:33                       ` Eli Zaretskii
2021-06-18 13:53                         ` fabrice nicol

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46a10b9f-91d7-63c4-1513-0af4743e0940@gmail.com \
    --to=fabrnicol@gmail.com \
    --cc=47408@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).