Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdlib PR lib/50316: Gracefully handle a zero numbe...



details:   https://anonhg.NetBSD.org/src/rev/b4b8a0eb25d1
branches:  trunk
changeset: 826035:b4b8a0eb25d1
user:      ginsbach <ginsbach%NetBSD.org@localhost>
date:      Sat Aug 12 01:10:04 2017 +0000

description:
PR lib/50316: Gracefully handle a zero number of members argument.

Taken from FreeBSD (which fixed this same issue long ago).

XXX: pullup-8
XXX: pullup-7
XXX: pullup-6

diffstat:

 lib/libc/stdlib/merge.c |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (28 lines):

diff -r 850c5980ffc1 -r b4b8a0eb25d1 lib/libc/stdlib/merge.c
--- a/lib/libc/stdlib/merge.c   Sat Aug 12 00:43:25 2017 +0000
+++ b/lib/libc/stdlib/merge.c   Sat Aug 12 01:10:04 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: merge.c,v 1.14 2012/03/13 21:13:48 christos Exp $      */
+/*     $NetBSD: merge.c,v 1.15 2017/08/12 01:10:04 ginsbach Exp $      */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "from: @(#)merge.c      8.2 (Berkeley) 2/14/94";
 #else
-__RCSID("$NetBSD: merge.c,v 1.14 2012/03/13 21:13:48 christos Exp $");
+__RCSID("$NetBSD: merge.c,v 1.15 2017/08/12 01:10:04 ginsbach Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -125,6 +125,9 @@
                return (-1);
        }
 
+       if (nmemb == 0)
+               return (0);
+
        /*
         * XXX
         * Stupid subtraction for the Cray.



Home | Main Index | Thread Index | Old Index