Date: Sun, 15 May 2016 00:25:36 +0000 (UTC) From: Garrett Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299811 - head/usr.sbin/bsnmpd/tools/libbsnmptools Message-ID: <201605150025.u4F0Pa2A003779@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Sun May 15 00:25:36 2016 New Revision: 299811 URL: https://svnweb.freebsd.org/changeset/base/299811 Log: Use strdup instead of malloc + strlcpy Fix error messages on failure for calloc/strdup MFC after: 3 weeks Sponsored by: EMC / Isilon Storage Division Modified: head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c Modified: head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c ============================================================================== --- head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c Sun May 15 00:24:21 2016 (r299810) +++ head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c Sun May 15 00:25:36 2016 (r299811) @@ -763,17 +763,16 @@ snmp_import_object(struct snmp_toolinfo return (-1); if ((oid2str = calloc(1, sizeof(struct snmp_oid2str))) == NULL) { - syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); + syslog(LOG_ERR, "calloc() failed: %s", strerror(errno)); return (-1); } - if ((string = malloc(strlen(nexttok) + 1)) == NULL) { - syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); + if ((string = strdup(nexttok)) == NULL) { + syslog(LOG_ERR, "strdup() failed: %s", strerror(errno)); free(oid2str); return (-1); } - strlcpy(string, nexttok, nitems(string)); oid2str->string = string; oid2str->strlen = strlen(nexttok);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605150025.u4F0Pa2A003779>