]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid interleaving stderr in dump_fingerprint
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 13 Jul 2019 17:41:46 +0000 (10:41 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 13 Jul 2019 23:53:21 +0000 (16:53 -0700)
* 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
src/lisp.h
src/pdumper.c

index 6a7c3477282c2463e25eaed6531fdafe49517f5a..54dafe07ac80f690bf18c57df33085854ed73a9c 100644 (file)
--- 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;
 }
 
index e93a219625efcffae62911688fb7b7727571e12a..4885e26e3f3424692bd1bc2dcfaea50ac5e8b907 100644 (file)
@@ -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);
index b80757c20712626d56c414f3c84e51671c34b2a4..03c00bf27b7c3f814398bb5626cc07b13f360f19 100644 (file)
@@ -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.  */