diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2021-04-17 22:28:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-17 22:28:45 (GMT) |
commit | 0b1c169c4a009e1094fe5df938d2367e63ebeea0 (patch) | |
tree | c76957f0ecef70034069d510eec79bcdd85d18f1 /Python | |
parent | 8bf274a5002c013dd4086f6390fa19452b63ac1d (diff) | |
download | cpython-0b1c169c4a009e1094fe5df938d2367e63ebeea0.zip cpython-0b1c169c4a009e1094fe5df938d2367e63ebeea0.tar.gz cpython-0b1c169c4a009e1094fe5df938d2367e63ebeea0.tar.bz2 |
bpo-38530: Cover more error paths in error suggestion functions (GH-25462)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/suggestions.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Python/suggestions.c b/Python/suggestions.c index aa4870d..d4e9dc2 100644 --- a/Python/suggestions.c +++ b/Python/suggestions.c @@ -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; } |