fix(webserver): php_native_split function various issues - #146
Conversation
got3nks
left a comment
There was a problem hiding this comment.
Two small things worth fixing before merge:
-
Sign-compare warning —
piece_countisint,split_limitisunsigned int, sopiece_count >= split_limit - 1will warn under-Wsign-comparein both branches. Makingpiece_countunsigned intcleans it up. -
Limit convention — PHP's
split($pattern, $string, $limit = -1)uses-1as "no limit". The PR treats0as the default and only positive values as the cap, so a caller passing PHP's documented-1would underflow toUINT_MAX(accidentally unlimited). Switchingsplit_limitto signedintwith-1default and checkingsplit_limit > 0aligns with PHP semantics and avoids the underflow.
The four core fixes themselves all check out. Thanks for the contribution.
|
I made Please say me if now it is ok and if I need to squash. |
|
I missed one change in PR description: nmatch = string length is useless as only pmatch[0] used, so changed it to 1 (fixed value). |
got3nks
left a comment
There was a problem hiding this comment.
Drop the if ( split_limit <= 0 ) block — no return after it makes it inconsistent with the other error paths in this function, and -1 is the PHP-documented sentinel for "no limit" so emitting an error on it defeats the convention. The -1 default + the loop's split_limit > 0 gate already handle "no limit" cleanly.
si = get_scope_item(g_current_scope, "__param_2");
if ( si ) {
PHP_VALUE_NODE *limit_node = &si->var->value;
cast_value_dnum(limit_node);
split_limit = limit_node->int_val;
}No need to squash.
|
You are right, sorry, fix applied. |
got3nks
left a comment
There was a problem hiding this comment.
Now matches PHP semantics cleanly — -1 default, split_limit > 0 gate handles "no limit" silently, no spurious error. Thanks for the back-and-forth.
Summary
Fix various issues in the
php_native_splitfunction:split_limitparameter was missing (the error message also incorrectly reported 'string' instead of 'limit' as the parameter name) removing the uselesselsebranch since the parameter is optional.split_limitin the function by introducing apiece_countvariable to track segments and added a check at the start of thewhileloops (in both branches).Test plan
N/A