summaryrefslogtreecommitdiff
path: root/src/print.c
diff options
context:
space:
mode:
authorPip Cet <pipcet@gmail.com>2020-09-20 12:24:16 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-09-20 12:24:16 +0200
commit988f45a75b745dc1fee6315749ddb48f00b000eb (patch)
tree884678ac47045bf2c64fda56eaee7fe90b0cae9e /src/print.c
parent23c20c39683766525d17da52482dfad85b943f48 (diff)
downloademacs-988f45a75b745dc1fee6315749ddb48f00b000eb.tar.gz
Fix printing of hash tables with removed elements
* src/print.c (print_vectorlike): Keep track of the actual number of elements printed rather than attempting to use hash bucket indices (bug#38892).
Diffstat (limited to 'src/print.c')
-rw-r--r--src/print.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/print.c b/src/print.c
index bd1769144e0..0ecc98f37bf 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1590,27 +1590,34 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag,
/* Print the data here as a plist. */
ptrdiff_t real_size = HASH_TABLE_SIZE (h);
- ptrdiff_t size = real_size;
+ ptrdiff_t size = h->count;
/* Don't print more elements than the specified maximum. */
if (FIXNATP (Vprint_length) && XFIXNAT (Vprint_length) < size)
size = XFIXNAT (Vprint_length);
printchar ('(', printcharfun);
- for (ptrdiff_t i = 0; i < size; i++)
+ ptrdiff_t j = 0;
+ for (ptrdiff_t i = 0; i < real_size; i++)
{
Lisp_Object key = HASH_KEY (h, i);
if (!EQ (key, Qunbound))
{
- if (i) printchar (' ', printcharfun);
+ if (j++) printchar (' ', printcharfun);
print_object (key, printcharfun, escapeflag);
printchar (' ', printcharfun);
print_object (HASH_VALUE (h, i), printcharfun, escapeflag);
+ if (j == size)
+ break;
}
}
- if (size < real_size)
- print_c_string (" ...", printcharfun);
+ if (j < h->count)
+ {
+ if (j)
+ printchar (' ', printcharfun);
+ print_c_string ("...", printcharfun);
+ }
print_c_string ("))", printcharfun);
}