@@ -834,7 +834,30 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim/*, int typ
834
834
return _zval_get_long_func (dim );
835
835
}
836
836
837
- static void ZEND_FASTCALL zend_jit_fetch_dim_str_r_helper (zval * container , zval * dim , zval * result )
837
+ static zend_always_inline zend_string * zend_jit_fetch_dim_str_offset (zend_string * str , zend_long offset )
838
+ {
839
+ if (UNEXPECTED ((zend_ulong )offset >= (zend_ulong )ZSTR_LEN (str ))) {
840
+ if (EXPECTED (offset < 0 )) {
841
+ /* Handle negative offset */
842
+ zend_long real_offset = (zend_long )ZSTR_LEN (str ) + offset ;
843
+
844
+ if (EXPECTED (real_offset >= 0 )) {
845
+ return ZSTR_CHAR ((zend_uchar )ZSTR_VAL (str )[real_offset ]);
846
+ }
847
+ }
848
+ zend_error (E_WARNING , "Uninitialized string offset " ZEND_LONG_FMT , offset );
849
+ return ZSTR_EMPTY_ALLOC ();
850
+ } else {
851
+ return ZSTR_CHAR ((zend_uchar )ZSTR_VAL (str )[offset ]);
852
+ }
853
+ }
854
+
855
+ static zend_string * ZEND_FASTCALL zend_jit_fetch_dim_str_offset_r_helper (zend_string * str , zend_long offset )
856
+ {
857
+ return zend_jit_fetch_dim_str_offset (str , offset );
858
+ }
859
+
860
+ static zend_string * ZEND_FASTCALL zend_jit_fetch_dim_str_r_helper (zend_string * str , zval * dim )
838
861
{
839
862
zend_long offset ;
840
863
@@ -843,22 +866,10 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_str_r_helper(zval *container, zval
843
866
} else {
844
867
offset = Z_LVAL_P (dim );
845
868
}
846
-
847
- if (UNEXPECTED (Z_STRLEN_P (container ) < ((offset < 0 ) ? - (size_t )offset : ((size_t )offset + 1 )))) {
848
- zend_error (E_WARNING , "Uninitialized string offset " ZEND_LONG_FMT , offset );
849
- ZVAL_EMPTY_STRING (result );
850
- } else {
851
- zend_uchar c ;
852
- zend_long real_offset ;
853
-
854
- real_offset = (UNEXPECTED (offset < 0 )) /* Handle negative offset */
855
- ? (zend_long )Z_STRLEN_P (container ) + offset : offset ;
856
- c = (zend_uchar )Z_STRVAL_P (container )[real_offset ];
857
- ZVAL_CHAR (result , c );
858
- }
869
+ return zend_jit_fetch_dim_str_offset (str , offset );
859
870
}
860
871
861
- static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper (zval * container , zval * dim , zval * result )
872
+ static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper (zend_string * str , zval * dim , zval * result )
862
873
{
863
874
zend_long offset ;
864
875
@@ -892,16 +903,19 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper(zval *container, zval
892
903
offset = Z_LVAL_P (dim );
893
904
}
894
905
895
- if (UNEXPECTED (Z_STRLEN_P (container ) < ((offset < 0 ) ? - (size_t )offset : ((size_t )offset + 1 )))) {
906
+ if ((zend_ulong )offset >= (zend_ulong )ZSTR_LEN (str )) {
907
+ if (offset < 0 ) {
908
+ /* Handle negative offset */
909
+ zend_long real_offset = (zend_long )ZSTR_LEN (str ) + offset ;
910
+
911
+ if (real_offset >= 0 ) {
912
+ ZVAL_CHAR (result , (zend_uchar )ZSTR_VAL (str )[real_offset ]);
913
+ return ;
914
+ }
915
+ }
896
916
ZVAL_NULL (result );
897
917
} else {
898
- zend_uchar c ;
899
- zend_long real_offset ;
900
-
901
- real_offset = (UNEXPECTED (offset < 0 )) /* Handle negative offset */
902
- ? (zend_long )Z_STRLEN_P (container ) + offset : offset ;
903
- c = (zend_uchar )Z_STRVAL_P (container )[real_offset ];
904
- ZVAL_CHAR (result , c );
918
+ ZVAL_CHAR (result , (zend_uchar )ZSTR_VAL (str )[offset ]);
905
919
}
906
920
}
907
921
0 commit comments