[PATCH] Don't put empty strings in buddy/divemaster

Anton Lundin glance at acc.umu.se
Fri Jun 26 15:34:43 PDT 2015


On 26 June, 2015 - Linus Torvalds wrote:

> On Fri, Jun 26, 2015 at 2:50 PM, Anton Lundin <glance at acc.umu.se> wrote:
> > We store no value as a NULL, so we can omit that value from the xml and
> > git files.
> 
> Ack.
> 
> However, it strikes me that maybe we should just teach "copy_string()"
> to do this. That would match "same_string()", and copy_string()
> already returns NULL today (although only if you passed in NULL), so
> it really would match that too.
> 
> If people wanted strdup(), they should use strdup(). copy_string is
> very much about our "empty and NULL are the same string" model.
> 

Feels cleaner, and if its cousins behaves that way, copy_string() should
do it to.

> So maybe a simpler patch instead? Something (totally untested!) like:
> 
>    static inline char *copy_string(const char *s)
>    {
>   -       return s ? strdup(s) : NULL;
>   +       return (s && *s) ? strdup(s) : NULL;
>    }
> 
> Hmm?
> 

I must have entered vacation mode too quickly and turned off my pointer
fu. It took me 10s to figure out how that one worked.


But, yep, it looks better.


//Anton


-- 
Anton Lundin	+46702-161604


More information about the subsurface mailing list