➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Duplicated assignment in Modules/_randommodule.c
Type: Stage: resolved
Components: Extension Modules Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: blarsen, christian.heimes, miss-islington, rhettinger
Priority: normal Keywords: patch

Created on 2021-05-04 20:46 by blarsen, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25904 merged blarsen, 2021-05-04 20:48
PR 25909 merged miss-islington, 2021-05-05 05:56
Messages (3)
msg392949 - (view) Author: Brad Larsen (blarsen) * Date: 2021-05-04 20:46
In Modules/_randommodule.c:600, `longval` is used in its own initialization.  This seems to be a typo introduced in commit cc0cd43c0f9 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 }
msg392972 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-05-05 03:43
Just curious, how did you find this?
msg393014 - (view) Author: Brad Larsen (blarsen) * Date: 2021-05-05 15:02
> 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.
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88205
2021-05-05 15:02:09blarsensetmessages: + msg393014
2021-05-05 05:56:32miss-islingtonsetnosy: + miss-islington

pull_requests: + pull_request24578
2021-05-05 04:39:49rhettingersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-05-05 03:43:27rhettingersetmessages: + msg392972
2021-05-05 03:40:07rhettingersetassignee: rhettinger

nosy: + rhettinger
2021-05-04 20:48:13blarsensetkeywords: + patch
stage: patch review
pull_requests: + pull_request24572
2021-05-04 20:46:01blarsencreate