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]

logic tweaks for charmap_read



The charmap_read() function used in localedef has a broken logic:

  - If filename == NULL, it reads the headers of all charmaps but
    does nothing. Optimization: Move the filename != NULL test outside
    the loop.

  - Redundant code:

        fscanf (fp, " <code_set_name> %as", &name) == 1
        || (fscanf (fp, " <code_set_name> \"%as\"", &name) == 1)

    The second clause can never succeed because the first clause always
    wins. Note that this second clause does not occur in the similar code
    in locale.c.

  - A return statement which returns from the function without closing
    the DIR * reference.


2000-09-30  Bruno Haible  <haible@clisp.cons.org>

	* locale/programs/charmap.c (charmap_read): Avoid redundant tests.
	Don't forget to call closedir when the filename was found as a
	code_set_name.

*** glibc-20000928/locale/programs/charmap.c.bak	Wed Jul  5 14:14:24 2000
--- glibc-20000928/locale/programs/charmap.c	Sat Sep 30 00:52:16 2000
***************
*** 120,126 ****
  	}
      }
  
!   if (result == NULL)
      {
        /* OK, one more try.  We also accept the names given to the
  	 character sets in the files.  Sometimes they differ from the
--- 120,126 ----
  	}
      }
  
!   if (result == NULL && filename != NULL)
      {
        /* OK, one more try.  We also accept the names given to the
  	 character sets in the files.  Sometimes they differ from the
***************
*** 155,166 ****
  			char junk[BUFSIZ];
  
  			if (fscanf (fp, " <code_set_name> %as", &name) == 1
- 			    || (fscanf (fp, " <code_set_name> \"%as\"", &name)
- 				== 1)
  			    || fscanf (fp, "%% alias %as", &name) == 1)
  			  {
! 			    if (filename != NULL
! 				&& strcasecmp (name, filename) == 0)
  			      break;
  
  			    free (name);
--- 155,163 ----
  			char junk[BUFSIZ];
  
  			if (fscanf (fp, " <code_set_name> %as", &name) == 1
  			    || fscanf (fp, "%% alias %as", &name) == 1)
  			  {
! 			    if (strcasecmp (name, filename) == 0)
  			      break;
  
  			    free (name);
***************
*** 188,196 ****
  			cmfile = lr_open (buf, charmap_hash);
  			result = (cmfile == NULL
  				  ? NULL : parse_charmap (cmfile));
- 
- 			if (result)
- 			  return result;
  
  			break;
  		      }
--- 185,190 ----

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