[Avcheck] Building avcheck with dietlibc

Michael Tokarev mjt@tls.msk.ru
Mon, 04 Mar 2002 23:41:38 +0300


Ralf Hildebrandt wrote:
> 
> Spits out some warningS:
> 
> [root@hauptpostamt avcheck-0.6]# diet gcc -o avcheck -O2 -Wall -DVERSION=\"0.6\" avcheck.c [ -f /usr/lib/libsocket.so ] && echo
> -lsocket -lnsl

Oh oh, another usage of dietlibc... ;)

> avcheck.c: In function tcpsock':
> avcheck.c:189: warning: implicit declaration of function memcpy'
> avcheck.c:195: warning: implicit declaration of function memset'

avcheck.c includes string.h.  Both those functions declared in dietlibc's
string.h.  Ha:

#ifndef __GNUC__
/* gcc unfortunately has some internal prototypes that are not compliant
 * to the single unix specification and if we define the correct
 * prototypes here, gcc emits warnings. */
int memcmp(const void *s1, const void *s2, size_t n) __THROW __pure__;
void* memset(void *s, int c, size_t n) __THROW;
void* memcpy(void *dest, const void *src, size_t n) __THROW;
#endif

How very cute.

> avcheck.c: In function main': avcheck.c:733: warning: value computed is not used

$Id: avcheck.c,v 1.4 2001/11/09 18:38:44 mjt Exp $ -- v 0.6:

    s.sun_family = AF_UNIX;
    strncpy(s.sun_path, avsocket, sizeof(s.sun_path) - 1);  <== line 733
    if (connect(avfd, (struct sockaddr*)&s,
       ....

> /opt/diet/lib-i386/libc.a(sprintf.o): In function sprintf': sprintf.o(.text+0xe): warning: Avoid *sprintf; use *snprintf. It is more secure.

All usages of sprintf are checked before.  E.g.:

  l = 3 + 15 + 1 + strlen(path);
  p = (char*)alloca(l + 1);
  sprintf(p, "<0>%.15s:%s", ctime(&now) + 4, path);

There is no need to use snprintf here -- effect will be just the same.
BTW, on old solarises there was no snprintf.  Both avcheck and avp/drweb
should run on such systems.

> /tmp/cc3jrOv7.o: In function err':
> /tmp/cc3jrOv7.o(.text+0xa4): warning: your code uses stdio (7+k bloat).

This is also cute.  So what, do not use stdio at all, and always implement
our own error-prone and ugly mini-stdio?!

> /tmp/cc3jrOv7.o: In function tcpsock':
> /tmp/cc3jrOv7.o(.text+0x2c8): warning: gethostbyname() leaks memory. Use gethostbyname_r instead!

Not all systems has gethostbyname_r as well.  Yes, gethostbyname leaks memory
in dietlibc.  But this isn't a problem: one or two calls per invocation (one
for -S host:port and another may be used for drweb:host:port) is ok.

> /opt/diet/lib-i386/libc.a(vfprintf.o): In function vfprintf': vfprintf.o(.text+0x36): warning: the printf functions add several kilobytes of bloat.

The same as for stdio.  Either we will write our own implementation each time, or
we will use already written routines.

> /opt/diet/lib-i386/libc.a(vsscanf.o): In function vsscanf': vsscanf.o(.text+0x76): warning: the scanf functions add several kilobytes of bloat.

scanf is a recommended way to convert string to number:

  while((c = getopt(argc, argv, "t:f:d:s:S:ni:cw:h:")) != EOF)
    switch(c) {
    case 't': /* timeout */
      if (sscanf(optarg, "%u%c", &avtimeout, (char*)&c) != 1)
        err(0, "invalid timeout value `%s'", optarg);
      break;

(the only usage of scanf in avcheck).

BTW, on my system, no linker warnings produced.  dietlibc-0.14,
binutils-2.11.92.0.12, gcc-3.1-pre.  But maybe I missed something
when installed dietlibc (in fact it's very probably).

I see no single point to worry...  Oh well, if the goal is to really make
avcheck very tiny -- but there are other ways for such optimizations... ;)

Regards,
 Michael.