From: Marco Gerards <metgerards@student.han.nl>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: strndup broken
Date: Fri, 21 Jan 2005 20:19:00 +0000 [thread overview]
Message-ID: <87acr2fscr.fsf@marco.marco-g.com> (raw)
In-Reply-To: <20050108234820.GA7198@miracle> (Hollis Blanchard's message of "Sat, 8 Jan 2005 17:48:20 -0600")
Hollis Blanchard <hollis@penguinppc.org> 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 <metgerards@student.han.nl>
* 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 *
next prev parent reply other threads:[~2005-01-21 20:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-08 23:48 strndup broken Hollis Blanchard
2005-01-21 20:19 ` Marco Gerards [this message]
2005-01-22 5:38 ` Hollis Blanchard
2005-01-22 13:46 ` Marco Gerards
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87acr2fscr.fsf@marco.marco-g.com \
--to=metgerards@student.han.nl \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.