Re: [code] [textadept] Macros/add-ons for quick C/C++ function traversal?

From: ardi <ardillasdelmonte.att.gmail.com>
Date: Sun, 14 Oct 2018 12:54:07 +0200

Thanks a lot, Mitchell. It seems that the regex engine that you are
using is not crash-safe (even from the find UI at the bottom of the TA
window). I'm trying to get the regex at
https://regex101.com/r/hE9iF2/3 working in TA. It doesn't work out of
the box, so I tried to tweak the syntax, and in the process I was able
to crash TA by using the find UI. For example, typing this regex in
the find field:

^[a-zA-Z]([^;#\\"'{}=><!/]|\\n)*\\\\)[ \\t]*\\n?[ \\t]*\\\\{

Yes, I know this regex is wrong because it has C-string syntax
(backslashes are escaped), but even if it's wrong, it shouldn't crash
TA, just issue a syntax error for example.

The procedure for reproducing the crash is straightforward:

-Open TA
-Open a C file.
-Show the Find UI.
-Copy and paste the regex above, exactly in the search field.
-Choose regex mode.
-Click "Find Next", and voila!

Thanks a lot,

ardi

On Sat, Oct 13, 2018 at 10:15 PM Mitchell <m.att.foicica.com> wrote:
>
> Hi ardi,
>
> On Sat, 13 Oct 2018, ardi wrote:
>
> > On Thu, Oct 11, 2018 at 2:55 PM Mitchell <m.att.foicica.com> wrote:
> > [...]
> >>
> >> buffer:search_anchor()
> >> local pos = buffer:search_next(buffer.FIND_REGEXP, regex)
> >> if pos ~= -1 then
> >> buffer:goto_pos(pos)
> >> else
> >> -- try another regex
> >> end
> >>
> >> where `regex` is your regex to match a function block. I'm pretty sure multi-line regex searches do not work,
> >> but you'd have to double-check. You can also use a loop to iterate over a table of regexes to try.
> >
> > I tried to start by implementing a simple function that searches the
> > '^{' regex backwards. I put it inside a "init.lua" file in
> > "~/.textadept/modules/common" while performing a require("common") in
> > my ~/.textadept/init.lua but however I'm making TA crash.
> >
> > The code in "~/.textadept/modules/common/init.lua" is as follows. Any
> > idea on why it's making TA crash?
> >
> > local function PrevCFunction()
> > buffer:search_anchor()
> > local pos = buffer:search_prev(buffer.FIND_REGEXP, '^{')
> > if pos ~= -1 then
> > buffer:goto_pos(pos)
> > end
> > end
> >
> > keys.f3 = PrevCFunction
> >
> > If the regex is '^[a-zA-Z]' then it doesn't crash...
> >
> > I'm guessing I'm doing something in an obviously wrong way, perhaps
> > I'm trying to do things quicker than I should.
>
> When I open up the command entry and type `buffer:search_prev(buffer.REGEXP, '^{')`, I'm not seeing a crash. Are you on Linux? If so, and if you have gdb installed, you can fetch a nightly build, run `gdb textadept` from a terminal in the Textadept directory, type the `r` command and hit enter, trigger the crash, and then type `bt` followed by enter for a stacktrace. Post the stacktrace here.
>
> It's also possible that you have to escape the brace in your regex: '^\\{' (remember '\\' is needed for one '\' in Lua strings).
>
> Cheers,
> Mitchell
> --
> You are subscribed to code.att.foicica.com.
> To change subscription settings, send an e-mail to code+help.att.foicica.com.
> To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
>

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Sun 14 Oct 2018 - 06:54:07 EDT

This archive was generated by hypermail 2.2.0 : Mon 15 Oct 2018 - 06:32:21 EDT