Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Oct 2009 18:31:54 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r198340 - head/sbin/sysctl
Message-ID:  <200910211831.n9LIVsHx007055@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Wed Oct 21 18:31:54 2009
New Revision: 198340
URL: http://svn.freebsd.org/changeset/base/198340

Log:
  Make input parsing in Farhenheit actually work.
  
  Don't clobber *p with '\0' when testing whether it has the value of 'F'.
  Just use the semantics of strtof() properly. If it returns p, we know
  that it parsed the string until it reached 'C' or 'F'.
  
  The code has not changed since it has been imported (r161951, Sep 3,
  2006).
  
  Submitted by:	Alexandre Perrin <kaworu@kaworu.ch>
  MFC after:	1 week

Modified:
  head/sbin/sysctl/sysctl.c

Modified: head/sbin/sysctl/sysctl.c
==============================================================================
--- head/sbin/sysctl/sysctl.c	Wed Oct 21 18:29:26 2009	(r198339)
+++ head/sbin/sysctl/sysctl.c	Wed Oct 21 18:31:54 2009	(r198340)
@@ -68,7 +68,7 @@ static int	sysctl_all(int *oid, int len)
 static int	name2oid(char *, int *);
 
 static void	set_T_dev_t(char *, void **, size_t *);
-static int	set_IK(char *, int *);
+static int	set_IK(const char *, int *);
 
 static void
 usage(void)
@@ -452,19 +452,19 @@ set_T_dev_t(char *path, void **val, size
 }
 
 static int
-set_IK(char *str, int *val)
+set_IK(const char *str, int *val)
 {
 	float temp;
 	int len, kelv;
-	char *p, *endptr;
+	const char *p;
+	char *endptr;
 
 	if ((len = strlen(str)) == 0)
 		return (0);
 	p = &str[len - 1];
 	if (*p == 'C' || *p == 'F') {
-		*p = '\0';
 		temp = strtof(str, &endptr);
-		if (endptr == str || *endptr != '\0')
+		if (endptr == str || endptr != p)
 			return (0);
 		if (*p == 'F')
 			temp = (temp - 32) * 5 / 9;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200910211831.n9LIVsHx007055>