From db9a76f7c60c98b1e0e18fca5673eafef56c8797 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Tue, 31 Jan 2017 10:06:40 +0100 Subject: [PATCH] Fixed an access violation in `DynamicJsonBuffer` when memory allocation fails (issue #433) --- CHANGELOG.md | 5 +++++ README.md | 9 ++++++--- include/ArduinoJson/DynamicJsonBuffer.hpp | 2 +- test/DynamicJsonBuffer_NoMemory_Tests.cpp | 6 ++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ef4932b..f90f60f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Fixed an access violation in `DynamicJsonBuffer` when memory allocation fails (issue #433) + v5.8.2 ------ diff --git a/README.md b/README.md index c1581479..7f936957 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Arduino JSON library +ArduinoJson - C++ JSON library for IoT ==================== [![Build status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/master?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/master) [![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=master)](https://travis-ci.org/bblanchon/ArduinoJson) [![Coverage Status](https://img.shields.io/coveralls/bblanchon/ArduinoJson.svg)](https://coveralls.io/r/bblanchon/ArduinoJson?branch=master) [![Star this project](http://githubbadges.com/star.svg?user=bblanchon&repo=ArduinoJson&style=flat&color=fff&background=007ec6)](https://github.com/bblanchon/ArduinoJson) @@ -36,7 +36,7 @@ Works on * RedBearLab boards (BLE Nano...) * Computers (Windows, Linux, OSX...) -See [FAQ: Compatibility issues](https://github.com/bblanchon/ArduinoJson/wiki/Compatibility-issues) +See [FAQ: Compatibility issues](https://bblanchon.github.io/ArduinoJson/faq/compilation-fails-device-crashes-nothing-on-serial-console) Quick start ----------- @@ -82,7 +82,10 @@ root.printTo(Serial); Documentation ------------- -The documentation is available online in the [Arduino JSON wiki](https://github.com/bblanchon/ArduinoJson/wiki) +The documentation is available online in the [ArduinoJson wiki](https://github.com/bblanchon/ArduinoJson/wiki). + +The [ArduinoJson Assistant](https://bblanchon.github.io/ArduinoJson/assistant/) helps you get started with the library. + Testimonials ------------ diff --git a/include/ArduinoJson/DynamicJsonBuffer.hpp b/include/ArduinoJson/DynamicJsonBuffer.hpp index 0b2b783b..64de7f03 100644 --- a/include/ArduinoJson/DynamicJsonBuffer.hpp +++ b/include/ArduinoJson/DynamicJsonBuffer.hpp @@ -84,7 +84,7 @@ class DynamicJsonBufferBase char* newStart = static_cast(_parent->allocInNewBlock(_length + 1)); if (_start && newStart) memcpy(newStart, _start, _length); - newStart[_length] = c; + if (newStart) newStart[_length] = c; _start = newStart; } _length++; diff --git a/test/DynamicJsonBuffer_NoMemory_Tests.cpp b/test/DynamicJsonBuffer_NoMemory_Tests.cpp index 398d8da4..92835144 100644 --- a/test/DynamicJsonBuffer_NoMemory_Tests.cpp +++ b/test/DynamicJsonBuffer_NoMemory_Tests.cpp @@ -43,3 +43,9 @@ TEST_F(DynamicJsonBuffer_NoMemory_Tests, ParseObject) { char json[] = "{}"; ASSERT_FALSE(_jsonBuffer.parseObject(json).success()); } + +TEST_F(DynamicJsonBuffer_NoMemory_Tests, String) { + DynamicJsonBufferBase::String str = _jsonBuffer.startString(); + str.append('!'); + ASSERT_EQ(NULL, str.c_str()); +}