From owner-svn-src-all@freebsd.org Sat Dec 31 11:13:01 2016 Return-Path: Delivered-To: svn-src-all@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 B8E9AC99494; Sat, 31 Dec 2016 11:13:01 +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 83DBB1B35; Sat, 31 Dec 2016 11:13:01 +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 uBVBD0EH045389; Sat, 31 Dec 2016 11:13:00 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBVBD0i9045388; Sat, 31 Dec 2016 11:13:00 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201612311113.uBVBD0i9045388@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Sat, 31 Dec 2016 11:13:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r310931 - head/contrib/bsnmp/lib X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Dec 2016 11:13:01 -0000 Author: ngie Date: Sat Dec 31 11:13:00 2016 New Revision: 310931 URL: https://svnweb.freebsd.org/changeset/base/310931 Log: Use strdup in snmp_parse_server(..) when possible instead of malloc+strcpy This simplifies the code and mutes a Coverity warning about sc->cport being improperly allocated Reported by: Coverity CID: 1018247 MFC after: 1 week Modified: head/contrib/bsnmp/lib/snmpclient.c Modified: head/contrib/bsnmp/lib/snmpclient.c ============================================================================== --- head/contrib/bsnmp/lib/snmpclient.c Sat Dec 31 11:12:26 2016 (r310930) +++ head/contrib/bsnmp/lib/snmpclient.c Sat Dec 31 11:13:00 2016 (r310931) @@ -1937,20 +1937,18 @@ snmp_parse_server(struct snmp_client *sc } /* port */ free(sc->cport); - if ((sc->cport = malloc(strlen(p + 1) + 1)) == NULL) { + if ((sc->cport = strdup(p + 1)) == NULL) { seterr(sc, "%s", strerror(errno)); return (-1); } - strcpy(sc->cport, p + 1); } else if (p > s) { /* host */ free(sc->chost); - if ((sc->chost = malloc(strlen(s) + 1)) == NULL) { + if ((sc->chost = strdup(strlen(s))) == NULL) { seterr(sc, "%s", strerror(errno)); return (-1); } - strcpy(sc->chost, s); } return (0); }