From b4e50fa0d03ebc4a71f4d0057495ac2b8c391429 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 18 Jun 2011 08:57:22 -0700 Subject: [PATCH] * fns.c (Ffillarray): Don't assume bool vector size fits in 'int'. --- src/ChangeLog | 2 ++ src/fns.c | 18 ++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 80626bc0c2a..c47a6402e81 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-06-18 Paul Eggert + * fns.c (Ffillarray): Don't assume bool vector size fits in 'int'. + * alloc.c (Fmake_bool_vector): Avoid unnecessary multiplication. * fns.c (concat): Catch string overflow earlier. diff --git a/src/fns.c b/src/fns.c index 4c1505ab0f1..7b303ff3836 100644 --- a/src/fns.c +++ b/src/fns.c @@ -2188,19 +2188,17 @@ ARRAY is a vector, string, char-table, or bool-vector. */) else if (BOOL_VECTOR_P (array)) { register unsigned char *p = XBOOL_VECTOR (array)->data; - int size_in_chars - = ((XBOOL_VECTOR (array)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) + EMACS_INT size = XBOOL_VECTOR (array)->size; + EMACS_INT size_in_chars + = ((size + BOOL_VECTOR_BITS_PER_CHAR - 1) / BOOL_VECTOR_BITS_PER_CHAR); - charval = (! NILP (item) ? -1 : 0); - for (idx = 0; idx < size_in_chars - 1; idx++) - p[idx] = charval; - if (idx < size_in_chars) + if (size_in_chars) { - /* Mask out bits beyond the vector size. */ - if (XBOOL_VECTOR (array)->size % BOOL_VECTOR_BITS_PER_CHAR) - charval &= (1 << (XBOOL_VECTOR (array)->size % BOOL_VECTOR_BITS_PER_CHAR)) - 1; - p[idx] = charval; + memset (p, ! NILP (item) ? -1 : 0, size_in_chars); + + /* Clear any extraneous bits in the last byte. */ + p[size_in_chars - 1] &= (1 << (size % BOOL_VECTOR_BITS_PER_CHAR)) - 1; } } else -- 2.39.2