>From 1178f98f2c0973dd1f8a66cbb4de20c0d7af3271 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 13 Jul 2019 10:41:46 -0700 Subject: [PATCH] Avoid interleaving stderr in dump_fingerprint * src/fns.c (hexbuf_digest): New function, containing most of the old make_digest_string. (make_digest_string): Use it. * src/pdumper.c (dump_fingerprint): Rewrite to use a single fprintf call, to avoid interleaving on GNU/Linux. --- src/fns.c | 19 ++++++++++++++----- src/lisp.h | 1 + src/pdumper.c | 13 +++++++------ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/fns.c b/src/fns.c index 6a7c347728..54dafe07ac 100644 --- a/src/fns.c +++ b/src/fns.c @@ -5040,18 +5040,27 @@ returns nil, then (funcall TEST x1 x2) also returns nil. */) #include "sha256.h" #include "sha512.h" -static Lisp_Object -make_digest_string (Lisp_Object digest, int digest_size) +/* Store into HEXBUF an unterminated hexadecimal character string + representing DIGEST, which is binary data of size DIGEST_SIZE bytes. + HEXBUF might equal DIGEST. */ +void +hexbuf_digest (char *hexbuf, void const *digest, int digest_size) { - unsigned char *p = SDATA (digest); + unsigned char const *p = digest; for (int i = digest_size - 1; i >= 0; i--) { static char const hexdigit[16] = "0123456789abcdef"; int p_i = p[i]; - p[2 * i] = hexdigit[p_i >> 4]; - p[2 * i + 1] = hexdigit[p_i & 0xf]; + hexbuf[2 * i] = hexdigit[p_i >> 4]; + hexbuf[2 * i + 1] = hexdigit[p_i & 0xf]; } +} + +static Lisp_Object +make_digest_string (Lisp_Object digest, int digest_size) +{ + hexbuf_digest (SSDATA (digest), SDATA (digest), digest_size); return digest; } diff --git a/src/lisp.h b/src/lisp.h index e93a219625..4885e26e3f 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3586,6 +3586,7 @@ extern ptrdiff_t list_length (Lisp_Object); extern EMACS_INT next_almost_prime (EMACS_INT) ATTRIBUTE_CONST; extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t); extern bool sweep_weak_table (struct Lisp_Hash_Table *, bool); +extern void hexbuf_digest (char *, void const *, int); extern char *extract_data_from_object (Lisp_Object, ptrdiff_t *, ptrdiff_t *); EMACS_UINT hash_string (char const *, ptrdiff_t); EMACS_UINT sxhash (Lisp_Object, int); diff --git a/src/pdumper.c b/src/pdumper.c index b80757c207..03c00bf27b 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -324,12 +324,13 @@ dump_reloc_set_offset (struct dump_reloc *reloc, dump_off offset) } static void -dump_fingerprint (const char *label, unsigned char const *xfingerprint) +dump_fingerprint (char const *label, + unsigned char const xfingerprint[sizeof fingerprint]) { - fprintf (stderr, "%s: ", label); - for (int i = 0; i < 32; ++i) - fprintf (stderr, "%02x", (unsigned) xfingerprint[i]); - putc ('\n', stderr); + enum { hexbuf_size = 2 * sizeof fingerprint }; + char hexbuf[hexbuf_size]; + hexbuf_digest (hexbuf, xfingerprint, sizeof fingerprint); + fprintf (stderr, "%s: %.*s\n", label, hexbuf_size, hexbuf); } /* Format of an Emacs portable dump file. All offsets are relative to @@ -355,7 +356,7 @@ struct dump_header char magic[sizeof (dump_magic)]; /* Associated Emacs binary. */ - unsigned char fingerprint[32]; + unsigned char fingerprint[sizeof fingerprint]; /* Relocation table for the dump file; each entry is a struct dump_reloc. */ -- 2.17.1