Skip to content

Commit e703122

Browse files
committed
[Backport of rev. 42093 by neal.norwitz]
Check return result from Py_InitModule*(). This API can fail. Probably should be backported.
1 parent 4c16bac commit e703122

75 files changed

Lines changed: 149 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Misc/NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Core and builtins
1515
- Overflow checking code in integer division ran afoul of new gcc
1616
optimizations. Changed to be more standard-conforming.
1717

18+
- Fix warnings reported by Klocwork's static analysis tool.
19+
1820
- Patch #1541585: fix buffer overrun when performing repr() on
1921
a unicode string in a build with wide unicode (UCS-4) support.
2022

‎Modules/_bsddb.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4846,6 +4846,8 @@ DL_EXPORT(void) init_bsddb(void)
48464846

48474847
/* Create the module and add the functions */
48484848
m = Py_InitModule(_bsddbModuleName, bsddb_methods);
4849+
if (m == NULL)
4850+
return;
48494851

48504852
/* Add some symbolic constants to the module */
48514853
d = PyModule_GetDict(m);

‎Modules/_curses_panel.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ init_curses_panel(void)
464464

465465
/* Create the module and add the functions */
466466
m = Py_InitModule("_curses_panel", PyCurses_methods);
467+
if (m == NULL)
468+
return;
467469
d = PyModule_GetDict(m);
468470

469471
/* For exception _curses_panel.error */

‎Modules/_cursesmodule.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,6 +2488,8 @@ init_curses(void)
24882488

24892489
/* Create the module and add the functions */
24902490
m = Py_InitModule("_curses", PyCurses_methods);
2491+
if (m == NULL)
2492+
return;
24912493

24922494
/* Add some symbolic constants to the module */
24932495
d = PyModule_GetDict(m);

‎Modules/_heapqmodule.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ init_heapq(void)
610610
PyObject *m;
611611

612612
m = Py_InitModule3("_heapq", heapq_methods, module_doc);
613+
if (m == NULL)
614+
return;
613615
PyModule_AddObject(m, "__about__", PyString_FromString(__about__));
614616
}
615617

‎Modules/_localemodule.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ init_locale(void)
715715
#endif
716716

717717
m = Py_InitModule("_locale", PyLocale_Methods);
718+
if (m == NULL)
719+
return;
718720

719721
d = PyModule_GetDict(m);
720722

‎Modules/_randommodule.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ init_random(void)
573573
if (PyType_Ready(&Random_Type) < 0)
574574
return;
575575
m = Py_InitModule3("_random", NULL, module_doc);
576+
if (m == NULL)
577+
return;
576578
Py_INCREF(&Random_Type);
577579
PyModule_AddObject(m, "Random", (PyObject *)&Random_Type);
578580
}

‎Modules/_sre.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3389,6 +3389,8 @@ PyMODINIT_FUNC init_sre(void)
33893389
Scanner_Type.ob_type = &PyType_Type;
33903390

33913391
m = Py_InitModule("_" SRE_MODULE, _functions);
3392+
if (m == NULL)
3393+
return;
33923394
d = PyModule_GetDict(m);
33933395

33943396
x = PyInt_FromLong(SRE_MAGIC);

‎Modules/_ssl.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ init_ssl(void)
657657
PySSL_Type.ob_type = &PyType_Type;
658658

659659
m = Py_InitModule3("_ssl", PySSL_methods, module_doc);
660+
if (m == NULL)
661+
return;
660662
d = PyModule_GetDict(m);
661663

662664
/* Load _socket module and its C API */

‎Modules/_testcapimodule.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,8 @@ init_testcapi(void)
856856
Copyable_Type.ob_type = &PyType_Type;
857857

858858
m = Py_InitModule("_testcapi", TestMethods);
859+
if (m == NULL)
860+
return;
859861

860862
PyModule_AddObject(m, "UCHAR_MAX", PyInt_FromLong(UCHAR_MAX));
861863
PyModule_AddObject(m, "USHRT_MAX", PyInt_FromLong(USHRT_MAX));

0 commit comments

Comments
 (0)