From b8b58262e995555e290b5967057ace3f81e6bede Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 19 Feb 2015 14:29:17 +0200 Subject: [PATCH] shared/gatt-db: Fix zero length realloc gatt_db_attribute_write should not attempt to realloc with zero length since that would cause the data to be freed, instead just skip any operation that could affect the buffer. --- src/shared/gatt-db.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index 3d2e690b6..2a00171cb 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -1551,6 +1551,10 @@ bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset, return true; } + /* Nothing to write just skip */ + if (len == 0) + goto done; + /* For values stored in db allocate on demand */ if (!attrib->value || offset >= attrib->value_len || len > (unsigned) (attrib->value_len - offset)) { @@ -1571,6 +1575,7 @@ bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset, memcpy(&attrib->value[offset], value, len); +done: func(attrib, 0, user_data); return true; -- 2.47.3