Seems to be perfectly defined for this purpose.
STRLEN is used for variables whose value will passed to the last argument of memcpy and for those that will receive the result of strlen. I don't see why it would be more suitable to use a different type than the actual type the functions use.
The problem is, as you pointed out above, size_t, (actually defined as what sizeof() returns), is an unsigned type, and therefore cannot handle negative indexing.
It does not need to handle negative indexing. The position and length are normalised before being stored into STRLEN vars, and the IV vars in which they stored as they are being normalised can already handle negative numbers. Putting the position and length into signed STRLEN vars instead of (signed) IV vars is not going to help simplify pp_substr any.
There are three ways of simplifying pp_substr:
If the maximum string length is no bigger than IV_MAX on all platforms, the simplest solution is to add a range check at the top and treat the position and length as IV vars on out.
if (SvIOK_UV(pos_sv) && (UV)pos_iv > (UV)IV_MAX) goto BOUND_FAIL; if (SvIOK_UV(len_sv) && (UV)len_iv > (UV)IV_MAX) len_iv = IV_MAX;
Dictate that the arguments to substr are limited to the range of IV instead of IV+UV. Tough luck if your system supports longer strings. The code would be identical to the code in the previous bullet.
Define a type that can hold the entire supported range of positions and lengths, reducing the supported range of positions and lengths on some platforms if necessary. Check the arguments against that type's maximum value, then use the that type for pos_iv and len_iv.
In reply to Re^7: [OT] LLP64 .v. LP64 portability
by ikegami
in thread [OT] LLP64 .v. LP64 portability
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |