[PATCH 3/3] sensord: Avoid strcat

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Calling strcat twice in a row is inefficient, it's better to use
sprintf at the end of the string, so that we look for that end only
once.
---
 prog/sensord/sense.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

--- lm-sensors.orig/prog/sensord/sense.c	2012-03-03 19:07:43.000000000 +0100
+++ lm-sensors/prog/sensord/sense.c	2012-03-03 20:30:47.981351697 +0100
@@ -114,10 +114,8 @@ static int do_features(const sensors_chi
 		if (feature->rrd) {
 			const char *rrded = feature->rrd(val);
 
-			/* FIXME: Jean's review comment:
-			 * sprintf would me more efficient.
-			 */
-			strcat(strcat (rrdBuff, ":"), rrded ? rrded : "U");
+			sprintf(rrdBuff + strlen(rrdBuff), ":%s",
+				rrded ? rrded : "U");
 		}
 
 		return 0;

-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@xxxxxxxxxxxxxx
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors


[Index of Archives]     [Linux Kernel]     [Linux Hardware Monitoring]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux