In src/string.c, the documentation for string_substr() says:

=item C<STRING * string_substr>

Copies the substring of length C<length> from C<offset> from the specified
Parrot string and stores it in C<**d>, allocating memory if necessary. The
substring is also returned.

=cut

*/

The signature is:

PARROT_API
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
STRING *
string_substr(PARROT_INTERP,
        ARGIN_NULLOK(STRING *src), INTVAL offset, INTVAL length,
        ARGOUT_NULLOK(STRING **d), int replace_dest);

Does it ever make sense to have a negative length?

The only code path that really looks at length is:

        /* Allow regexes to return $' easily for "aaa" =~ /aaa/ */
        if (offset == (INTVAL)string_length(interp, src) || length < 1)
            return string_make_empty(interp, enum_stringrep_one, 0);

        /* ... */
        true_length = (UINTVAL)length;

As far as I can tell, making length unsigned has no ill effects throughout the 
system.

(I'm making as many parameters and struct members unsigned as possible so that 
the compiler can warn us if we ever use signed values with them.  This is one 
nice way to check some of our assumptions.)

-- c

Reply via email to