Subject: Re: bug#75754: styled_format stack usage/GC protection

From: Eli Zaretskii <[email-masked]>
Date: Tue, 04 Feb 2025 14:21:00 +0200

> Date: Mon, 03 Feb 2025 21:02:17 +0000
> From: Pip Cet <[email-masked]>
> Cc: [email-masked], [email-masked]
> 
> "Eli Zaretskii" <[email-masked]> writes:
> 
> >> Date: Thu, 23 Jan 2025 23:58:41 +0000
> >> From: Pip Cet <[email-masked]>
> >> Cc: [email-masked], [email-masked]
> >>
> >> 1. Reload format_start and format (and end, and format0) after every
> >> call which might have GC'd.  If you think we should do this, please
> >> tell me whether lisp_string_width can GC.
> >
> > It can, if called with the last argument 'true' (because
> > find_automatic_composition calls into Lisp).  Currently, we call it
> > with 'false', so it cannot.
> >
> >> More importantly, assuming it doesn't, document this in every
> >> function in the call tree starting at lisp_string_width so we don't
> >> accidentally change it.
> >>
> >> 2. memcpy the format string.  Two-liner, more likely to fix the bug for
> >> good than (1), wastes more memory (since sa_avail has been negative
> >> since we entered the function, this is xmalloc'd memory).
> >>
> >> 3. replace format by a ptrdiff_t and all instances of *format by
> >> SREF (args[0], index).  Faster than 2, but many changes hurting
> >> readability.
> >
> > I prefer (2), I think.  Assuming it indeed fixes the problem.
> 
> I had to modify it slightly to copy the final NUL character (no harm
> done if it isn't used, but it does appear to be relied upon in a few
> places).
> 
> Pushed now.  Please test

Thanks, the test I wrote now passes, so I've installed it.

> 2. the crash tests need to be installed once we have a way of presenting
> "Emacs crashed" messages nicely for ERT tets.  Alternatively, just wait
> a few weeks; people who run new test suites on old Emacs versions can
> expect the occasional crash.

Does this mean you didn't want me to install the test?  It doesn't
crash.