https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114293

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:39737cdf002637c7a652e9c3e36f369cfce581e5

commit r14-9437-g39737cdf002637c7a652e9c3e36f369cfce581e5
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Mar 12 10:23:19 2024 +0100

    strlen: Fix another spot that can create invalid ranges [PR114293]

    This PR is similar to PR110603 fixed with r14-8487, except in a different
    spot.  From the memset with -1 size of non-zero value we determine minimum
    of (size_t) -1 and the code uses PTRDIFF_MAX - 2 (not really sure I
    understand why it is - 2 and not - 1, e.g. heap allocated array
    with PTRDIFF_MAX char elements which contain '\0' in the last element
    should be fine, no?  One can still represent arr[PTRDIFF_MAX] - arr[0]
    and arr[0] - arr[PTRDIFF_MAX] in ptrdiff_t and
    strlen (arr) == PTRDIFF_MAX - 1) as the maximum, so again invalid range.
    As in the other case, it is just UB that can lead to that, and we have
    choice to only keep the min and use +inf for max, or only keep max
    and use 0 for min, or not set the range at all, or use [min, min] or
    [max, max] etc.  The following patch uses [min, +inf].

    2024-03-12  Jakub Jelinek  <ja...@redhat.com>

            PR tree-optimization/114293
            * tree-ssa-strlen.cc (strlen_pass::handle_builtin_strlen): If
            max is smaller than min, set max to ~(size_t)0.

            * gcc.dg/pr114293.c: New test.

Reply via email to