diff options
author | 2015-06-21 03:20:56 +0000 | |
---|---|---|
committer | 2015-06-21 03:20:56 +0000 | |
commit | ada4c6055c06dd6d2032a67e98d64255b3cf6c6f (patch) | |
tree | ef161655ebb201990a0c338d1a642c13d7aff578 /lib/libc/stdlib/merge.c | |
parent | memory leak on failure; from Maxime Villard (diff) | |
download | wireguard-openbsd-ada4c6055c06dd6d2032a67e98d64255b3cf6c6f.tar.xz wireguard-openbsd-ada4c6055c06dd6d2032a67e98d64255b3cf6c6f.zip |
Just return if nmemb is 0. Avoids a NULL dereference and is
consistent with the behavior of the other libc sort functions.
OK deraadt@
Diffstat (limited to 'lib/libc/stdlib/merge.c')
-rw-r--r-- | lib/libc/stdlib/merge.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/libc/stdlib/merge.c b/lib/libc/stdlib/merge.c index 43ef8b08e26..d60317ce082 100644 --- a/lib/libc/stdlib/merge.c +++ b/lib/libc/stdlib/merge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: merge.c,v 1.9 2011/03/06 00:55:38 deraadt Exp $ */ +/* $OpenBSD: merge.c,v 1.10 2015/06/21 03:20:56 millert Exp $ */ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -101,6 +101,9 @@ mergesort(void *base, size_t nmemb, size_t size, return (-1); } + if (nmemb == 0) + return (0); + /* * XXX * Stupid subtraction for the Cray. |