MT#55283 add bencode_buffer_contains

Quick and unreliable test to see whether something is an allocation from
the buffer.

Change-Id: Ibbede22b3d6465db171cba55328b3625ed4c962d
rfuchs/test
Richard Fuchs 1 year ago
parent 2a14ce2f56
commit 695f05fe91

@ -134,6 +134,11 @@ alloc:
return ret;
}
bool bencode_buffer_contains(bencode_buffer_t *buf, const void *ptr) {
struct __bencode_buffer_piece *piece = buf->pieces;
return (ptr >= (void *) piece->buf && ptr < (void *) piece->tail);
}
void bencode_buffer_free(bencode_buffer_t *buf) {
struct __bencode_buffer_piece *piece, *next;

@ -65,6 +65,9 @@ int bencode_buffer_init(bencode_buffer_t *buf);
/* Allocate a piece of memory from the given buffer object */
void *bencode_buffer_alloc(bencode_buffer_t *, size_t);
// quick and non-reliable check whether the given pointer is from the buffer
bool bencode_buffer_contains(bencode_buffer_t *, const void *);
/* Destroys a previously initialized bencode_buffer_t object. All memory used by the object is freed
* and all objects created through it become invalid. */
void bencode_buffer_free(bencode_buffer_t *buf);

Loading…
Cancel
Save