From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Howells Subject: Re: [PATCH v2] arch: s390: appldata: using strncpy() and strnlen() instead of sprintf() Date: Tue, 28 May 2013 11:22:33 +0100 Message-ID: <4310.1369736553@warthog.procyon.org.uk> References: <51A32D81.2010105@asianux.com> <51A2CC07.5010100@asianux.com> Return-path: In-Reply-To: <51A32D81.2010105@asianux.com> Sender: linux-arch-owner@vger.kernel.org List-Archive: List-Post: To: Chen Gang Cc: dhowells@redhat.com, Geert Uytterhoeven , Martin Schwidefsky , Heiko Carstens , jang@linux.vnet.ibm.com, linux390@de.ibm.com, linux-s390@vger.kernel.org, Linux-Arch , "kernel-janitors@vger.kernel.org" List-ID: Chen Gang wrote: > - len = sprintf(buf, appldata_timer_active ? "1\n" : "0\n"); > + strncpy(buf, appldata_timer_active ? "1\n" : "0\n", > + ARRAY_SIZE(buf)); > + len = strnlen(buf, ARRAY_SIZE(buf)); Since the strings here are a fixed, preknown size, you should use memcpy (or just fill in the array directly which would likely take fewer instructions since the strings are so short and vary by one character) and hard-code the length or use sizeof() instead of strnlen(). David