From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752066AbcCHUmm (ORCPT ); Tue, 8 Mar 2016 15:42:42 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:36132 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751582AbcCHUlG (ORCPT ); Tue, 8 Mar 2016 15:41:06 -0500 From: Rasmus Villemoes To: Kees Cook , Andrew Morton , Richard Purdie , Jacek Anaszewski Cc: Rasmus Villemoes , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC 3/7] leds: avoid fragile sprintf use Date: Tue, 8 Mar 2016 21:40:50 +0100 Message-Id: <1457469654-17059-4-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1457469654-17059-1-git-send-email-linux@rasmusvillemoes.dk> References: <1457469654-17059-1-git-send-email-linux@rasmusvillemoes.dk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Passing overlapping src and dst buffers to sprintf is fragile (and undefined behaviour). So while this may seem like a clever way of appending a newline and obtaining the length of the resulting string at the same time, we might as well use that pbuf points to the current end of string and do the same thing with an assignment, increment and pointer subtraction. Signed-off-by: Rasmus Villemoes --- drivers/leds/led-class-flash.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/leds/led-class-flash.c b/drivers/leds/led-class-flash.c index cf398275a53c..4fae548a7822 100644 --- a/drivers/leds/led-class-flash.c +++ b/drivers/leds/led-class-flash.c @@ -212,7 +212,8 @@ static ssize_t flash_fault_show(struct device *dev, mask <<= 1; } - return sprintf(buf, "%s\n", buf); + *pbuf++ = '\n'; + return pbuf - buf; } static DEVICE_ATTR_RO(flash_fault); -- 2.1.4