From owner-svn-src-head@freebsd.org Fri Jun 23 13:26:14 2017 Return-Path: Delivered-To: svn-src-head@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 EAA6BDA49A4; Fri, 23 Jun 2017 13:26:14 +0000 (UTC) (envelope-from bapt@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 C6A96651; Fri, 23 Jun 2017 13:26:14 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v5NDQDnQ037070; Fri, 23 Jun 2017 13:26:13 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v5NDQDmg037068; Fri, 23 Jun 2017 13:26:13 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201706231326.v5NDQDmg037068@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Fri, 23 Jun 2017 13:26:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r320267 - head/usr.sbin/sesutil X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jun 2017 13:26:15 -0000 Author: bapt Date: Fri Jun 23 13:26:13 2017 New Revision: 320267 URL: https://svnweb.freebsd.org/changeset/base/320267 Log: Do not use sprintf(3) when not needed, while here, prefer snprintf(3) over sprintf(3) Modified: head/usr.sbin/sesutil/eltsub.c head/usr.sbin/sesutil/eltsub.h Modified: head/usr.sbin/sesutil/eltsub.c ============================================================================== --- head/usr.sbin/sesutil/eltsub.c Fri Jun 23 11:55:43 2017 (r320266) +++ head/usr.sbin/sesutil/eltsub.c Fri Jun 23 13:26:13 2017 (r320267) @@ -51,134 +51,97 @@ */ #define TEMPERATURE_OFFSET 20 -char * +const char * geteltnm(int type) { static char rbuf[132]; switch (type) { case ELMTYP_UNSPECIFIED: - sprintf(rbuf, "Unspecified"); - break; + return ("Unspecified"); case ELMTYP_DEVICE: - sprintf(rbuf, "Device Slot"); - break; + return ("Device Slot"); case ELMTYP_POWER: - sprintf(rbuf, "Power Supply"); - break; + return ("Power Supply"); case ELMTYP_FAN: - sprintf(rbuf, "Cooling"); - break; + return ("Cooling"); case ELMTYP_THERM: - sprintf(rbuf, "Temperature Sensors"); - break; + return ("Temperature Sensors"); case ELMTYP_DOORLOCK: - sprintf(rbuf, "Door Lock"); - break; + return ("Door Lock"); case ELMTYP_ALARM: - sprintf(rbuf, "Audible alarm"); - break; + return ("Audible alarm"); case ELMTYP_ESCC: - sprintf(rbuf, "Enclosure Services Controller Electronics"); - break; + return ("Enclosure Services Controller Electronics"); case ELMTYP_SCC: - sprintf(rbuf, "SCC Controller Electronics"); - break; + return ("SCC Controller Electronics"); case ELMTYP_NVRAM: - sprintf(rbuf, "Nonvolatile Cache"); - break; + return ("Nonvolatile Cache"); case ELMTYP_INV_OP_REASON: - sprintf(rbuf, "Invalid Operation Reason"); - break; + return ("Invalid Operation Reason"); case ELMTYP_UPS: - sprintf(rbuf, "Uninterruptible Power Supply"); - break; + return ("Uninterruptible Power Supply"); case ELMTYP_DISPLAY: - sprintf(rbuf, "Display"); - break; + return ("Display"); case ELMTYP_KEYPAD: - sprintf(rbuf, "Key Pad Entry"); - break; + return ("Key Pad Entry"); case ELMTYP_ENCLOSURE: - sprintf(rbuf, "Enclosure"); - break; + return ("Enclosure"); case ELMTYP_SCSIXVR: - sprintf(rbuf, "SCSI Port/Transceiver"); - break; + return ("SCSI Port/Transceiver"); case ELMTYP_LANGUAGE: - sprintf(rbuf, "Language"); - break; + return ("Language"); case ELMTYP_COMPORT: - sprintf(rbuf, "Communication Port"); - break; + return ("Communication Port"); case ELMTYP_VOM: - sprintf(rbuf, "Voltage Sensor"); - break; + return ("Voltage Sensor"); case ELMTYP_AMMETER: - sprintf(rbuf, "Current Sensor"); - break; + return ("Current Sensor"); case ELMTYP_SCSI_TGT: - sprintf(rbuf, "SCSI Target Port"); - break; + return ("SCSI Target Port"); case ELMTYP_SCSI_INI: - sprintf(rbuf, "SCSI Initiator Port"); - break; + return ("SCSI Initiator Port"); case ELMTYP_SUBENC: - sprintf(rbuf, "Simple Subenclosure"); - break; + return ("Simple Subenclosure"); case ELMTYP_ARRAY_DEV: - sprintf(rbuf, "Array Device Slot"); - break; + return ("Array Device Slot"); case ELMTYP_SAS_EXP: - sprintf(rbuf, "SAS Expander"); - break; + return ("SAS Expander"); case ELMTYP_SAS_CONN: - sprintf(rbuf, "SAS Connector"); - break; + return ("SAS Connector"); default: - (void) sprintf(rbuf, "", type); - break; + snprintf(rbuf, sizeof(rbuf), "", type); + return (rbuf); } - return (rbuf); } -char * +const char * scode2ascii(u_char code) { static char rbuf[32]; switch (code & 0xf) { case SES_OBJSTAT_UNSUPPORTED: - sprintf(rbuf, "Unsupported"); - break; + return ("Unsupported"); case SES_OBJSTAT_OK: - sprintf(rbuf, "OK"); - break; + return ("OK"); case SES_OBJSTAT_CRIT: - sprintf(rbuf, "Critical"); - break; + return ("Critical"); case SES_OBJSTAT_NONCRIT: - sprintf(rbuf, "Noncritical"); - break; + return ("Noncritical"); case SES_OBJSTAT_UNRECOV: - sprintf(rbuf, "Unrecoverable"); - break; + return ("Unrecoverable"); case SES_OBJSTAT_NOTINSTALLED: - sprintf(rbuf, "Not Installed"); - break; + return ("Not Installed"); case SES_OBJSTAT_UNKNOWN: - sprintf(rbuf, "Unknown"); - break; + return ("Unknown"); case SES_OBJSTAT_NOTAVAIL: - sprintf(rbuf, "Not Available"); - break; + return ("Not Available"); case SES_OBJSTAT_NOACCESS: - sprintf(rbuf, "No Access Allowed"); - break; + return ("No Access Allowed"); default: - sprintf(rbuf, "", code & 0xf); - break; + snprintf(rbuf, sizeof(rbuf), "", code & 0xf); + return (rbuf); } - return (rbuf); } struct sbuf * Modified: head/usr.sbin/sesutil/eltsub.h ============================================================================== --- head/usr.sbin/sesutil/eltsub.h Fri Jun 23 11:55:43 2017 (r320266) +++ head/usr.sbin/sesutil/eltsub.h Fri Jun 23 13:26:13 2017 (r320267) @@ -32,6 +32,6 @@ * mjacob@feral.com */ -char *geteltnm(int); -char *scode2ascii(u_char); +const char *geteltnm(int); +const char *scode2ascii(u_char); struct sbuf *stat2sbuf(int, u_char *);