Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 Nov 2015 19:54:40 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r290508 - head/usr.bin/localedef
Message-ID:  <201511071954.tA7Jsexv062089@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Sat Nov  7 19:54:40 2015
New Revision: 290508
URL: https://svnweb.freebsd.org/changeset/base/290508

Log:
  Fix an off by one due to bad conversion from avl(3) to tree(3)
  Readd calloc as it was not the issue just the messenger
  
  Submitted by:	dim
  Found by:	Address Sanitizer

Modified:
  head/usr.bin/localedef/collate.c

Modified: head/usr.bin/localedef/collate.c
==============================================================================
--- head/usr.bin/localedef/collate.c	Sat Nov  7 19:33:57 2015	(r290507)
+++ head/usr.bin/localedef/collate.c	Sat Nov  7 19:54:40 2015	(r290508)
@@ -1242,11 +1242,11 @@ dump_collate(void)
 	}
 	n = 0;
 	RB_FOREACH(ce, elem_by_expand, &elem_by_expand) {
-		n++;
 		(void) wsncpy(chain[n].str, ce->expand, COLLATE_STR_LEN);
 		for (i = 0; i < NUM_WT; i++) {
 			chain[n].pri[i] = get_weight(ce->ref[i], i);
 		}
+		n++;
 	}
 	if (n != collinfo.chain_count)
 		INTERR;
@@ -1255,12 +1255,11 @@ dump_collate(void)
 	 * Large (> UCHAR_MAX) character priorities
 	 */
 	RB_NUMNODES(collchar_t, collchars, &collchars, n);
-	large = malloc(sizeof (collate_large_t) * n);
+	large = calloc(n, sizeof (collate_large_t));
 	if (large == NULL) {
 		fprintf(stderr, "out of memory");
 		return;
 	}
-	memset(large, 0, sizeof (collate_large_t) * n);
 
 	i = 0;
 	RB_FOREACH(cc, collchars, &collchars) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201511071954.tA7Jsexv062089>