<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Zephyr JSON - json_obj_encode_buf accesses the wrong address with nested arrays</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/64297/zephyr-json---json_obj_encode_buf-accesses-the-wrong-address-with-nested-arrays</link><description>There was a problem converting the structure to JSON. I have two structures 
 And their description: 
 
 I create a structure and initialize: 
 
 Code for getting JSON: 
 
 
 Using this structure, the json_obj_encode_buf function tries to access an inaccessible</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Jul 2020 08:46:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/64297/zephyr-json---json_obj_encode_buf-accesses-the-wrong-address-with-nested-arrays" /><item><title>RE: Zephyr JSON - json_obj_encode_buf accesses the wrong address with nested arrays</title><link>https://devzone.nordicsemi.com/thread/262132?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 08:46:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ee21134-d9b9-41f0-a408-56e27765a9a6</guid><dc:creator>Yury Morgunov</dc:creator><description>&lt;p&gt;My observations were confirmed when I added 1 to the size of the array. It turns out that +1 gives an additional address offset for addition_array_len. So this will work, but it&amp;#39;s a crutch&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;JSON_OBJ_DESCR_ARRAY(struct test_nested, addition_array, 9+1, addition_array_len, JSON_TOK_NUMBER),&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr JSON - json_obj_encode_buf accesses the wrong address with nested arrays</title><link>https://devzone.nordicsemi.com/thread/262119?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 08:00:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2b12c48-10dd-4047-b3ac-3ead62fc9569</guid><dc:creator>Yury Morgunov</dc:creator><description>&lt;p&gt;After going through the library with the debugger, I saw that addition_array_len was ignored after converting the first element of test_struct.&lt;/p&gt;
&lt;p&gt;Because of this, it turns out that when trying to process test_string2 from the second element of the test_struct array, the program does not refer to the string address, but to addition_array_len. addition_array_len is 5 so the program thinks that the line is at address 5 and breaks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>