Commit Graph

668 Commits

Author SHA1 Message Date
Ayesh Karunaratne
b8e380ab09 Update deprecation message for incompatible float to int conversion
Updates the deprecation message for implicit incompatible float to int conversion from:

```
Implicit conversion from non-compatible float %.*H to int in %s on line %d
```

to

```
Implicit conversion from float %.*H to int loses precision in %s on line %d
```

Related: #6661
2021-06-07 14:36:11 +02:00
George Peter Banyard
b6958bb847
Implement "Deprecate implicit non-integer-compatible float to int conversions" RFC. (#6661)
RFC: https://wiki.php.net/rfc/implicit-float-int-deprecate

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-05-31 15:48:45 +01:00
George Peter Banyard
aca6aefd85
Remove 'register' type qualifier (#6980)
The compiler should be smart enough to optimize this on its own
2021-05-14 13:38:01 +01:00
Nikita Popov
0c5711856f Add zend_ulong_to_str() API
No point in going through a smart_str and append_unsigned if we
can construct the result directly...
2021-04-13 15:56:24 +02:00
Nikita Popov
65a5c184d7 Add functions to convert i64/u64 to string
PDO implement half of this, but this functionality is generally
useful. Provide these as zend_u64_to_str and zend_i64_to_str to
complement zend_long_to_str.
2021-04-13 15:43:23 +02:00
Josh Soref
462da6e09c Fix spelling and grammar mistakes
This PR corrects misspellings identified by the check-spelling action.

The misspellings have been reported at jsoref@b6ba3e2#commitcomment-48946465

The action reports that the changes in this PR would make it happy: jsoref@602417c

Closes GH-6822.
2021-04-13 12:09:37 +02:00
George Peter Banyard
5caaf40b43
Introduce pseudo-keyword ZEND_FALLTHROUGH
And use it instead of comments
2021-04-07 00:46:29 +01:00
Dmitry Stogov
9da66e6ad0 Optimized object conversion to array without rebulding properties HashTable 2021-03-01 22:37:37 +03:00
Dmitry Stogov
5e01542526 Improve basename(). Avoid calling mblen() for ASCII compatible locales. 2021-02-19 15:42:21 +03:00
Nikita Popov
353f7ffb6b Delref only after successful allocation
Otherwise we may have inconsistent refcounts after OOM.

I expect this problem is much more prevalent, but this at least
fixes some string/array separation cases.

Fixes oss-fuzz #30999.
2021-02-16 10:01:46 +01:00
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
We're starting to see a mix between uses of zend_bool and bool.
Replace all usages with the standard bool type everywhere.

Of course, zend_bool is retained as an alias.
2021-01-15 12:33:06 +01:00
Nikita Popov
058756b3bb Remove the convert_to_long_base function
This function is unused in php-src, and has somewhat dubious
semantics, especially since we switched convert_to_long to not
use strtol for the base 10 case.

If you want to convert strings from a different base, use
ZEND_STRTOL directly.
2021-01-15 10:43:26 +01:00
Nikita Popov
b429228420 Remove zend_locale_sprintf_double()
This function is unused, and also not particularly useful now that
PHP no longer prints doubles in a locale-sensitive way unless
someone really goes out of their way to force it.
2021-01-14 12:13:34 +01:00
Nikita Popov
66ecee6243 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Detect self-addition of array more accurately
  Deindirect source elements in zend_hash_merge
2020-10-12 11:25:27 +02:00
Nikita Popov
5a7f9afb99 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Detect self-addition of array more accurately
  Deindirect source elements in zend_hash_merge
2020-10-12 11:24:59 +02:00
Nikita Popov
3c4dd73c02 Detect self-addition of array more accurately
While the zvals may be different, they may still point to the
same array.

Fixes oss-fuzz #26245.
2020-10-12 11:24:31 +02:00
Nikita Popov
ae77c7b057 Return correct result code for division by zero
Turns out we do need to return FAILURE here on div by zero
exception. Use a three-way return value from div_function_base.

Fixes oss-fuzz #25975.
2020-10-02 12:09:14 +02:00
Nikita Popov
fb4554e431 Throw warning for failed object to int/float conversion
We previously couldn't increase the error level here because it
was coupled to comparison handling. This is no longer the case
in PHP 8.
2020-09-21 17:04:39 +02:00
George Peter Banyard
31ef94cd42 Convert Division by 0 warnings to Error per the Engine Warning RFC
Closes GH-6125
2020-09-14 13:40:07 +02:00
Máté Kocsis
3e800e997b
Move custom type checks to ZPP
Closes GH-6034
2020-09-02 11:11:38 +02:00
Nikita Popov
4acac9bd72 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix leak on assign concat of array and empty string
2020-08-31 17:06:21 +02:00
Nikita Popov
9560e3ba7a Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix leak on assign concat of array and empty string
2020-08-31 17:05:55 +02:00
Nikita Popov
cd2afd99b1 Fix leak on assign concat of array and empty string 2020-08-31 17:05:31 +02:00
George Peter Banyard
fa8d9b1183 Improve type declarations for Zend APIs
Voidification of Zend API which always succeeded
Use bool argument types instead of int for boolean arguments
Use bool return type for functions which return true/false (1/0)
Use zend_result return type for functions which return SUCCESS/FAILURE as they don't follow normal boolean semantics

Closes GH-6002
2020-08-28 15:41:27 +02:00
George Peter Banyard
b2248789ed Implement 'Saner Numeric Strings' RFC:
RFC: https://wiki.php.net/rfc/saner-numeric-strings

This removes the -1 allow_error mode from is_numeric_string functions and replaces it by
a trailing boolean out argument to preserve BC in a couple of places.

Most of the changes can be resumed to "numeric" strings which emitted a E_NOTICE now emit
a E_WARNING and "numeric" strings which emitted a E_WARNING now throw a TypeError.

This mostly affects:
 - String offsets
 - Arithmetic operations
 - Bitwise operations

Closes GH-5762
2020-07-29 02:51:09 +01:00
Andrea Faulds
f759936591 Permit trailing whitespace in numeric strings
This is part 1 of the 'Saner Numeric Strings' RFC:
https://wiki.php.net/rfc/saner-numeric-strings
2020-07-29 02:22:38 +01:00
Nikita Popov
acbf7802af Improved number to string comparison semantics
RFC: https://wiki.php.net/rfc/string_to_number_comparison

Closes GH-3886.
2020-07-22 12:23:49 +02:00
Christoph M. Becker
92c4b06513 Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0)
Instead of marking unreachable code with `ZEND_ASSERT(0)`, we introduce
`ZEND_UNREACHABLE()`, so that MSVC which does not consider `assert(0)`
to mark unreachable code does no longer trigger C4715[1] warnings in
debug builds.  This may be useful for other compilers as well.

[1] <https://docs.microsoft.com/de-de/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4715?view=vs-2019>
2020-06-16 18:39:09 +02:00
twosee
83a77015ad Add helper APIs for maybe-interned string creation
Add ZVAL_CHAR/RETVAL_CHAR/RETURN_CHAR as a shortcut for using
ZVAL_INTERNED_STRING and ZSTR_CHAR.

Add zend_string_init_fast() as a helper for the empty string /
one char interned string / zend_string_init() pattern.

Also add corresponding ZVAL_STRINGL_FAST etc macros.

Closes GH-5684.
2020-06-08 15:31:52 +02:00
Nikita Popov
c6a6ca078b Use zend_zval_type_name() API where possible
Rather than zend_get_type_by_const(Z_TYPE_P()).
2020-05-13 14:56:05 +02:00
George Peter Banyard
25acc4a6b4 Fix [-Wundef] warning in Zend folder 2020-05-12 22:01:51 +02:00
Nikita Popov
53f5cfd99e Drop multi_convert_* APIs
These are no longer used internally, and I'd rather they weren't
used externally either.
2020-05-12 17:10:06 +02:00
Máté Kocsis
4a816584a4
Make float to string casts locale-independent
From now on, float to string casting will always behave locale-independently.
RFC: https://wiki.php.net/rfc/locale_independent_float_to_string
Closes GH-5224

Co-authored-by: George Peter Banyard <girgias@php.net>
2020-05-08 10:52:23 +02:00
Nikita Popov
e41f764b5c Revert "Move declaration at top of the block"
This reverts commit b56f203850.

We use C99 now, this is not needed anymore.
2020-05-06 09:42:58 +02:00
Xinchen Hui
b56f203850 Move declaration at top of the block 2020-05-06 14:01:56 +08:00
Nikita Popov
5bc1e224db Make numeric operations on resources, arrays and objects type errors
RFC: https://wiki.php.net/rfc/arithmetic_operator_type_checks

Closes GH-5331.
2020-05-05 16:11:13 +02:00
Nikita Popov
8ffbd4653e Perform isupper check using sse2 as well
Rather than just vectorizing the lowering, also vectorize the
check for uppercase characters, using the same method.
2020-05-04 19:19:54 +02:00
Xinchen Hui
d2c6bf203a Folder mark 2020-04-28 13:47:04 +08:00
Xinchen Hui
11491b63f8 Also zend_str_tolower_dup_ex 2020-04-28 11:04:20 +08:00
Xinchen Hui
58005d7b42 Remove unnecessary register qualifier 2020-04-27 20:31:06 +08:00
Xinchen Hui
6a500cb249 SSE2 str_tolower 2020-04-27 16:35:06 +08:00
Nikita Popov
5430a466ff Avoid control flow warning 2020-04-02 10:54:32 +02:00
Nikita Popov
cdaf35033d Improve "unsupported operands" error
By mentioning the operand types. We can do that now, as the
original operand types now remain available.

Closes GH-5330.
2020-04-01 11:26:43 +02:00
Nikita Popov
9c0afc859c Remove op_func from TRY_BINARY_OP1 macro
And move the operator overloading helpers into zend_operators.c,
there's no reason for them to be in the header.
2020-04-01 10:15:03 +02:00
Nikita Popov
f182309e87 Refactor operator implementations
Instead of looping, use straight-line code with the following
layout:

1. Try to apply the base operation on the dereferenced operands.
2. Try overloaded object operations.
3. Try to convert operands to number, else error out.
4. Apply the base operation on the converted operands.

This makes the code easier to reason about and fixes some edge-case
bugs:

1. We should only try invoking operator overloading once prior to
   type conversion. Previously it was invoked both before and after
   type conversion.
2. We should not modify any values if an exception is thrown.
   Previously we sometimes modified the LHS of a compound assignment
   operator.
3. If conversion of the first operand fails, we no longer try to
   convert the second operand. I think the previous behavior here
   was fine as well, but this still seems a more typical.

This will also make some followup changes I have in mind simpler.
2020-03-31 20:49:39 +02:00
Nikita Popov
944b10e3d3 Remove unused argument form convert_object_to_type() 2020-03-31 17:31:35 +02:00
Nikita Popov
0509a1e066 Clean up silent/noisy flag in convert_to_number 2020-03-31 16:53:03 +02:00
Nikita Popov
8fd7f02ea4 Make cast_object handler required
Avoid subtle differences in behavior depending on whether the
handler is absent or returns FAILURE.

If you previously set cast_object to NULL, create a handler that
always returns FAILURE instead.
2020-03-31 14:37:49 +02:00
Nikita Popov
bef4b2e4e9 Report object cast failures internally
Make cast_object return FAILURE for casts to int/float, rather than
throwing a notice and returning SUCCESS. Instead move the emission
of the notice to the code invoking cast_object. This will allow us
to customize the behavior per call-site.

This change is written to be NFC, and the code in
zend_std_compare_objects() should illustrate the current behavior
doesn't make a lot of sense.
2020-03-31 12:07:25 +02:00
Nikita Popov
26327bcd3b Throw "Unsupported operand types" error when using ** on arrays 2019-10-29 13:05:02 +01:00