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

Linus Torvalds torvalds at linux-foundation.org
Fri Jun 26 14:57:25 PDT 2015


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.

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?

                  Linus


More information about the subsurface mailing list