Skip to content

range(9.9, '0') causes segmentation fault #13094

Closed

Description

@KidFlo

Description

Hi,

The following code:

<?php
var_dump(range(9.9, '0'));

Resulted in a SEGFAULT.

But I expected (something like) this output instead:

array(10) {
  [0]=>
  float(9.9)
  [1]=>
  float(8.9)
  [2]=>
  float(7.9)
  [3]=>
  float(6.9)
  [4]=>
  float(5.9)
  [5]=>
  float(4.9)
  [6]=>
  float(3.9000000000000004)
  [7]=>
  float(2.9000000000000004)
  [8]=>
  float(1.9000000000000004)
  [9]=>
  float(0.9000000000000004)
}

This might not be specific to Windows, since I was also able to reproduce it here : https://3v4l.org/qc6TF.
Anyway if you need me to dump more information, just ask (I may not respond immediately).

PHP Version

PHP 8.3.1

Operating System

Windows 11

Activity

  1. iluuu1994 commented on Jan 8, 2024

    @iluuu1994
    Member

    Likely caused by the changes from #10826, so assigning to @Girgias.

  2. ndossche commented on Jan 8, 2024

    @ndossche
    Member

    Huh I had already started debugging this,
    anyway the root cause is if (UNEXPECTED(start_type + end_type < 2*IS_STRING)) {
    Comment says /* If one of the inputs is NOT a string */ but that's not true as in the example start_type is 5 and end_type is 7, which is 12, and 2*IS_STRING is also 12.
    I'd just change it to if (UNEXPECTED(start_type != IS_STRING || end_type != IS_STRING)) { which is clearer and unlikely to be slower in practice. But deferring to Gina.

  3. iluuu1994 commented on Jan 8, 2024

    @iluuu1994
    Member

    @nielsdos No worries, I doubt Gina will be mad ^^ In any case, it's good she's informed.

  4. Girgias commented on Jan 8, 2024

    @Girgias
    Member

    Erg I was trying to be smart and failed.

    Can you PR the change @nielsdos so that you get proper credit?

  5. added a commit that references this issue on Jan 9, 2024
    4216932
  6. added a commit that references this issue on Jan 9, 2024
    5e34bb8
  7. added a commit that references this issue on Jan 25, 2024
    1d6f344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions