Date: Sat, 31 Dec 2016 11:13:00 +0000 (UTC) From: Ngie Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r310931 - head/contrib/bsnmp/lib Message-ID: <201612311113.uBVBD0i9045388@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201612311113.uBVBD0i9045388>