From 3872d23a513c6c951da84bb95dae967c4b6ad302 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Tue, 21 Mar 2023 15:38:19 +0200 Subject: [PATCH] examples/sort.c: fix out-of-bound memory access Issue described in https://github.com/drh/cii/issues/9 and also in book's errata. --- examples/sort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sort.c b/examples/sort.c index 8adfcd9..8636ac7 100644 --- a/examples/sort.c +++ b/examples/sort.c @@ -31,7 +31,7 @@ int partition(int a[], int i, int j) { k = i; v = a[k]; while (i < j) { - i++; while (a[i] < v && i < j) i++; + i++; while (i < j && a[i] < v) i++; j--; while (a[j] > v ) j--; if (i < j) { t = a[i]; a[i] = a[j]; a[j] = t; } }