From: "Yoshinori K. Okuji" <okuji@enbug.org>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] read command
Date: Sat, 2 Feb 2008 13:38:28 +0100 [thread overview]
Message-ID: <200802021338.28362.okuji@enbug.org> (raw)
In-Reply-To: <20080201224800.GA12043@thorin>
On Friday 01 February 2008 23:48, Robert Millan wrote:
> On Fri, Feb 01, 2008 at 11:45:50PM +0100, Robert Millan wrote:
> > +static void *
> > +grub_xrealloc (void *ptr, grub_size_t size)
> > +{
> > + void *value = grub_realloc (ptr, size);
> > + if (value == 0)
> > + grub_fatal ("Virtual memory exhausted");
> > + return value;
> > +}
> > +
> > +static char *
> > +grub_getline (void)
> > +{
> > + int i;
> > + char *line;
> > +
> > + i = 0;
> > + line = grub_malloc (1 + i + sizeof('\0'));
> > +
> > + while ((line[i - 1] != '\n') && (line[i - 1] != '\r'))
> > + {
> > + line[i] = grub_getkey ();
> > + if (grub_isprint (line[i]))
> > + grub_putchar (line[i]);
> > + i++;
> > + line = grub_xrealloc (line, 1 + i + sizeof('\0'));
> > + }
> > + line[i] = '\0';
> > +
> > + return line;
> > +}
>
> Does it make sense to move any of these two to kernel? Or to normal.mod ?
> Or maybe just to un-static-ize them and leave them here?
What would be other use cases?
BTW it is a bad idea to use xrealloc. xmalloc and xrealloc are sometimes used
in the GNU Project, but they must not be used in GRUB. If a program runs in
user space, when it panics, the control is back to the OS. But GRUB is a
standalone program. When it panics, the user loses any kind of control. Thus
grub_fatal must be used only if there is nothing else you can do.
In this case, grub_getline should simply return NULL. How the user deals with
this situation is up to the user.
Okuji
next prev parent reply other threads:[~2008-02-02 12:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-01 22:45 [PATCH] read command Robert Millan
2008-02-01 22:48 ` Robert Millan
2008-02-02 12:38 ` Yoshinori K. Okuji [this message]
2008-02-02 17:05 ` Robert Millan
2008-02-02 18:48 ` Yoshinori K. Okuji
2008-02-02 20:34 ` Robert Millan
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=200802021338.28362.okuji@enbug.org \
--to=okuji@enbug.org \
--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.