You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Duplicated assignment in Modules/_randommodule.c #88205
Activity
bradlarsen commentedon May 4, 2021
In Modules/_randommodule.c:600,
longvalis 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(). */
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 }
rhettinger commentedon May 5, 2021
Just curious, how did you find this?
bradlarsen commentedon May 5, 2021
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.