From owner-svn-src-stable@freebsd.org Tue Mar 28 06:05:27 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8AA77D21D61; Tue, 28 Mar 2017 06:05:27 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 41C347E1; Tue, 28 Mar 2017 06:05:27 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2S65QGA006857; Tue, 28 Mar 2017 06:05:26 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2S65QWU006855; Tue, 28 Mar 2017 06:05:26 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201703280605.v2S65QWU006855@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Tue, 28 Mar 2017 06:05:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r316072 - stable/10/lib/libkvm X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Mar 2017 06:05:27 -0000 Author: ngie Date: Tue Mar 28 06:05:26 2017 New Revision: 316072 URL: https://svnweb.freebsd.org/changeset/base/316072 Log: MFC r315686,r315688: r315686: kvm_geterr: handle `kd` == NULL in a deterministic/graceful manner Return a NUL string instead of just working by accident with kvm_geterr(3) when MALLOC_PRODUCTION is disabled (I didn't confirm the MALLOC_PRODUCTION being enabled path). Document the new explicit return behavior for kvm_geterr(3), as well as the previous implicit behavior, i.e., the buffer attached to returned via kvm_geterr(3) would be empty if a previous error hadn't been stored in `kd`. r315688: kvm_write: fix -Wcast-qual warning in pointer arithmetic argument Cast buf to `const char *` when doing arithmetic operation to match `cp`'s type [1]. Modified: stable/10/lib/libkvm/kvm.c stable/10/lib/libkvm/kvm_geterr.3 Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libkvm/kvm.c ============================================================================== --- stable/10/lib/libkvm/kvm.c Tue Mar 28 06:03:43 2017 (r316071) +++ stable/10/lib/libkvm/kvm.c Tue Mar 28 06:05:26 2017 (r316072) @@ -76,9 +76,14 @@ static char sccsid[] = "@(#)kvm.c 8.2 (B /* from src/lib/libc/gen/nlist.c */ int __fdnlist(int, struct nlist *); +static char _kd_is_null[] = ""; + char * kvm_geterr(kvm_t *kd) { + + if (kd == NULL) + return (_kd_is_null); return (kd->errbuf); } @@ -623,5 +628,5 @@ kvm_write(kvm_t *kd, u_long kva, const v len -= cw; } - return (cp - (char *)buf); + return (cp - (const char *)buf); } Modified: stable/10/lib/libkvm/kvm_geterr.3 ============================================================================== --- stable/10/lib/libkvm/kvm_geterr.3 Tue Mar 28 06:03:43 2017 (r316071) +++ stable/10/lib/libkvm/kvm_geterr.3 Tue Mar 28 06:05:26 2017 (r316072) @@ -32,7 +32,7 @@ .\" @(#)kvm_geterr.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd March 21, 2017 .Dt KVM_GETERR 3 .Os .Sh NAME @@ -54,6 +54,15 @@ library call did not produce an error. The string returned is stored in memory owned by .Xr kvm 3 so the message should be copied out and saved elsewhere if necessary. +.Sh RETURN VALUES +The function +.Fn kvm_geterr +will return "" if +.Fa kd +is +.Dv NULL +or an error has not been captured for +.Fa kd . .Sh SEE ALSO .Xr kvm 3 , .Xr kvm_close 3 ,