Procházet zdrojové kódy

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

Benoit Blanchon před 9 roky
rodič
revize
db9a76f7c6

+ 5 - 0
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
 ------
 

+ 6 - 3
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
 ------------

+ 1 - 1
include/ArduinoJson/DynamicJsonBuffer.hpp

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

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