Skip to content

Unreachable (useless) code in bytesio.c:resize_buffer() #117068

@ghost

Description

Bug report

Bug description:

https://github.com/NGRsoftlab/cpython/blob/main/Modules/_io/bytesio.c#L158

size_t alloc = PyBytes_GET_SIZE(self->buf);

/* skipped for short */

if (alloc > ((size_t)-1) / sizeof(char))
        goto overflow;

This code is useless and goto is unreachable, because of false condition:

  1. 'alloc' has a type 'size_t' with minimum value '0' and a maximum value of size_t ('18446744073709551615' on x86_64)
  2. ((size_t)-1) is a maximum value of size_t ('18446744073709551615' on x86_64)
  3. size_t is built-in type for C
  4. sizeof(char) is always 1 in C

Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions