Fixed an access violation in DynamicJsonBuffer when memory allocation fails (issue #433)

This commit is contained in:
Benoit Blanchon
2017-01-31 10:06:40 +01:00
parent 3fd87e8e82
commit db9a76f7c6
4 changed files with 18 additions and 4 deletions

View File

@ -1,6 +1,11 @@
ArduinoJson: change log
=======================
HEAD
----
* Fixed an access violation in `DynamicJsonBuffer` when memory allocation fails (issue #433)
v5.8.2
------

View File

@ -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
------------

View File

@ -84,7 +84,7 @@ class DynamicJsonBufferBase
char* newStart =
static_cast<char*>(_parent->allocInNewBlock(_length + 1));
if (_start && newStart) memcpy(newStart, _start, _length);
newStart[_length] = c;
if (newStart) newStart[_length] = c;
_start = newStart;
}
_length++;

View File

@ -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<NoMemoryAllocator>::String str = _jsonBuffer.startString();
str.append('!');
ASSERT_EQ(NULL, str.c_str());
}