bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#19208: replace-match unhelpful error message


From: Paul Eggert
Subject: bug#19208: replace-match unhelpful error message
Date: Sat, 3 Aug 2019 13:22:26 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

No, that's just another sanity check -- num_regs is the max allowed
number of sub-matches.  (I've now added some comments to clarify.)

Unfortunately that patch messes up the sanity check, as the patched code allows 'sub' to be negative, or to be equal to search_regs.num_regs, and in either case this results in a bad pointer.

Yoda conditionals and a !...

Actually those were Leibniz conditionals, which are comparisons involving "<" or "<=". The idea is that the conditionals' textual order reflects numeric order. This is a common style in math when doing range checking, e.g., "0 <= i < n". Yoda conditionals are expressions like "0 != x" which I agree are confusing.

I learned Leibniz conditionals from the late Val Schorre, who was *really* good at programming and programming style: Knuth credits Schorre with the invention of goto-less programming in the early 1960s. When I redid your patch as a Leibniz conditional, I instantly spotted the bug that it introduced. You might give Leibniz conditionals a try, as they help make code more readable and reliable when checking for range errors or overflow.

While in the neighborhood I spotted some other rare possibilities for bad behavior due to out-of-range indexes. I fixed the bugs I found by installing the attached.

Attachment: 0001-Fix-rare-undefined-behaviors-in-replace-match.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]