History

Print bound region when bound checking error occurs

herman ten brugge committed 2 years ago

Commit f0cd0fb1 parent 233e22f2 files · +10 −8Browse files

Unified · Split

2 files
  1. lib/bcheck.c +9 −7
  2. tests/tests2/126_bound_global.expect +1 −1
lib/bcheck.c+9−7
@@ -559,7 +559,9 @@ void * __bound_ptr_add(void *p, size_t offset) · 558 unmodified lines
559559 if (tree->is_invalid || addr + offset > tree->size) {
560560 POST_SEM ();
561561 if (print_warn_ptr_add)
562− bound_warning("%p is outside of the region", p + offset);
562+ bound_warning("%p is outside of the region (0x%lx..0x%lx)",
563+ p + offset, (long)tree->start,
564+ (long)(tree->start + tree->size - 1));
563565 if (never_fatal <= 0)
564566 return INVALID_POINTER; /* return an invalid pointer */
565567 return p + offset;
@@ -605,7 +607,9 @@ void * __bound_ptr_indir ## dsize (void *p, size_t offset) \ · 39 unmodified lines
605607 if (addr <= tree->size) { \
606608 if (tree->is_invalid || addr + offset + dsize > tree->size) { \
607609 POST_SEM (); \
608− bound_warning("%p is outside of the region", p + offset); \
610+ bound_warning("%p is outside of the region (0x%lx..0x%lx)", \
611+ p + offset, (long)tree->start, \
612+ (long)(tree->start + tree->size - 1)); \
609613 if (never_fatal <= 0) \
610614 return INVALID_POINTER; /* return an invalid pointer */ \
611615 return p + offset; \
@@ -1105,11 +1109,9 @@ add_bounds: · 493 unmodified lines
11051109 while (p[0] != 0) {
11061110 tree = splay_insert(p[0], p[1], tree);
11071111 #if BOUND_DEBUG
1108− if (print_calls) {
1109− dprintf(stderr, "%s, %s(): static var %p 0x%lx\n",
1110− __FILE__, __FUNCTION__,
1111− (void *) p[0], (unsigned long) p[1]);
1112− }
1112+ dprintf(stderr, "%s, %s(): static var %p 0x%lx\n",
1113+ __FILE__, __FUNCTION__,
1114+ (void *) p[0], (unsigned long) p[1]);
11131115 #endif
11141116 p += 2;
11151117 }
tests/tests2/126_bound_global.expect+1−1
@@ -1,2 +1,2 @@
1−126_bound_global.c:11: at main: BCHECK: ........ is outside of the region
1+126_bound_global.c:11: at main: BCHECK: ........ is outside of the region (..................)
22 126_bound_global.c:11: at main: RUNTIME ERROR: invalid memory access

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t