[New-bugs-announce] [issue44049] Use C99 Variable-length array if possible

Dong-hee Na report at bugs.python.org
Wed May 5 08:10:58 EDT 2021

New submission from Dong-hee Na <donghee.na at python.org>:

I had a chance to read Python/suggestion.c and I can notice that we use the static declared size of the array.

Since we live in the C99 era and the CPython codebase already uses C99(struct initialization is a good example), how about using the C99 feature if possible.

We should care about stack overflow from the big input but with the expected very small input size it will be okay to use.

-    static size_t buffer[MAX_STRING_SIZE];
     // Both strings are the same (by identity)
     if (a == b) {
         return 0;
@@ -68,6 +66,8 @@ levenshtein_distance(const char *a, size_t a_size,
         size_t t_size = a_size; a_size = b_size; b_size = t_size;

+    size_t buffer[a_size];
     // quick fail when a match is impossible.
     if ((b_size - a_size) * MOVE_COST > max_cost) {
         return max_cost + 1

messages: 393006
nosy: corona10, pablogsal, vstinner
priority: normal
severity: normal
status: open
title: Use C99 Variable-length array if possible
type: enhancement
versions: Python 3.11

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list