aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2015-07-31 09:55:49 -0700
committerPaul Eggert2015-07-31 10:13:36 -0700
commit0f23e95b29a7a0a07bba0e9bc796cd7b7bc7232a (patch)
treecc081e1fbfeae45269d3a8c64b3be33e4f53fb02 /src
parent8a7a99e0280103e223b8e1a717107bdf9b8eabc7 (diff)
downloademacs-0f23e95b29a7a0a07bba0e9bc796cd7b7bc7232a.tar.gz
emacs-0f23e95b29a7a0a07bba0e9bc796cd7b7bc7232a.zip
Fix some int overflows in profiler.c
* src/profiler.c (make_log): Make args EMACS_INT, not int, to avoid unwanted behavior on 'int' overflow. (make_log, evict_lower_half, record_backtrace): Use ptrdiff_t, not int, for object indexes.
Diffstat (limited to 'src')
-rw-r--r--src/profiler.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/profiler.c b/src/profiler.c
index d4c98a82657..efdb1d9fe14 100644
--- a/src/profiler.c
+++ b/src/profiler.c
@@ -38,7 +38,7 @@ typedef struct Lisp_Hash_Table log_t;
38static struct hash_table_test hashtest_profiler; 38static struct hash_table_test hashtest_profiler;
39 39
40static Lisp_Object 40static Lisp_Object
41make_log (int heap_size, int max_stack_depth) 41make_log (EMACS_INT heap_size, EMACS_INT max_stack_depth)
42{ 42{
43 /* We use a standard Elisp hash-table object, but we use it in 43 /* We use a standard Elisp hash-table object, but we use it in
44 a special way. This is OK as long as the object is not exposed 44 a special way. This is OK as long as the object is not exposed
@@ -53,7 +53,7 @@ make_log (int heap_size, int max_stack_depth)
53 53
54 /* What is special about our hash-tables is that the keys are pre-filled 54 /* What is special about our hash-tables is that the keys are pre-filled
55 with the vectors we'll put in them. */ 55 with the vectors we'll put in them. */
56 int i = ASIZE (h->key_and_value) / 2; 56 ptrdiff_t i = ASIZE (h->key_and_value) >> 1;
57 while (i > 0) 57 while (i > 0)
58 set_hash_key_slot (h, --i, 58 set_hash_key_slot (h, --i,
59 Fmake_vector (make_number (max_stack_depth), Qnil)); 59 Fmake_vector (make_number (max_stack_depth), Qnil));
@@ -120,12 +120,11 @@ static void evict_lower_half (log_t *log)
120 Fremhash (key, tmp); 120 Fremhash (key, tmp);
121 } 121 }
122 eassert (EQ (log->next_free, make_number (i))); 122 eassert (EQ (log->next_free, make_number (i)));
123 { 123
124 int j; 124 eassert (VECTORP (key));
125 eassert (VECTORP (key)); 125 for (ptrdiff_t j = 0; j < ASIZE (key); j++)
126 for (j = 0; j < ASIZE (key); j++) 126 ASET (key, j, Qnil);
127 ASET (key, j, Qnil); 127
128 }
129 set_hash_key_slot (log, i, key); 128 set_hash_key_slot (log, i, key);
130 } 129 }
131} 130}
@@ -165,9 +164,8 @@ record_backtrace (log_t *log, EMACS_INT count)
165 else 164 else
166 { /* BEWARE! hash_put in general can allocate memory. 165 { /* BEWARE! hash_put in general can allocate memory.
167 But currently it only does that if log->next_free is nil. */ 166 But currently it only does that if log->next_free is nil. */
168 int j;
169 eassert (!NILP (log->next_free)); 167 eassert (!NILP (log->next_free));
170 j = hash_put (log, backtrace, make_number (count), hash); 168 ptrdiff_t j = hash_put (log, backtrace, make_number (count), hash);
171 /* Let's make sure we've put `backtrace' right where it 169 /* Let's make sure we've put `backtrace' right where it
172 already was to start with. */ 170 already was to start with. */
173 eassert (index == j); 171 eassert (index == j);