Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Cs5Tv-0008JJ-5u for mharc-grub-devel@gnu.org; Fri, 21 Jan 2005 15:34:11 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Cs5Ts-0008Im-Ms for grub-devel@gnu.org; Fri, 21 Jan 2005 15:34:08 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Cs5Tr-0008HZ-98 for grub-devel@gnu.org; Fri, 21 Jan 2005 15:34:07 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Cs5Tq-0008H5-RD for grub-devel@gnu.org; Fri, 21 Jan 2005 15:34:06 -0500 Received: from [145.74.66.11] (helo=mail-cn.han.nl) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Cs5Gr-0004Ur-LC for grub-devel@gnu.org; Fri, 21 Jan 2005 15:20:41 -0500 Received: from vscan-cn.han.nl (venus.han.nl [145.74.65.6]) by mail-cn.han.nl (Postfix) with ESMTP id 5D3339F52 for ; Fri, 21 Jan 2005 21:19:15 +0100 (CET) Received: from mail-cn.han.nl ([145.74.66.11]) by vscan-cn.han.nl (venus.han.nl [145.74.65.6]) (amavisd-new, port 10024) with ESMTP id 12430-10 for ; Fri, 21 Jan 2005 21:19:14 +0100 (CET) Received: from mail1.han.nl (mail1.han.nl [145.74.103.11]) by mail-cn.han.nl (Postfix) with ESMTP id 55A339F32 for ; Fri, 21 Jan 2005 21:19:14 +0100 (CET) Received: from marco.marco-g.com (mgerards.xs4all.nl [82.92.27.129]) by mail1.han.nl (Postfix) with ESMTP id 74C3CC047 for ; Fri, 21 Jan 2005 21:19:13 +0100 (CET) Mail-Copies-To: metgerards@student.han.nl To: The development of GRUB 2 References: <20050108234820.GA7198@miracle> From: Marco Gerards Date: Fri, 21 Jan 2005 20:19:00 +0000 In-Reply-To: <20050108234820.GA7198@miracle> (Hollis Blanchard's message of "Sat, 8 Jan 2005 17:48:20 -0600") Message-ID: <87acr2fscr.fsf@marco.marco-g.com> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new (2.2.0) at vscan-cn.han.nl Subject: Re: strndup broken X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jan 2005 20:34:09 -0000 Hollis Blanchard writes: > A while back I made the unpleasent discovery that grub_strndup was > broken. This patch fixes it, but the author has been having trouble > sending it out. Because of copyright problems (Ian did not assign his copyrights yet) and especially because the old function was just plain wrong I have rewritten it. Can you check if it works for you? If I don't hear anything I will commit it next week or so. Thanks, Marco 2005-01-21 Marco Gerards * kern/misc.c (grub_strndup): Function rewritten. Index: kern/misc.c =================================================================== RCS file: /cvsroot/grub/grub2/kern/misc.c,v retrieving revision 1.16 diff -u -p -u -p -r1.16 misc.c --- kern/misc.c 1 Nov 2004 16:14:16 -0000 1.16 +++ kern/misc.c 21 Jan 2005 20:15:00 -0000 @@ -354,18 +354,19 @@ grub_strdup (const char *s) char * grub_strndup (const char *s, grub_size_t n) { - grub_size_t len = 0; - char *p = (char *) s; + grub_size_t len; + char *p; - while (*(p++) && len < n) - len++; - - len = grub_strlen (s) + 1; - p = (char *) grub_malloc (len); + len = grub_strlen (s); + if (len > n) + len = n; + p = (char *) grub_malloc (len + 1); if (! p) return 0; - - return grub_memcpy (p, s, len); + + grub_memcpy (p, s, len); + p[len] = '\0'; + return p; } void *