Skip to content

Duplicated assignment in Modules/_randommodule.c #88205

Closed

Description

@bradlarsen
mannequin
BPO 44039
Nosy @rhettinger, @tiran, @bradlarsen, @miss-islington
PRs
  • bpo-44039: Eliminate duplicated assignment in _randommodule.c #25904
  • [3.10] bpo-44039: Eliminate duplicated assignment in _randommodule.c (GH-25904) #25909
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2021-05-05.04:39:49.359>
    created_at = <Date 2021-05-04.20:46:01.256>
    labels = ['extension-modules', '3.10', '3.11']
    title = 'Duplicated assignment in Modules/_randommodule.c'
    updated_at = <Date 2021-05-05.15:02:09.677>
    user = 'https://github.com/bradlarsen'

    bugs.python.org fields:

    activity = <Date 2021-05-05.15:02:09.677>
    actor = 'blarsen'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2021-05-05.04:39:49.359>
    closer = 'rhettinger'
    components = ['Extension Modules']
    creation = <Date 2021-05-04.20:46:01.256>
    creator = 'blarsen'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44039
    keywords = ['patch']
    message_count = 3.0
    messages = ['392949', '392972', '393014']
    nosy_count = 4.0
    nosy_names = ['rhettinger', 'christian.heimes', 'blarsen', 'miss-islington']
    pr_nums = ['25904', '25909']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44039'
    versions = ['Python 3.10', 'Python 3.11']

    Activity

    1. bradlarsen commented on May 4, 2021

      bradlarsenmannequin
      MannequinAuthor

      In Modules/_randommodule.c:600, longval is used in its own initialization. This seems to be a typo introduced in commit cc0cd43 for bpo-1635741.

      585 static int
      586 _random_exec(PyObject *module)
      587 {
      588 _randomstate *state = get_random_state(module);
      589
      590 state->Random_Type = PyType_FromModuleAndSpec(
      591 module, &Random_Type_spec, NULL);
      592 if (state->Random_Type == NULL) {
      593 return -1;
      594 }
      595 if (PyModule_AddType(module, (PyTypeObject *)state->Random_Type) < 0) {
      596 return -1;
      597 }
      598
      599 /* Look up and save int.__abs__, which is needed in random_seed(). */

      • 600 PyObject *longval = longval = PyLong_FromLong(0);
        601 if (longval == NULL) {
        602 return -1;
        603 }
        604
        605 PyObject *longtype = PyObject_Type(longval);
        606 Py_DECREF(longval);
        607 if (longtype == NULL) {
        608 return -1;
        609 }
        610
        611 state->Long___abs__ = PyObject_GetAttrString(longtype, "__abs__");
        612 Py_DECREF(longtype);
        613 if (state->Long___abs__ == NULL) {
        614 return -1;
        615 }
        616 return 0;
        617 }
    2. rhettinger commented on May 5, 2021

      @rhettinger
      Contributor

      Just curious, how did you find this?

    3. bradlarsen commented on May 5, 2021

      bradlarsenmannequin
      MannequinAuthor

      Just curious, how did you find this?

      I am working on some new CodeQL queries (https://securitylab.github.com/tools/codeql/) and saw a warning about this self-assignment from one of the existing queries.

      LGTM apparently regularly scans cpython: https://lgtm.com/projects/g/python/cpython

      Thanks for the quick review.

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions