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]

another gettext bug



Outside glibc, on platforms without 'tsearch' function, ngettext would not
work. In fact, the only place where plural_eval() is called is inside
#if defined HAVE_TSEARCH || defined _LIBC. Here is a fix.

Bruno


2000-07-14  Bruno Haible  <haible@clisp.cons.org>

	* intl/dcigettext.c (dcigettext): Call plural_eval on all platforms,
	not only those having tsearch.

*** glibc-20000714/intl/dcigettext.c.bak	Mon Jul  3 16:39:28 2000
--- glibc-20000714/intl/dcigettext.c	Sat Jul 15 16:25:41 2000
***************
*** 553,576 ****
        if (domain != NULL)
  	{
  	  unsigned long int index = 0;
- #if defined HAVE_TSEARCH || defined _LIBC
- 	  struct loaded_domain *domaindata =
- 	    (struct loaded_domain *) domain->data;
  
  	  if (plural != 0)
  	    {
  	      /* 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 = plural_eval (domaindata->plural, n);
! 	      if (search->plindex >= domaindata->nplurals)
! 		/* This should never happen.  It means the plural expression
! 		   and the given maximum value do not match.  */
! 		search->plindex = 0;
! 	      index = search->plindex;
  	      search->category = category;
  
  	      foundp = (struct known_translation_t **) tfind (search, &root,
--- 553,577 ----
        if (domain != NULL)
  	{
  	  unsigned long int index = 0;
  
  	  if (plural != 0)
  	    {
+ 	      struct loaded_domain *domaindata =
+ 		(struct loaded_domain *) domain->data;
+ 	      index = plural_eval (domaindata->plural, n);
+ 	      if (index >= domaindata->nplurals)
+ 		/* This should never happen.  It means the plural expression
+ 		   and the given maximum value do not match.  */
+ 		index = 0;
+ 
+ #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;
  	      search->category = category;
  
  	      foundp = (struct known_translation_t **) tfind (search, &root,
***************
*** 580,587 ****
  		  __libc_rwlock_unlock (_nl_state_lock);
  		  return (char *) (*foundp)->translation;
  		}
- 	    }
  #endif
  
  	  retval = _nl_find_msg (domain, msgid1, index);
  
--- 581,588 ----
  		  __libc_rwlock_unlock (_nl_state_lock);
  		  return (char *) (*foundp)->translation;
  		}
  #endif
+ 	    }
  
  	  retval = _nl_find_msg (domain, msgid1, index);
  

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