public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Small glibc fixes
@ 2007-03-16 18:59 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2007-03-16 18:59 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

While building glibc with gcc 4.3 I looked at a few warnings
(some new with 4.3, some older).

dl_open_worker reported an uninitialized variable, because DL_DST_REQ_STATIC
used l var, but that wasn't passed through as macro argument.  All
other users of DL_DST_REQUIRED passed l as first argument to it, so
it made no difference, but dl_open_worker does not.  I have rearranged
the code so that without dl-dst.h fix it actually errored out - l
was used independently in 2 different scopes.

include/dlfcn.h is included with #define link_map link_map_public
and that struct isn't declared yet, so gcc was warning.

gcc 4.3 now complains about (socklen_t) (((struct sockaddr_un *) NULL)->sun_path)
claiming a pointer on 64-bit target is truncated to 32-bit int.  It
was a fancy way of writing offsetof anyway.

tst-mktime2.c actually got killed when compiled with gcc 4.3, which
assumed the loop will never wrap and so after calling the function
with INT_MAX/2+1 it called it with INT_MIN and then forever with
0.

_itoa is now a macro, so when vfwprintf wants to redefine to _itowa,
it should undef it first.

And lastly, strerror_l was using free, but didn't have a prototype for that.

2007-03-16  Jakub Jelinek  <jakub@redhat.com>

	* elf/dl-open.c (dl_open_worker): Declare l in 2 different
	smaller scopes.
	* elf/dl-dst.h (DL_DST_REQ_STATIC): Add l as macro argument.
	(DL_DST_REQUIRED): Adjust user.

	* include/dlfcn.h (struct link_map): New forward decl.

	* inet/getnameinfo.c: Include stddef.h.
	(getnameinfo): Use offsetof.

	* time/tst-mktime2.c (do_test): Don't rely on signed wrap.

	* stdio-common/vfprintf.c (_itoa): Undef before redefining.

	* string/strerror_l.c: Include stdlib.h.

--- libc/elf/dl-open.c.jj	2007-03-16 18:26:45.000000000 +0100
+++ libc/elf/dl-open.c	2007-03-16 18:26:45.000000000 +0100
@@ -161,7 +161,7 @@ dl_open_worker (void *a)
   struct dl_open_args *args = a;
   const char *file = args->file;
   int mode = args->mode;
-  struct link_map *new, *l;
+  struct link_map *new;
   int lazy;
   unsigned int i;
   bool any_tls = false;
@@ -186,6 +186,7 @@ dl_open_worker (void *a)
 	 By default we assume this is the main application.  */
       call_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
 
+      struct link_map *l;
       for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
 	for (l = GL(dl_ns)[ns]._ns_loaded; l != NULL; l = l->l_next)
 	  if (caller_dlopen >= (const void *) l->l_map_start
@@ -325,7 +326,7 @@ dl_open_worker (void *a)
   /* Relocate the objects loaded.  We do this in reverse order so that copy
      relocs of earlier objects overwrite the data written by later objects.  */
 
-  l = new;
+  struct link_map *l = new;
   while (l->l_next)
     l = l->l_next;
   while (1)
--- libc/elf/dl-dst.h.jj	2006-10-19 17:28:02.000000000 +0200
+++ libc/elf/dl-dst.h	2007-03-16 19:21:29.000000000 +0100
@@ -1,5 +1,6 @@
 /* Handling of dynamic sring tokens.
-   Copyright (C) 1999,2001,2002,2003,2004,2006 Free Software Foundation, Inc.
+   Copyright (C) 1999,2001,2002,2003,2004,2006,2007
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -50,7 +51,7 @@
 									      \
 	   First get the origin string if it is not available yet.	      \
 	   This can only happen for the map of the executable.  */	      \
-	DL_DST_REQ_STATIC						      \
+	DL_DST_REQ_STATIC (l)						      \
 	if ((l)->l_origin == NULL)					      \
 	  {								      \
 	    assert ((l)->l_name[0] == '\0');				      \
@@ -68,9 +69,9 @@
     __len; })
 
 #ifdef SHARED
-# define DL_DST_REQ_STATIC /* nothing */
+# define DL_DST_REQ_STATIC(l) /* nothing */
 #else
-# define DL_DST_REQ_STATIC \
+# define DL_DST_REQ_STATIC(l) \
   if ((l) == NULL)							      \
     {									      \
       const char *origin = _dl_get_origin ();				      \
--- libc/include/dlfcn.h.jj	2006-10-31 23:05:31.000000000 +0100
+++ libc/include/dlfcn.h	2007-03-16 18:30:41.000000000 +0100
@@ -45,6 +45,8 @@ extern int _dl_addr (const void *address
 libc_hidden_proto (_dl_addr)
 #endif
 
+struct link_map;
+
 /* Close an object previously opened by _dl_open.  */
 extern void _dl_close (void *map) attribute_hidden;
 /* Same as above, but without locking and safety checks for user
--- libc/inet/getnameinfo.c.jj	2006-08-28 18:23:18.000000000 +0200
+++ libc/inet/getnameinfo.c	2007-03-16 18:24:16.000000000 +0100
@@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBI
 #include <alloca.h>
 #include <errno.h>
 #include <netdb.h>
+#include <stddef.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -180,7 +181,7 @@ getnameinfo (const struct sockaddr *sa, 
   switch (sa->sa_family)
     {
     case AF_LOCAL:
-      if (addrlen < (socklen_t) (((struct sockaddr_un *) NULL)->sun_path))
+      if (addrlen < (socklen_t) offsetof (struct sockaddr_un, sun_path))
 	return EAI_FAMILY;
       break;
     case AF_INET:
--- libc/time/tst-mktime2.c.jj	2004-12-01 20:55:52.000000000 +0100
+++ libc/time/tst-mktime2.c	2007-03-16 17:42:27.000000000 +0100
@@ -102,7 +102,8 @@ static int
 do_test (void)
 {
   time_t t, delta;
-  int i, j;
+  int i;
+  unsigned int j;
 
   setenv ("TZ", "America/Sao_Paulo", 1);
   /* This test makes some buggy mktime implementations loop.
@@ -128,7 +129,7 @@ do_test (void)
       mktime_test ((time_t) (60 * 60));
       mktime_test ((time_t) (60 * 60 * 24));
 
-      for (j = 1; 0 < j; j *= 2)
+      for (j = 1; j <= INT_MAX; j *= 2)
 	bigtime_test (j);
       bigtime_test (j - 1);
     }
--- libc/stdio-common/vfprintf.c.jj	2007-01-22 16:47:39.000000000 +0100
+++ libc/stdio-common/vfprintf.c	2007-03-16 18:15:18.000000000 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006
+/* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006, 2007
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -99,6 +99,7 @@
 # define PUTC(C, F)	_IO_putwc_unlocked (C, F)
 # define ORIENT		if (_IO_fwide (s, 1) != 1) return -1
 
+# undef _itoa
 # define _itoa(Val, Buf, Base, Case) _itowa (Val, Buf, Base, Case)
 # define _itoa_word(Val, Buf, Base, Case) _itowa_word (Val, Buf, Base, Case)
 # undef EOF
--- libc/string/strerror_l.c.jj	2007-02-01 17:08:31.000000000 +0100
+++ libc/string/strerror_l.c	2007-03-16 18:17:33.000000000 +0100
@@ -19,6 +19,7 @@
 #include <libintl.h>
 #include <locale.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/param.h>
 

	Jakub

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-03-16 18:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-16 18:59 [PATCH] Small glibc fixes Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).