diff options
-rw-r--r-- | src/lib/libc/stdlib/qsort.3 | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/qsort.3 b/src/lib/libc/stdlib/qsort.3 index cadfda7961..cbb1ec44d4 100644 --- a/src/lib/libc/stdlib/qsort.3 +++ b/src/lib/libc/stdlib/qsort.3 | |||
@@ -29,7 +29,7 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
31 | .\" | 31 | .\" |
32 | .\" $OpenBSD: qsort.3,v 1.21 2019/01/21 20:34:14 otto Exp $ | 32 | .\" $OpenBSD: qsort.3,v 1.22 2019/01/21 20:43:27 tedu Exp $ |
33 | .\" | 33 | .\" |
34 | .Dd $Mdocdate: January 21 2019 $ | 34 | .Dd $Mdocdate: January 21 2019 $ |
35 | .Dt QSORT 3 | 35 | .Dt QSORT 3 |
@@ -180,12 +180,16 @@ char *array[] = { "XX", "YYY", "Z" }; | |||
180 | int | 180 | int |
181 | cmp(const void *a, const void *b) | 181 | cmp(const void *a, const void *b) |
182 | { | 182 | { |
183 | /* a and b point to an element of the array */ | 183 | /* |
184 | * a and b point to elements of the array. | ||
185 | * Cast and dereference to obtain the actual elements, | ||
186 | * which are also pointers in this case. | ||
187 | */ | ||
184 | size_t lena = strlen(*(const char **)a); | 188 | size_t lena = strlen(*(const char **)a); |
185 | size_t lenb = strlen(*(const char **)b); | 189 | size_t lenb = strlen(*(const char **)b); |
186 | /* | 190 | /* |
187 | * Do not subtract the lengths, an int cannot represent the range of | 191 | * Do not subtract the lengths. The difference between values cannot |
188 | * values the difference can take. | 192 | * be represented by an int. |
189 | */ | 193 | */ |
190 | return lena < lenb ? -1 : lena > lenb; | 194 | return lena < lenb ? -1 : lena > lenb; |
191 | } | 195 | } |
@@ -193,7 +197,7 @@ cmp(const void *a, const void *b) | |||
193 | int | 197 | int |
194 | main() | 198 | main() |
195 | { | 199 | { |
196 | int i; | 200 | size_t i; |
197 | 201 | ||
198 | qsort(array, N, sizeof(array[0]), cmp); | 202 | qsort(array, N, sizeof(array[0]), cmp); |
199 | for (i = 0; i < N; i++) | 203 | for (i = 0; i < N; i++) |