diff options
| author | Dmitry Antipov | 2012-08-08 09:23:02 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2012-08-08 09:23:02 +0400 |
| commit | 9c08a8d4b549df18f815412d2a5494d28253179f (patch) | |
| tree | 0d42c53782a8fa40b1d5a21e575d3736f8427108 /src | |
| parent | 2c2d9c9cd0a409778ebc3618888fc9795c2a9135 (diff) | |
| download | emacs-9c08a8d4b549df18f815412d2a5494d28253179f.tar.gz emacs-9c08a8d4b549df18f815412d2a5494d28253179f.zip | |
Check total length of intervals with eassert.
* intervals.h (CHECK_TOTAL_LENGTH): Remove.
* intervals.c: Change all users to eassert.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/intervals.c | 54 | ||||
| -rw-r--r-- | src/intervals.h | 9 |
3 files changed, 33 insertions, 36 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 016d2561cde..7c49694dd44 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2012-08-08 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 2 | |||
| 3 | Check total length of intervals with eassert. | ||
| 4 | * intervals.h (CHECK_TOTAL_LENGTH): Remove. | ||
| 5 | * intervals.c: Change all users to eassert. | ||
| 6 | |||
| 1 | 2012-08-07 Eli Zaretskii <eliz@gnu.org> | 7 | 2012-08-07 Eli Zaretskii <eliz@gnu.org> |
| 2 | 8 | ||
| 3 | * .gdbinit (xframe, xwindow, nextcons, xcar, xcdr, xlist): Rename | 9 | * .gdbinit (xframe, xwindow, nextcons, xcar, xcdr, xlist): Rename |
diff --git a/src/intervals.c b/src/intervals.c index cde4dd89d0b..40f77f3957a 100644 --- a/src/intervals.c +++ b/src/intervals.c | |||
| @@ -76,14 +76,14 @@ create_root_interval (Lisp_Object parent) | |||
| 76 | { | 76 | { |
| 77 | new->total_length = (BUF_Z (XBUFFER (parent)) | 77 | new->total_length = (BUF_Z (XBUFFER (parent)) |
| 78 | - BUF_BEG (XBUFFER (parent))); | 78 | - BUF_BEG (XBUFFER (parent))); |
| 79 | CHECK_TOTAL_LENGTH (new); | 79 | eassert (0 <= TOTAL_LENGTH (new)); |
| 80 | BUF_INTERVALS (XBUFFER (parent)) = new; | 80 | BUF_INTERVALS (XBUFFER (parent)) = new; |
| 81 | new->position = BEG; | 81 | new->position = BEG; |
| 82 | } | 82 | } |
| 83 | else if (STRINGP (parent)) | 83 | else if (STRINGP (parent)) |
| 84 | { | 84 | { |
| 85 | new->total_length = SCHARS (parent); | 85 | new->total_length = SCHARS (parent); |
| 86 | CHECK_TOTAL_LENGTH (new); | 86 | eassert (0 <= TOTAL_LENGTH (new)); |
| 87 | STRING_SET_INTERVALS (parent, new); | 87 | STRING_SET_INTERVALS (parent, new); |
| 88 | new->position = 0; | 88 | new->position = 0; |
| 89 | } | 89 | } |
| @@ -338,11 +338,11 @@ rotate_right (INTERVAL interval) | |||
| 338 | 338 | ||
| 339 | /* A's total length is decreased by the length of B and its left child. */ | 339 | /* A's total length is decreased by the length of B and its left child. */ |
| 340 | interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval); | 340 | interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval); |
| 341 | CHECK_TOTAL_LENGTH (interval); | 341 | eassert (0 <= TOTAL_LENGTH (interval)); |
| 342 | 342 | ||
| 343 | /* B must have the same total length of A. */ | 343 | /* B must have the same total length of A. */ |
| 344 | B->total_length = old_total; | 344 | B->total_length = old_total; |
| 345 | CHECK_TOTAL_LENGTH (B); | 345 | eassert (0 <= TOTAL_LENGTH (B)); |
| 346 | 346 | ||
| 347 | return B; | 347 | return B; |
| 348 | } | 348 | } |
| @@ -385,11 +385,11 @@ rotate_left (INTERVAL interval) | |||
| 385 | 385 | ||
| 386 | /* A's total length is decreased by the length of B and its right child. */ | 386 | /* A's total length is decreased by the length of B and its right child. */ |
| 387 | interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval); | 387 | interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval); |
| 388 | CHECK_TOTAL_LENGTH (interval); | 388 | eassert (0 <= TOTAL_LENGTH (interval)); |
| 389 | 389 | ||
| 390 | /* B must have the same total length of A. */ | 390 | /* B must have the same total length of A. */ |
| 391 | B->total_length = old_total; | 391 | B->total_length = old_total; |
| 392 | CHECK_TOTAL_LENGTH (B); | 392 | eassert (0 <= TOTAL_LENGTH (B)); |
| 393 | 393 | ||
| 394 | return B; | 394 | return B; |
| 395 | } | 395 | } |
| @@ -513,7 +513,7 @@ split_interval_right (INTERVAL interval, ptrdiff_t offset) | |||
| 513 | { | 513 | { |
| 514 | interval_set_right (interval, new); | 514 | interval_set_right (interval, new); |
| 515 | new->total_length = new_length; | 515 | new->total_length = new_length; |
| 516 | CHECK_TOTAL_LENGTH (new); | 516 | eassert (0 <= TOTAL_LENGTH (new)); |
| 517 | } | 517 | } |
| 518 | else | 518 | else |
| 519 | { | 519 | { |
| @@ -522,7 +522,7 @@ split_interval_right (INTERVAL interval, ptrdiff_t offset) | |||
| 522 | interval_set_parent (interval->right, new); | 522 | interval_set_parent (interval->right, new); |
| 523 | interval_set_right (interval, new); | 523 | interval_set_right (interval, new); |
| 524 | new->total_length = new_length + new->right->total_length; | 524 | new->total_length = new_length + new->right->total_length; |
| 525 | CHECK_TOTAL_LENGTH (new); | 525 | eassert (0 <= TOTAL_LENGTH (new)); |
| 526 | balance_an_interval (new); | 526 | balance_an_interval (new); |
| 527 | } | 527 | } |
| 528 | 528 | ||
| @@ -558,7 +558,7 @@ split_interval_left (INTERVAL interval, ptrdiff_t offset) | |||
| 558 | { | 558 | { |
| 559 | interval_set_left (interval, new); | 559 | interval_set_left (interval, new); |
| 560 | new->total_length = new_length; | 560 | new->total_length = new_length; |
| 561 | CHECK_TOTAL_LENGTH (new); | 561 | eassert (0 <= TOTAL_LENGTH (new)); |
| 562 | } | 562 | } |
| 563 | else | 563 | else |
| 564 | { | 564 | { |
| @@ -567,7 +567,7 @@ split_interval_left (INTERVAL interval, ptrdiff_t offset) | |||
| 567 | interval_set_parent (new->left, new); | 567 | interval_set_parent (new->left, new); |
| 568 | interval_set_left (interval, new); | 568 | interval_set_left (interval, new); |
| 569 | new->total_length = new_length + new->left->total_length; | 569 | new->total_length = new_length + new->left->total_length; |
| 570 | CHECK_TOTAL_LENGTH (new); | 570 | eassert (0 <= TOTAL_LENGTH (new)); |
| 571 | balance_an_interval (new); | 571 | balance_an_interval (new); |
| 572 | } | 572 | } |
| 573 | 573 | ||
| @@ -918,7 +918,7 @@ adjust_intervals_for_insertion (INTERVAL tree, | |||
| 918 | for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) | 918 | for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) |
| 919 | { | 919 | { |
| 920 | temp->total_length += length; | 920 | temp->total_length += length; |
| 921 | CHECK_TOTAL_LENGTH (temp); | 921 | eassert (0 <= TOTAL_LENGTH (temp)); |
| 922 | temp = balance_possible_root_interval (temp); | 922 | temp = balance_possible_root_interval (temp); |
| 923 | } | 923 | } |
| 924 | 924 | ||
| @@ -975,7 +975,7 @@ adjust_intervals_for_insertion (INTERVAL tree, | |||
| 975 | for (temp = i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) | 975 | for (temp = i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) |
| 976 | { | 976 | { |
| 977 | temp->total_length += length; | 977 | temp->total_length += length; |
| 978 | CHECK_TOTAL_LENGTH (temp); | 978 | eassert (0 <= TOTAL_LENGTH (temp)); |
| 979 | temp = balance_possible_root_interval (temp); | 979 | temp = balance_possible_root_interval (temp); |
| 980 | } | 980 | } |
| 981 | } | 981 | } |
| @@ -1178,7 +1178,7 @@ delete_node (register INTERVAL i) | |||
| 1178 | this = this->left; | 1178 | this = this->left; |
| 1179 | this->total_length += migrate_amt; | 1179 | this->total_length += migrate_amt; |
| 1180 | } | 1180 | } |
| 1181 | CHECK_TOTAL_LENGTH (this); | 1181 | eassert (0 <= TOTAL_LENGTH (this)); |
| 1182 | interval_set_left (this, migrate); | 1182 | interval_set_left (this, migrate); |
| 1183 | interval_set_parent (migrate, this); | 1183 | interval_set_parent (migrate, this); |
| 1184 | 1184 | ||
| @@ -1260,7 +1260,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from, | |||
| 1260 | relative_position, | 1260 | relative_position, |
| 1261 | amount); | 1261 | amount); |
| 1262 | tree->total_length -= subtract; | 1262 | tree->total_length -= subtract; |
| 1263 | CHECK_TOTAL_LENGTH (tree); | 1263 | eassert (0 <= TOTAL_LENGTH (tree)); |
| 1264 | return subtract; | 1264 | return subtract; |
| 1265 | } | 1265 | } |
| 1266 | /* Right branch. */ | 1266 | /* Right branch. */ |
| @@ -1275,7 +1275,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from, | |||
| 1275 | relative_position, | 1275 | relative_position, |
| 1276 | amount); | 1276 | amount); |
| 1277 | tree->total_length -= subtract; | 1277 | tree->total_length -= subtract; |
| 1278 | CHECK_TOTAL_LENGTH (tree); | 1278 | eassert (0 <= TOTAL_LENGTH (tree)); |
| 1279 | return subtract; | 1279 | return subtract; |
| 1280 | } | 1280 | } |
| 1281 | /* Here -- this node. */ | 1281 | /* Here -- this node. */ |
| @@ -1290,7 +1290,7 @@ interval_deletion_adjustment (register INTERVAL tree, register ptrdiff_t from, | |||
| 1290 | amount = my_amount; | 1290 | amount = my_amount; |
| 1291 | 1291 | ||
| 1292 | tree->total_length -= amount; | 1292 | tree->total_length -= amount; |
| 1293 | CHECK_TOTAL_LENGTH (tree); | 1293 | eassert (0 <= TOTAL_LENGTH (tree)); |
| 1294 | if (LENGTH (tree) == 0) | 1294 | if (LENGTH (tree) == 0) |
| 1295 | delete_interval (tree); | 1295 | delete_interval (tree); |
| 1296 | 1296 | ||
| @@ -1332,7 +1332,7 @@ adjust_intervals_for_deletion (struct buffer *buffer, | |||
| 1332 | if (ONLY_INTERVAL_P (tree)) | 1332 | if (ONLY_INTERVAL_P (tree)) |
| 1333 | { | 1333 | { |
| 1334 | tree->total_length -= length; | 1334 | tree->total_length -= length; |
| 1335 | CHECK_TOTAL_LENGTH (tree); | 1335 | eassert (0 <= TOTAL_LENGTH (tree)); |
| 1336 | return; | 1336 | return; |
| 1337 | } | 1337 | } |
| 1338 | 1338 | ||
| @@ -1398,19 +1398,19 @@ merge_interval_right (register INTERVAL i) | |||
| 1398 | while (! NULL_LEFT_CHILD (successor)) | 1398 | while (! NULL_LEFT_CHILD (successor)) |
| 1399 | { | 1399 | { |
| 1400 | successor->total_length += absorb; | 1400 | successor->total_length += absorb; |
| 1401 | CHECK_TOTAL_LENGTH (successor); | 1401 | eassert (0 <= TOTAL_LENGTH (successor)); |
| 1402 | successor = successor->left; | 1402 | successor = successor->left; |
| 1403 | } | 1403 | } |
| 1404 | 1404 | ||
| 1405 | successor->total_length += absorb; | 1405 | successor->total_length += absorb; |
| 1406 | CHECK_TOTAL_LENGTH (successor); | 1406 | eassert (0 <= TOTAL_LENGTH (successor)); |
| 1407 | delete_interval (i); | 1407 | delete_interval (i); |
| 1408 | return successor; | 1408 | return successor; |
| 1409 | } | 1409 | } |
| 1410 | 1410 | ||
| 1411 | /* Zero out this interval. */ | 1411 | /* Zero out this interval. */ |
| 1412 | i->total_length -= absorb; | 1412 | i->total_length -= absorb; |
| 1413 | CHECK_TOTAL_LENGTH (i); | 1413 | eassert (0 <= TOTAL_LENGTH (i)); |
| 1414 | 1414 | ||
| 1415 | successor = i; | 1415 | successor = i; |
| 1416 | while (! NULL_PARENT (successor)) /* It's above us. Subtract as | 1416 | while (! NULL_PARENT (successor)) /* It's above us. Subtract as |
| @@ -1425,7 +1425,7 @@ merge_interval_right (register INTERVAL i) | |||
| 1425 | 1425 | ||
| 1426 | successor = INTERVAL_PARENT (successor); | 1426 | successor = INTERVAL_PARENT (successor); |
| 1427 | successor->total_length -= absorb; | 1427 | successor->total_length -= absorb; |
| 1428 | CHECK_TOTAL_LENGTH (successor); | 1428 | eassert (0 <= TOTAL_LENGTH (successor)); |
| 1429 | } | 1429 | } |
| 1430 | 1430 | ||
| 1431 | /* This must be the rightmost or last interval and cannot | 1431 | /* This must be the rightmost or last interval and cannot |
| @@ -1454,19 +1454,19 @@ merge_interval_left (register INTERVAL i) | |||
| 1454 | while (! NULL_RIGHT_CHILD (predecessor)) | 1454 | while (! NULL_RIGHT_CHILD (predecessor)) |
| 1455 | { | 1455 | { |
| 1456 | predecessor->total_length += absorb; | 1456 | predecessor->total_length += absorb; |
| 1457 | CHECK_TOTAL_LENGTH (predecessor); | 1457 | eassert (0 <= TOTAL_LENGTH (predecessor)); |
| 1458 | predecessor = predecessor->right; | 1458 | predecessor = predecessor->right; |
| 1459 | } | 1459 | } |
| 1460 | 1460 | ||
| 1461 | predecessor->total_length += absorb; | 1461 | predecessor->total_length += absorb; |
| 1462 | CHECK_TOTAL_LENGTH (predecessor); | 1462 | eassert (0 <= TOTAL_LENGTH (predecessor)); |
| 1463 | delete_interval (i); | 1463 | delete_interval (i); |
| 1464 | return predecessor; | 1464 | return predecessor; |
| 1465 | } | 1465 | } |
| 1466 | 1466 | ||
| 1467 | /* Zero out this interval. */ | 1467 | /* Zero out this interval. */ |
| 1468 | i->total_length -= absorb; | 1468 | i->total_length -= absorb; |
| 1469 | CHECK_TOTAL_LENGTH (i); | 1469 | eassert (0 <= TOTAL_LENGTH (i)); |
| 1470 | 1470 | ||
| 1471 | predecessor = i; | 1471 | predecessor = i; |
| 1472 | while (! NULL_PARENT (predecessor)) /* It's above us. Go up, | 1472 | while (! NULL_PARENT (predecessor)) /* It's above us. Go up, |
| @@ -1481,7 +1481,7 @@ merge_interval_left (register INTERVAL i) | |||
| 1481 | 1481 | ||
| 1482 | predecessor = INTERVAL_PARENT (predecessor); | 1482 | predecessor = INTERVAL_PARENT (predecessor); |
| 1483 | predecessor->total_length -= absorb; | 1483 | predecessor->total_length -= absorb; |
| 1484 | CHECK_TOTAL_LENGTH (predecessor); | 1484 | eassert (0 <= TOTAL_LENGTH (predecessor)); |
| 1485 | } | 1485 | } |
| 1486 | 1486 | ||
| 1487 | /* This must be the leftmost or first interval and cannot | 1487 | /* This must be the leftmost or first interval and cannot |
| @@ -2235,7 +2235,7 @@ copy_intervals (INTERVAL tree, ptrdiff_t start, ptrdiff_t length) | |||
| 2235 | new->position = 0; | 2235 | new->position = 0; |
| 2236 | got = (LENGTH (i) - (start - i->position)); | 2236 | got = (LENGTH (i) - (start - i->position)); |
| 2237 | new->total_length = length; | 2237 | new->total_length = length; |
| 2238 | CHECK_TOTAL_LENGTH (new); | 2238 | eassert (0 <= TOTAL_LENGTH (new)); |
| 2239 | copy_properties (i, new); | 2239 | copy_properties (i, new); |
| 2240 | 2240 | ||
| 2241 | t = new; | 2241 | t = new; |
| @@ -2318,7 +2318,7 @@ set_intervals_multibyte_1 (INTERVAL i, int multi_flag, | |||
| 2318 | i->total_length = end - start; | 2318 | i->total_length = end - start; |
| 2319 | else | 2319 | else |
| 2320 | i->total_length = end_byte - start_byte; | 2320 | i->total_length = end_byte - start_byte; |
| 2321 | CHECK_TOTAL_LENGTH (i); | 2321 | eassert (0 <= TOTAL_LENGTH (i)); |
| 2322 | 2322 | ||
| 2323 | if (TOTAL_LENGTH (i) == 0) | 2323 | if (TOTAL_LENGTH (i) == 0) |
| 2324 | { | 2324 | { |
diff --git a/src/intervals.h b/src/intervals.h index 2bf16d64862..fa9fe8d6fdb 100644 --- a/src/intervals.h +++ b/src/intervals.h | |||
| @@ -191,15 +191,6 @@ interval_copy_parent (INTERVAL d, INTERVAL s) | |||
| 191 | #define INTERVAL_PARENT_OR_NULL(i) \ | 191 | #define INTERVAL_PARENT_OR_NULL(i) \ |
| 192 | (INTERVAL_HAS_PARENT (i) ? INTERVAL_PARENT (i) : 0) | 192 | (INTERVAL_HAS_PARENT (i) ? INTERVAL_PARENT (i) : 0) |
| 193 | 193 | ||
| 194 | /* Abort if interval I's size is negative. */ | ||
| 195 | #define CHECK_TOTAL_LENGTH(i) \ | ||
| 196 | do \ | ||
| 197 | { \ | ||
| 198 | if ((i)->total_length < 0) \ | ||
| 199 | abort (); \ | ||
| 200 | } \ | ||
| 201 | while (0) | ||
| 202 | |||
| 203 | /* Reset this interval to its vanilla, or no-property state. */ | 194 | /* Reset this interval to its vanilla, or no-property state. */ |
| 204 | #define RESET_INTERVAL(i) \ | 195 | #define RESET_INTERVAL(i) \ |
| 205 | { \ | 196 | { \ |