From 00362a273fc5892056e5acdaf387f77b002436cc Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 23 Jan 2013 10:41:48 -0500 Subject: [PATCH] fix `string-normalize-nf[k]c' when composed is much smaller then decomposed For composed normalization, space is initially allocated based on the decomposed length. The clean up step to avoid wasted space was wrong. --- collects/tests/racket/uni-norm.rktl | 6 ++++++ src/racket/src/string.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/collects/tests/racket/uni-norm.rktl b/collects/tests/racket/uni-norm.rktl index 34ef000f1f..203e1983e9 100644 --- a/collects/tests/racket/uni-norm.rktl +++ b/collects/tests/racket/uni-norm.rktl @@ -80,4 +80,10 @@ (test c5 string-normalize-nfkd c5))) test-strings) +;; Some tests where the composed form is much smaller than decomposed: +(let () + (define s (list->string (for/list ([i 64]) #\é))) + (test s string-normalize-nfc s) + (test s string-normalize-nfc (string-normalize-nfd s))) + (report-errs) diff --git a/src/racket/src/string.c b/src/racket/src/string.c index 23dcad8bdb..907a53bd7a 100644 --- a/src/racket/src/string.c +++ b/src/racket/src/string.c @@ -3891,8 +3891,8 @@ static Scheme_Object *normalize_c(Scheme_Object *o) s2[j] = 0; if (len - j > 16) { - s2 = (mzchar *)scheme_malloc_atomic((j + 1) * sizeof(mzchar)); - memcpy(s2, s, (j + 1) * sizeof(mzchar)); + s = (mzchar *)scheme_malloc_atomic((j + 1) * sizeof(mzchar)); + memcpy(s, s2, (j + 1) * sizeof(mzchar)); s2 = s; }