emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 2bcf0f0: Improve commentary in 'field_relpos'


From: Eli Zaretskii
Subject: [Emacs-diffs] master 2bcf0f0: Improve commentary in 'field_relpos'
Date: Wed, 3 Apr 2019 13:43:22 -0400 (EDT)

branch: master
commit 2bcf0f097cd6841af5844d3a2a9d670ba4daea99
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Improve commentary in 'field_relpos'
    
    * src/pdumper.c (PDUMPER_MAX_OBJECT_SIZE): New macro.
    (field_relpos): Use PDUMPER_MAX_OBJECT_SIZE, and comment on
    why we require that relpos be not too large.
---
 src/pdumper.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/pdumper.c b/src/pdumper.c
index 7fabfa7..b19f206 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -1777,6 +1777,8 @@ dump_roots (struct dump_context *ctx)
   visit_static_gc_roots (visitor);
 }
 
+#define PDUMPER_MAX_OBJECT_SIZE 2048
+
 static dump_off
 field_relpos (const void *in_start, const void *in_field)
 {
@@ -1784,7 +1786,15 @@ field_relpos (const void *in_start, const void *in_field)
   ptrdiff_t in_field_val = (ptrdiff_t) in_field;
   eassert (in_start_val <= in_field_val);
   ptrdiff_t relpos = in_field_val - in_start_val;
-  eassert (relpos < 1024); /* Sanity check.  */
+  /* The following assertion attempts to detect bugs whereby IN_START
+     and IN_FIELD don't point to the same object/structure, on the
+     assumption that a too-large difference between them is
+     suspicious.  As of Apr 2019 the largest object we dump -- 'struct
+     buffer' -- is slightly smaller than 1KB, and we want to leave
+     some margin for future extensions.  If the assertion below is
+     ever violated, make sure the two pointers indeed point into the
+     same object, and if so, enlarge the value of PDUMPER_MAX_OBJECT_SIZE.  */
+  eassert (relpos < PDUMPER_MAX_OBJECT_SIZE);
   return (dump_off) relpos;
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]