GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Incorrect warning when assign an unsigned integer member · Issue #114388 · python/cpython

Incorrect warning when assign an unsigned integer member #114388

New issue
Copy link
New issue
Copy link
Closed
Closed
Incorrect warning when assign an unsigned integer member#114388
Copy link
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)

Description

@serhiy-storchaka
serhiy-storchaka
opened on Jan 21, 2024
Issue body actions

Assigning a negative value to an unsigned integer member can emit a RuntimeWarning.

$ ./python -Wa
>>> import _testcapi
>>> ts = _testcapi._test_structmembersType_NewAPI()
>>> ts.T_UBYTE = -42
<stdin>:1: RuntimeWarning: Truncation of value to unsigned char
>>> ts.T_USHORT = -42
<stdin>:1: RuntimeWarning: Truncation of value to unsigned short
>>> ts.T_UINT = -42
<stdin>:1: RuntimeWarning: Writing negative value into unsigned field
<stdin>:1: RuntimeWarning: Truncation of value to unsigned int
>>> ts.T_ULONG = -42
<stdin>:1: RuntimeWarning: Writing negative value into unsigned field

(And for T_ULONGLONG it raises an OverflowError, but this is perhaps another issue).

The first issue is that it emits two warnings for T_UINT. It is also weird that warnings are different.

The second issue is that if the value is not an int subclass, it emits a warning also for positive values for T_UINT and T_ULONG:

>>> class Index:
...     def __init__(self, value):
...         self.value = value
...     def __index__(self):
...         return self.value
... 
>>> ts.T_UBYTE = Index(42)
>>> ts.T_USHORT = Index(42)
>>> ts.T_UINT = Index(42)
<stdin>:1: RuntimeWarning: Writing negative value into unsigned field
>>> ts.T_ULONG = Index(42)
<stdin>:1: RuntimeWarning: Writing negative value into unsigned field

(No warning is emitted for assigning a negative index to T_ULONGLONG, but this is perhaps another issue).

Linked PRs

  • gh-114388: Fix warnings when assign an unsigned integer member #114391
  • gh-114388: Fix an error in GH-114391 #115000
  • [3.12] gh-114388: Fix warnings when assign an unsigned integer member (GH-114391) #115001
  • [3.11] gh-114388: Fix warnings when assign an unsigned integer member (GH-114391) #115002

Activity

  1. serhiy-storchaka
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    3.11only security fixesonly security fixes
    3.12only security fixesonly security fixes
    3.13only security fixesonly security fixes
    on Jan 21, 2024
  2. serhiy-storchaka
    added a commit that references this issue on Jan 21, 2024

    pythongh-114388: Fix warnings when assign an unsigned integer member

    0763094
  3. serhiy-storchaka
    added 6 commits that reference this issue on Feb 4, 2024

    gh-114388: Fix warnings when assign an unsigned integer member (GH-11…

    3ddc515

    pythongh-114388: Fix an error in pythonGH-114391

    4e3c377

    [3.12] pythongh-114388: Fix warnings when assign an unsigned integer …

    f806bed

    [3.11] pythongh-114388: Fix warnings when assign an unsigned integer …

    3d6b8d4

    gh-114388: Fix an error in GH-114391 (GH-115000)

    d466052

    [3.12] gh-114388: Fix warnings when assign an unsigned integer member (…

    b9937a6
  4. serhiy-storchaka
    closed this as completedon Feb 4, 2024
  5. serhiy-storchaka
    added a commit that references this issue on Feb 4, 2024

    [3.11] gh-114388: Fix warnings when assign an unsigned integer member (…

    0244e96
  6. aisk
    added 2 commits that reference this issue on Feb 11, 2024

    pythongh-114388: Fix warnings when assign an unsigned integer member (p…

    2ce4d9a

    pythongh-114388: Fix an error in pythonGH-114391 (pythonGH-115000)

    c7fcf23
  7. fsc-eriker
    added 2 commits that reference this issue on Feb 14, 2024

    pythongh-114388: Fix warnings when assign an unsigned integer member (p…

    c9527df

    pythongh-114388: Fix an error in pythonGH-114391 (pythonGH-115000)

    736a53a
  8. encukou commented on Mar 28, 2024

    @encukou
    encukou
    on Mar 28, 2024
    Member
    More actions

    With this change, there's a new warning emitted for “Writing negative value into unsigned field”.
    @zooba, you might be interested in this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.