bug-gnulib
[Top][All Lists]
Advanced

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

Re: RFC: modules for generic unordered sets and mappings


From: Jim Meyering
Subject: Re: RFC: modules for generic unordered sets and mappings
Date: Fri, 02 Jul 2010 15:22:44 +0200

Paolo Bonzini wrote:
...
>>> In fact, glib or libnih probably provide all that you need already,
>>> and they're always loaded on a modern Linux system so their cost is
>>> effectively zero.
>>
>> Not everyone can depend on "glib" being installed.
>> Are you seriously suggesting that one of those libraries become
>> a prerequisite of fundamental packages like find, tar and coreutils?
>
> libnih is used by upstart (which is /sbin/init), so that would
> actually make some sense.  It is installed in /lib under Linux
> systems:

[ Since I found no bug-reporting email address for libnih and didn't
  feel like logging in to launchpad just to post this, I've simply
  Cc'd Scott, who is listed as the owner of this package.
  Scott, if you'd like more context, here's the thread:

  http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/22198/focus=22216 ]


I checked the latest out with this command:

    bzr branch lp:libnih

and did a superficial review.

libnih appears not to be mature enough for my needs, and besides,
lacks functionality that is absolutely required in coreutils.

A few quick points:

Its hash implementation includes no ability to rehash if the
initially-chosen table size ends up being too small, and hence
no analog of gnulib's "tuning" (to influence growth/shrink rate).

---------------------------------------
Its buffer-resize code doesn't handle overflow
when the current size + "grow" is larger than SIZE_MAX:

  int
  nih_io_buffer_resize (NihIoBuffer *buffer,
                        size_t       grow)
  {
          char   *new_buf;
          size_t  new_len, new_size;

          nih_assert (buffer != NULL);

          new_len = buffer->len + grow;
          if (! new_len) {
                  /* No bytes to store, so clean up the buffer */
                  if (buffer->buf)
                          nih_unref (buffer->buf, buffer);

                  buffer->buf = NULL;
                  buffer->size = 0;

                  return 0;
          }

          /* Round buffer to next largest multiple of BUFSIZ */
          new_size = ((new_len - 1) / BUFSIZ) * BUFSIZ + BUFSIZ;
          if (new_size == buffer->size)
                  return 0;

          /* Adjust buffer memory */
          new_buf = nih_realloc (buffer->buf, buffer, new_size);
          if (! new_buf)
                  return -1;

---------------------------------------
Finally, its directory-traversal code uses strcoll as the qsort name
comparator, but does not handle strcoll failure.  Doing that can evoke
from qsort what POSIX calls "undefined behavior", i.e., often a segfault,
silent memory corruption, etc.   Scott, to fix this, you may want to
look at how the xstrcoll function is used in coreutils' ls.c.

I stopped there.

Jim



reply via email to

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