Skip to content

Conversation

khwilliamson
Copy link
Contributor

@khwilliamson khwilliamson commented Sep 26, 2025

There are a bunch of functions that are passed both a string pointer and a pointer to the string end. This commit allows you to declare the latter in embed.fnc, and have an assert(s < e) generated that goes in the PERL_ARGS_ASSERT for the function.

This is extended for functions where it should instead be assert(s <= e) and assert(s <= cur)

  • This set of changes does not require a perldelta entry.

Inspection showed these were wrongly categorized
Wrap to fit in 80 column terminal window
Where s is a pointer into a string, and e is the end of it.
I went through the declarations in embed.fnc and added PTR hints for all
the ones that looked to have pointers to the beginning and end of a
string.  I then ran the test suite, and reverted any that had problems.

This is the result.  Testing in the field may reveal others that the
test suite missed; we can fix those as they occur.
This is the first use of the new MPTR hint that is used to generate an
assertion that a pointer is somewhere in the middle of a string.
Generally, a pointer to a string upper bound actually to one beyond the
actual final byte in the string.  This is sanctioned by the C Standard,
and allows you to just subtract the lower bound from it to get its
length, without having to add 1.

But some function we have tolerate the upper bound pointer being set to
the actual final byte.  The EPTRQ hint in embed.fnc is used for those;
the assertion becomes 'l <= u' instead of strictly less-than.

This commit is the first to use this type of hint, and it applies it
only to those functions whose documentation and behavior clearly
indicate this is expected.

There's a dozen-ish ones where that isn't true.  And they need to be
investigated further before deciding their disposition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant