bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH 1/2] dfa, etc.: prefer xreallocarray to older name
@ 2021-05-30 17:05 Paul Eggert
  2021-05-30 17:05 ` [PATCH 2/2] reallocarray-tests: port to weird platforms Paul Eggert
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Eggert @ 2021-05-30 17:05 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Paul Eggert

* lib/dfa.c (addtok_mb, realloc_trans_if_necessary, enlist):
* lib/readtokens.c (readtokens):
* tests/uninorm/test-u32-normalize-big.c:
(read_normalization_test_file):
Prefer xreallocarray to the equivalent xnrealloc.
The newer name follows the glibc lead of ‘reallocarray’.
---
 ChangeLog                              | 10 ++++++++++
 lib/dfa.c                              | 14 +++++++-------
 lib/readtokens.c                       |  2 +-
 tests/uninorm/test-u32-normalize-big.c |  8 ++++----
 4 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9b159678a..08f9c7b24 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2021-05-30  Paul Eggert  <eggert@cs.ucla.edu>
+
+	dfa, etc.: prefer xreallocarray to older name
+	* lib/dfa.c (addtok_mb, realloc_trans_if_necessary, enlist):
+	* lib/readtokens.c (readtokens):
+	* tests/uninorm/test-u32-normalize-big.c:
+	(read_normalization_test_file):
+	Prefer xreallocarray to the equivalent xnrealloc.
+	The newer name follows the glibc lead of ‘reallocarray’.
+
 2021-05-30  Bruno Haible  <bruno@clisp.org>
 
 	Write 'LGPLv3+ or GPLv2+' instead of 'LGPLv3+ or GPLv2'.
diff --git a/lib/dfa.c b/lib/dfa.c
index 33de2fb82..5aa4e9913 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -1531,8 +1531,8 @@ addtok_mb (struct dfa *dfa, token t, char mbprop)
       dfa->tokens = xpalloc (dfa->tokens, &dfa->talloc, 1, -1,
                              sizeof *dfa->tokens);
       if (dfa->localeinfo.multibyte)
-        dfa->multibyte_prop = xnrealloc (dfa->multibyte_prop, dfa->talloc,
-                                         sizeof *dfa->multibyte_prop);
+        dfa->multibyte_prop = xreallocarray (dfa->multibyte_prop, dfa->talloc,
+                                             sizeof *dfa->multibyte_prop);
     }
   if (dfa->localeinfo.multibyte)
     dfa->multibyte_prop[dfa->tindex] = mbprop;
@@ -2850,13 +2850,13 @@ realloc_trans_if_necessary (struct dfa *d)
       realtrans[0] = realtrans[1] = NULL;
       d->trans = realtrans + 2;
       idx_t newalloc = d->tralloc = newalloc1 - 2;
-      d->fails = xnrealloc (d->fails, newalloc, sizeof *d->fails);
-      d->success = xnrealloc (d->success, newalloc, sizeof *d->success);
-      d->newlines = xnrealloc (d->newlines, newalloc, sizeof *d->newlines);
+      d->fails = xreallocarray (d->fails, newalloc, sizeof *d->fails);
+      d->success = xreallocarray (d->success, newalloc, sizeof *d->success);
+      d->newlines = xreallocarray (d->newlines, newalloc, sizeof *d->newlines);
       if (d->localeinfo.multibyte)
         {
           realtrans = d->mb_trans ? d->mb_trans - 2 : NULL;
-          realtrans = xnrealloc (realtrans, newalloc1, sizeof *realtrans);
+          realtrans = xreallocarray (realtrans, newalloc1, sizeof *realtrans);
           if (oldalloc == 0)
             realtrans[0] = realtrans[1] = NULL;
           d->mb_trans = realtrans + 2;
@@ -3938,7 +3938,7 @@ enlist (char **cpp, char *new, idx_t len)
         cpp[i] = NULL;
       }
   /* Add the new string.  */
-  cpp = xnrealloc (cpp, i + 2, sizeof *cpp);
+  cpp = xreallocarray (cpp, i + 2, sizeof *cpp);
   cpp[i] = new;
   cpp[i + 1] = NULL;
   return cpp;
diff --git a/lib/readtokens.c b/lib/readtokens.c
index 091882714..2c08283e6 100644
--- a/lib/readtokens.c
+++ b/lib/readtokens.c
@@ -169,7 +169,7 @@ readtokens (FILE *stream,
       if (n_tokens >= sz)
         {
           tokens = x2nrealloc (tokens, &sz, sizeof *tokens);
-          lengths = xnrealloc (lengths, sz, sizeof *lengths);
+          lengths = xreallocarray (lengths, sz, sizeof *lengths);
         }
 
       if (token_length == (size_t) -1)
diff --git a/tests/uninorm/test-u32-normalize-big.c b/tests/uninorm/test-u32-normalize-big.c
index e5bad9aa2..537dcf96e 100644
--- a/tests/uninorm/test-u32-normalize-big.c
+++ b/tests/uninorm/test-u32-normalize-big.c
@@ -118,7 +118,7 @@ read_normalization_test_file (const char *filename,
             {
               lines =
                 (struct normalization_test_line *)
-                xnrealloc (lines, lines_length, sizeof (struct normalization_test_line));
+                xreallocarray (lines, lines_length, sizeof *lines);
               file->parts[part_index].lines = lines;
               file->parts[part_index].lines_length = lines_length;
             }
@@ -158,7 +158,7 @@ read_normalization_test_file (const char *filename,
               /* Append uc to the sequence.  */
               sequence =
                 (uint32_t *)
-                xnrealloc (sequence, sequence_length + 2, sizeof (uint32_t));
+                xreallocarray (sequence, sequence_length + 2, sizeof *sequence);
               sequence[sequence_length] = uc;
               sequence_length++;
 
@@ -190,7 +190,7 @@ read_normalization_test_file (const char *filename,
             lines_allocated = 7;
           lines =
             (struct normalization_test_line *)
-            xnrealloc (lines, lines_allocated, sizeof (struct normalization_test_line));
+            xreallocarray (lines, lines_allocated, sizeof *lines);
         }
       lines[lines_length] = line;
       lines_length++;
@@ -200,7 +200,7 @@ read_normalization_test_file (const char *filename,
     {
       lines =
         (struct normalization_test_line *)
-        xnrealloc (lines, lines_length, sizeof (struct normalization_test_line));
+        xreallocarray (lines, lines_length, sizeof *lines);
       file->parts[part_index].lines = lines;
       file->parts[part_index].lines_length = lines_length;
     }
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] reallocarray-tests: port to weird platforms
  2021-05-30 17:05 [PATCH 1/2] dfa, etc.: prefer xreallocarray to older name Paul Eggert
@ 2021-05-30 17:05 ` Paul Eggert
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Eggert @ 2021-05-30 17:05 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Paul Eggert

* tests/test-reallocarray.c (main): Don’t assume that
PTRDIFF_MAX / 2 + 1 <= SIZE_MAX.  POSIX allows platforms
where this isn’t true, though I don’t know of any examples.
---
 ChangeLog                 | 5 +++++
 tests/test-reallocarray.c | 9 ++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 08f9c7b24..a110970f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2021-05-30  Paul Eggert  <eggert@cs.ucla.edu>
 
+	reallocarray-tests: port to weird platforms
+	* tests/test-reallocarray.c (main): Don’t assume that
+	PTRDIFF_MAX / 2 + 1 <= SIZE_MAX.  POSIX allows platforms
+	where this isn’t true, though I don’t know of any examples.
+
 	dfa, etc.: prefer xreallocarray to older name
 	* lib/dfa.c (addtok_mb, realloc_trans_if_necessary, enlist):
 	* lib/readtokens.c (readtokens):
diff --git a/tests/test-reallocarray.c b/tests/test-reallocarray.c
index f0839ff74..ff90962a9 100644
--- a/tests/test-reallocarray.c
+++ b/tests/test-reallocarray.c
@@ -36,9 +36,12 @@ main ()
     {
       void *volatile p = NULL;
 
-      p = reallocarray (p, PTRDIFF_MAX / n + 1, n);
-      ASSERT (p == NULL);
-      ASSERT (errno == ENOMEM);
+      if (PTRDIFF_MAX / n + 1 <= SIZE_MAX)
+        {
+          p = reallocarray (p, PTRDIFF_MAX / n + 1, n);
+          ASSERT (p == NULL);
+          ASSERT (errno == ENOMEM);
+        }
 
       p = reallocarray (p, SIZE_MAX / n + 1, n);
       ASSERT (p == NULL);
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-30 17:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-30 17:05 [PATCH 1/2] dfa, etc.: prefer xreallocarray to older name Paul Eggert
2021-05-30 17:05 ` [PATCH 2/2] reallocarray-tests: port to weird platforms Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).