This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

libintl patches (4)


Since gcc doesn't tolerate zero-sized types anymore, here is a patch
to remove use 1-sized arrays at the end of structs.


2000-12-31  Bruno Haible  <haible@clisp.cons.org>

	* intl/gettextP.h (ZERO): New macro.
	(struct binding): Always use ZERO.
	* intl/bindtextdom.c (set_binding_values): Use offsetof, not sizeof.
	Include <stddef.h> whenever possible.
	* intl/dcigettext.c (ZERO): Remove macro.
	(struct transmem_list): Use ZERO.
	(DCIGETTEXT): Use offsetof, not sizeof.
	Include <stddef.h> whenever possible.

diff -r -c3 glibc-cvs/intl2/gettextP.h glibc-cvs/intl3/gettextP.h
*** glibc-cvs/intl/gettextP.h	Thu May  4 12:53:41 2000
--- glibc-cvs/intl/gettextP.h	Wed Jan  3 19:59:38 2001
***************
*** 139,154 ****
    unsigned long int nplurals;
  };
  
  struct binding
  {
    struct binding *next;
    char *dirname;
    char *codeset;
! #ifdef __GNUC__
!   char domainname[0];
! #else
!   char domainname[1];
! #endif
  };
  
  extern int _nl_msg_cat_cntr;
--- 139,154 ----
    unsigned long int nplurals;
  };
  
+ /* We want to allocate a string at the end of the struct.  But ISO C
+    doesn't allow zero sized arrays.  */
+ #define ZERO 1
+ 
  struct binding
  {
    struct binding *next;
    char *dirname;
    char *codeset;
!   char domainname[ZERO];
  };
  
  extern int _nl_msg_cat_cntr;
diff -r -c3 glibc-cvs/intl2/bindtextdom.c glibc-cvs/intl3/bindtextdom.c
*** glibc-cvs/intl/bindtextdom.c	Wed Jan  3 19:57:06 2001
--- glibc-cvs/intl/bindtextdom.c	Wed Jan  3 19:59:38 2001
***************
*** 20,26 ****
  # include <config.h>
  #endif
  
! #if defined STDC_HEADERS || defined _LIBC
  # include <stdlib.h>
  #else
  # ifdef HAVE_MALLOC_H
--- 20,29 ----
  # include <config.h>
  #endif
  
! #if defined HAVE_STDDEF_H || defined _LIBC
! # include <stddef.h>
! #endif
! #if defined HAVE_STDLIB_H || defined _LIBC
  # include <stdlib.h>
  #else
  # ifdef HAVE_MALLOC_H
***************
*** 234,240 ****
        /* We have to create a new binding.  */
        size_t len = strlen (domainname) + 1;
        struct binding *new_binding =
! 	(struct binding *) malloc (sizeof (*new_binding) + len);
  
        if (__builtin_expect (new_binding == NULL, 0))
  	goto failed;
--- 237,243 ----
        /* We have to create a new binding.  */
        size_t len = strlen (domainname) + 1;
        struct binding *new_binding =
! 	(struct binding *) malloc (offsetof (struct binding, domainname) + len);
  
        if (__builtin_expect (new_binding == NULL, 0))
  	goto failed;
diff -r -c3 glibc-cvs/intl2/dcigettext.c glibc-cvs/intl3/dcigettext.c
*** glibc-cvs/intl/dcigettext.c	Wed Jan  3 15:33:40 2001
--- glibc-cvs/intl/dcigettext.c	Wed Jan  3 20:03:39 2001
***************
*** 54,61 ****
  # define __set_errno(val) errno = (val)
  #endif
  
! #if defined STDC_HEADERS || defined _LIBC
  # include <stddef.h>
  # include <stdlib.h>
  #else
  char *getenv ();
--- 54,63 ----
  # define __set_errno(val) errno = (val)
  #endif
  
! #if defined HAVE_STDDEF_H || defined _LIBC
  # include <stddef.h>
+ #endif
+ #if defined HAVE_STDLIB_H || defined _LIBC
  # include <stdlib.h>
  #else
  char *getenv ();
***************
*** 197,210 ****
  # define HAVE_LOCALE_NULL
  #endif
  
- /* We want to allocate a string at the end of the struct.  gcc makes
-    this easy.  */
- #ifdef __GNUC__
- # define ZERO 0
- #else
- # define ZERO 1
- #endif
- 
  /* This is the type used for the search tree where known translations
     are stored.  */
  struct known_translation_t
--- 199,204 ----
***************
*** 332,338 ****
  static struct transmem_list
  {
    struct transmem_list *next;
!   char data[0];
  } *transmem_list;
  
  
--- 326,332 ----
  static struct transmem_list
  {
    struct transmem_list *next;
!   char data[ZERO];
  } *transmem_list;
  
  
***************
*** 416,423 ****
      {
        /* Try to find the translation among those which we found at
  	 some time.  */
!       search = (struct known_translation_t *) alloca (sizeof (*search)
! 						      + msgid_len);
        memcpy (search->msgid, msgid1, msgid_len);
        search->domain = (char *) domainname;
        search->plindex = 0;
--- 410,417 ----
      {
        /* Try to find the translation among those which we found at
  	 some time.  */
!       search = (struct known_translation_t *)
! 	     alloca (offsetof (struct known_translation_t, msgid) + msgid_len);
        memcpy (search->msgid, msgid1, msgid_len);
        search->domain = (char *) domainname;
        search->plindex = 0;
***************
*** 578,585 ****
  #if defined HAVE_TSEARCH || defined _LIBC
  	      /* Try to find the translation among those which we
  		 found at some time.  */
! 	      search = (struct known_translation_t *) alloca (sizeof (*search)
! 							      + msgid_len);
  	      memcpy (search->msgid, msgid1, msgid_len);
  	      search->domain = (char *) domainname;
  	      search->plindex = index;
--- 572,580 ----
  #if defined HAVE_TSEARCH || defined _LIBC
  	      /* Try to find the translation among those which we
  		 found at some time.  */
! 	      search = (struct known_translation_t *)
! 		       alloca (offsetof (struct known_translation_t, msgid)
! 			       + msgid_len);
  	      memcpy (search->msgid, msgid1, msgid_len);
  	      search->domain = (char *) domainname;
  	      search->plindex = index;
***************
*** 622,629 ****
  		  struct known_translation_t *newp;
  
  		  newp = (struct known_translation_t *)
! 		    malloc (sizeof (*newp) + msgid_len
! 			    + domainname_len + 1 - ZERO);
  		  if (newp != NULL)
  		    {
  		      newp->domain = mempcpy (newp->msgid, msgid1, msgid_len);
--- 617,624 ----
  		  struct known_translation_t *newp;
  
  		  newp = (struct known_translation_t *)
! 		    malloc (offsetof (struct known_translation_t, msgid)
! 			    + msgid_len + domainname_len + 1);
  		  if (newp != NULL)
  		    {
  		      newp->domain = mempcpy (newp->msgid, msgid1, msgid_len);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]