bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GPT name overflow


From: Andreas Dilger
Subject: Re: GPT name overflow
Date: Mon, 18 Mar 2002 22:13:12 -0700
User-agent: Mutt/1.3.27i

On Mar 19, 2002  18:23 +1100, Andrew Clausen wrote:
> > Well, BSD partitions only have 8 types AFAICS, so it shouldn't matter
> > whether it is decimal or hex.  I could be wrong, as I've never used BSD
> > partition types, but that's what I saw in the code.
> 
> fdisk uses hex *shrug*.  Everyone knows 0x83... do you know what it
> is in decimal?

Well, what I was getting at is that 0-7 in decimal is the same as 0-7
in hex, so it is irrelevant if it is %d or %x for BSD.  We may as well
stick with hex, because it is hex for the MSDOS and GPT partitions.

> > Actually, in most cases this is not true, because we are just pointing
> > to a static entry in the array.
> 
> Which makes the problem worse, because people reading the code might
> get the impression that it really is constant memory.

Well, in 99.9% of cases it is a pointer to a static string.  The
"type-%x" stuff is only to handle the extra cases.  For MSDOS this could
be avoided entirely by fully enumerating all of the partition types.
For GPT that is not possible.

> > In general, I hate it when applications have to free memory allocated by
> > a library.
> 
> Why?  Bureaucracy?  (Garbage collection rocks!  Want to rewrite parted
> in haskell?!)

Well, the problem is that I generally don't want to free code that is
not allocated by my program (sometimes you are supposed to, sometimes
you aren't).  Even worse is if there is a mismatch between the malloc/free
used by the library, and that in the application.  Usually, if I ever
write code which does this, I also supply a "foo_free" function, even if
it is just a wrapper around "free()", to avoid problems.

> > I'd rather we had to pass in an array (how to know size?)
> > and copy the name string into that.
> 
> I prefer the opposite, hehe.  strdup() and free() are simple.
> snprintf, 2 parameters, etc. is complicated.

Well, I'm not saying this is great, but it is better than one piece of
code allocating memory, and another piece of code freeing it.

Cheers, Andreas
--
Andreas Dilger  \ "If a man ate a pound of pasta and a pound of antipasto,
                 \  would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/               -- Dogbert




reply via email to

[Prev in Thread] Current Thread [Next in Thread]