Author: markj
Date: Thu Jan 16 00:26:53 2020
New Revision: 356769
URL: https://svnweb.freebsd.org/changeset/base/356769

Log:
  MFC r356569:
  libc: Fix a few bugs in the xlocale collation code.
  
  PR:   243195

Modified:
  stable/12/lib/libc/locale/collate.c
  stable/12/lib/libc/locale/rune.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/lib/libc/locale/collate.c
==============================================================================
--- stable/12/lib/libc/locale/collate.c Wed Jan 15 21:05:43 2020        
(r356768)
+++ stable/12/lib/libc/locale/collate.c Thu Jan 16 00:26:53 2020        
(r356769)
@@ -109,7 +109,7 @@ __collate_load_tables(const char *encoding)
        return (__collate_load_tables_l(encoding, &__xlocale_global_collate));
 }
 
-int
+static int
 __collate_load_tables_l(const char *encoding, struct xlocale_collate *table)
 {
        int i, chains, z;
@@ -147,7 +147,7 @@ __collate_load_tables_l(const char *encoding, struct x
        }
        map = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
        (void) _close(fd);
-       if ((TMP = map) == NULL) {
+       if ((TMP = map) == MAP_FAILED) {
                return (_LDP_ERROR);
        }
 
@@ -181,6 +181,11 @@ __collate_load_tables_l(const char *encoding, struct x
                return (_LDP_ERROR);
        }
 
+       if (table->map && (table->maplen > 0)) {
+               (void) munmap(table->map, table->maplen);
+       }
+       table->map = map;
+       table->maplen = sbuf.st_size;
        table->info = info;
        table->char_pri_table = (void *)TMP;
        TMP += sizeof (collate_char_t) * (UCHAR_MAX + 1);

Modified: stable/12/lib/libc/locale/rune.c
==============================================================================
--- stable/12/lib/libc/locale/rune.c    Wed Jan 15 21:05:43 2020        
(r356768)
+++ stable/12/lib/libc/locale/rune.c    Thu Jan 16 00:26:53 2020        
(r356769)
@@ -94,7 +94,7 @@ _Read_RuneMagi(const char *fname)
 
        fdata = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
        (void) _close(fd);
-       if (fdata == NULL) {
+       if (fdata == MAP_FAILED) {
                errno = EINVAL;
                return (NULL);
        }
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to