libtool-patches
[Top][All Lists]
Advanced

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

Re: Remove deps on *printf(3) in libltdl


From: Bob Friesenhahn
Subject: Re: Remove deps on *printf(3) in libltdl
Date: Tue, 21 Dec 2004 09:23:38 -0600 (CST)

On Tue, 21 Dec 2004, Ralf Wildenhues wrote:

As announced some time ago, I'd like to get rid of *printf in libltdl.
This is primarily an advantage for small-sized software.  With static
dietlibc on linux-x86, I can get an executable using libltdl at about
20K stripped size, which is not great, but a third less than without
this patch (this is including all libc functions, of course!).

Another side not is in place here, since I do not make use of strl*:
With allocated buffers of precomputed size, there can be no overflow
(unless you compute wrongly, of course).  I do not see much value in
safeguarding what would otherwise be a bug anyway.  YMMV.

In my country all drivers are required to wear seatbelts even though they are all self-attested expert drivers and their cars are perfectly maintained.

If all programmers were perfect, there would be no need for the strl* functions. Not all of us are perfect. I think that we should use the strl* functions even for turing-correct solutions since it helps double-check our work. There is little penalty for using these improved functions.

Bob


OK to apply to HEAD?

Regards,
Ralf

        * libltdl/lt__alloc.c (alloc_die_default),
        libltdl/ltdl.c (tryall_dlopen_module, load_deplibs):
        Replace all *printf invocations.

Index: libltdl/lt__alloc.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/lt__alloc.c,v
retrieving revision 1.4
diff -u -r1.4 lt__alloc.c
--- libltdl/lt__alloc.c 1 Oct 2004 10:24:18 -0000       1.4
+++ libltdl/lt__alloc.c 21 Dec 2004 07:07:42 -0000
@@ -44,7 +44,7 @@
static void
alloc_die_default (void)
{
-  fprintf (stderr, "Out of memory.\n");
+  fputs ("Out of memory.\n", stderr);
  exit (EXIT_FAILURE);
}

Index: libltdl/ltdl.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/ltdl.c,v
retrieving revision 1.228
diff -u -r1.228 ltdl.c
--- libltdl/ltdl.c      16 Dec 2004 12:00:09 -0000      1.228
+++ libltdl/ltdl.c      21 Dec 2004 07:07:43 -0000
@@ -422,7 +422,9 @@
  if (!filename)
    return 1;

-  sprintf (filename, "%.*s/%s", (int) dirname_len, dirname, dlname);
+  strcpy (filename, dirname);
+  filename[dirname_len] = '/';
+  strcpy (filename + dirname_len + 1, dlname);

  /* Now that we have combined DIRNAME and MODULENAME, if there is
     also a PREFIX to contend with, simply recurse with the arguments
@@ -814,7 +816,10 @@
                  size_t name_len = 3+ /* "lib" */ LT_STRLEN (p + 2);
                  name = MALLOC (char, 1+ name_len);
                  if (name)
-                   sprintf (name, "lib%s", p+2);
+                   {
+                     strcpy(name, "lib");
+                     strcpy(name + 3, p+2);
+                   }
                }
              else
                name = lt__strdup(p);



======================================
Bob Friesenhahn
address@hidden
http://www.simplesystems.org/users/bfriesen




reply via email to

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