Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S272647AbTHPIlh (ORCPT ); Sat, 16 Aug 2003 04:41:37 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S272653AbTHPIlh (ORCPT ); Sat, 16 Aug 2003 04:41:37 -0400 Received: from mail.lmcg.wisc.edu ([144.92.101.145]:56518 "EHLO mail.lmcg.wisc.edu") by vger.kernel.org with ESMTP id S272647AbTHPIlf (ORCPT ); Sat, 16 Aug 2003 04:41:35 -0400 Date: Sat, 16 Aug 2003 03:41:29 -0500 From: Daniel Forrest To: Peter Kjellerstedt Cc: "'Timothy Miller'" , "'Willy Tarreau'" , linux-kernel mailing list Subject: Re: generic strncpy - off-by-one error Message-ID: <20030816034129.A6301@rda07.lmcg.wisc.edu> Reply-To: Daniel Forrest References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from peter.kjellerstedt@axis.com on Sat, Aug 16, 2003 at 10:15:14AM +0200 Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 927 Lines: 49 On Sat, Aug 16, 2003 at 10:15:14AM +0200, Peter Kjellerstedt wrote: > > Here is the code that I used: > > char *strncpy(char *dest, const char *src, size_t count) > { > char *tmp = dest; > > while (count && *src) { > *tmp++ = *src++; > count--; > } > > if (count) { > size_t count2; > > while (count & (sizeof(long) - 1)) { Shouldn't this be: while (tmp & (sizeof(long) - 1)) { > *tmp++ = '\0'; > count--; > } > > count2 = count / sizeof(long); > while (count2) { > *((long *)tmp)++ = '\0'; > count2--; > } > > count &= (sizeof(long) - 1); > while (count) { > *tmp++ = '\0'; > count--; > } > } > > return dest; > } -- Dan - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/