mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
bpo-38530: Cover more error paths in error suggestion functions (GH-25462)
This commit is contained in:
parent
8bf274a500
commit
0b1c169c4a
2 changed files with 15 additions and 2 deletions
|
@ -8,7 +8,7 @@
|
|||
#define MAX_STRING_SIZE 25
|
||||
|
||||
/* Calculate the Levenshtein distance between string1 and string2 */
|
||||
static size_t
|
||||
static Py_ssize_t
|
||||
levenshtein_distance(const char *a, size_t a_size,
|
||||
const char *b, size_t b_size) {
|
||||
|
||||
|
@ -33,7 +33,7 @@ levenshtein_distance(const char *a, size_t a_size,
|
|||
|
||||
size_t *buffer = PyMem_Calloc(a_size, sizeof(size_t));
|
||||
if (buffer == NULL) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initialize the buffer row
|
||||
|
@ -99,6 +99,9 @@ calculate_suggestions(PyObject *dir,
|
|||
}
|
||||
Py_ssize_t current_distance = levenshtein_distance(
|
||||
name_str, name_size, item_str, item_size);
|
||||
if (current_distance == -1) {
|
||||
return NULL;
|
||||
}
|
||||
if (current_distance == 0 || current_distance > MAX_DISTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue