Mercurial > hg > octave-lojdl > gnulib-hg
changeset 11205:2d19b06ab374
Handle empty strings correctly.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 22 Feb 2009 13:15:52 +0100 |
parents | 55b4123a6159 |
children | c7e84b56dbc3 |
files | ChangeLog lib/uninorm/u-normalize-internal.h tests/uninorm/test-u16-nfc.c tests/uninorm/test-u16-nfd.c tests/uninorm/test-u16-nfkc.c tests/uninorm/test-u16-nfkd.c tests/uninorm/test-u32-nfc.c tests/uninorm/test-u32-nfd.c tests/uninorm/test-u32-nfkc.c tests/uninorm/test-u32-nfkd.c tests/uninorm/test-u8-nfc.c tests/uninorm/test-u8-nfd.c tests/uninorm/test-u8-nfkc.c tests/uninorm/test-u8-nfkd.c |
diffstat | 14 files changed, 76 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2009-02-22 Bruno Haible <bruno@clisp.org> + + * lib/uninorm/u-normalize-internal.h (FUNC): At the end, handle + zero-length results and shrink excess allocated memory. + * tests/uninorm/test-u8-nfc.c (test_u8_nfc): Check empty string result. + * tests/uninorm/test-u8-nfd.c (test_u8_nfd): Likewise. + * tests/uninorm/test-u8-nfkc.c (test_u8_nfkc): Likewise. + * tests/uninorm/test-u8-nfkd.c (test_u8_nfkd): Likewise. + * tests/uninorm/test-u16-nfc.c (test_u16_nfc): Likewise. + * tests/uninorm/test-u16-nfd.c (test_u16_nfd): Likewise. + * tests/uninorm/test-u16-nfkc.c (test_u16_nfkc): Likewise. + * tests/uninorm/test-u16-nfkd.c (test_u16_nfkd): Likewise. + * tests/uninorm/test-u32-nfc.c (test_u32_nfc): Likewise. + * tests/uninorm/test-u32-nfd.c (test_u32_nfd): Likewise. + * tests/uninorm/test-u32-nfkc.c (test_u32_nfkc): Likewise. + * tests/uninorm/test-u32-nfkd.c (test_u32_nfkd): Likewise. + 2009-02-21 Bruno Haible <bruno@clisp.org> * doc/gnulib.texi: Include safe-alloc.texi earlier.
--- a/lib/uninorm/u-normalize-internal.h +++ b/lib/uninorm/u-normalize-internal.h @@ -331,6 +331,29 @@ } } + if (length == 0) + { + if (result == NULL) + { + /* Return a non-NULL value. NULL means error. */ + result = (UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + goto fail; + } + } + } + else if (result != resultbuf && length < allocated) + { + /* Shrink the allocated memory if possible. */ + UNIT *memory; + + memory = (UNIT *) realloc (result, length * sizeof (UNIT)); + if (memory != NULL) + result = memory; + } + if (sortbuf_count > 0) abort (); if (sortbuf != sortbuf_preallocated)
--- a/tests/uninorm/test-u16-nfc.c +++ b/tests/uninorm/test-u16-nfc.c @@ -103,6 +103,9 @@ void test_u16_nfc (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint16_t input[] = { 0x0020 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
--- a/tests/uninorm/test-u16-nfd.c +++ b/tests/uninorm/test-u16-nfd.c @@ -103,6 +103,9 @@ void test_u16_nfd (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint16_t input[] = { 0x0020 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
--- a/tests/uninorm/test-u16-nfkc.c +++ b/tests/uninorm/test-u16-nfkc.c @@ -103,6 +103,9 @@ void test_u16_nfkc (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint16_t input[] = { 0x0020 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
--- a/tests/uninorm/test-u16-nfkd.c +++ b/tests/uninorm/test-u16-nfkd.c @@ -103,6 +103,9 @@ void test_u16_nfkd (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint16_t input[] = { 0x0020 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
--- a/tests/uninorm/test-u32-nfc.c +++ b/tests/uninorm/test-u32-nfc.c @@ -103,6 +103,9 @@ void test_u32_nfc (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint32_t input[] = { 0x0020 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
--- a/tests/uninorm/test-u32-nfd.c +++ b/tests/uninorm/test-u32-nfd.c @@ -103,6 +103,9 @@ void test_u32_nfd (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint32_t input[] = { 0x0020 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
--- a/tests/uninorm/test-u32-nfkc.c +++ b/tests/uninorm/test-u32-nfkc.c @@ -103,6 +103,9 @@ void test_u32_nfkc (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint32_t input[] = { 0x0020 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
--- a/tests/uninorm/test-u32-nfkd.c +++ b/tests/uninorm/test-u32-nfkd.c @@ -103,6 +103,9 @@ void test_u32_nfkd (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint32_t input[] = { 0x0020 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
--- a/tests/uninorm/test-u8-nfc.c +++ b/tests/uninorm/test-u8-nfc.c @@ -103,6 +103,9 @@ void test_u8_nfc (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint8_t input[] = { 0x20 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
--- a/tests/uninorm/test-u8-nfd.c +++ b/tests/uninorm/test-u8-nfd.c @@ -103,6 +103,9 @@ void test_u8_nfd (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint8_t input[] = { 0x20 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
--- a/tests/uninorm/test-u8-nfkc.c +++ b/tests/uninorm/test-u8-nfkc.c @@ -103,6 +103,9 @@ void test_u8_nfkc (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint8_t input[] = { 0x20 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);
--- a/tests/uninorm/test-u8-nfkd.c +++ b/tests/uninorm/test-u8-nfkd.c @@ -103,6 +103,9 @@ void test_u8_nfkd (void) { + { /* Empty string. */ + ASSERT (check (NULL, 0, NULL, 0) == 0); + } { /* SPACE */ static const uint8_t input[] = { 0x20 }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0);