<?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>Why was a malloc with heap_size = 0 successful?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/24441/why-was-a-malloc-with-heap_size-0-successful</link><description>We started with the default project that have no heap.
Added mallocs to the system and they seemed to succeed, without realizing heap was set to 0. They did not return NULL. 
 I would have expected the mallocs to fail since there is no heap at all.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 18 Aug 2017 08:54:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/24441/why-was-a-malloc-with-heap_size-0-successful" /><item><title>RE: Why was a malloc with heap_size = 0 successful?</title><link>https://devzone.nordicsemi.com/thread/96240?ContentTypeID=1</link><pubDate>Fri, 18 Aug 2017 08:54:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f66e3f6f-0802-4a2d-b939-230086f55aa6</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi!
The mem-manager has checks for &amp;gt; 0 &amp;amp;&amp;amp; &amp;lt; max_block_size:
&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.0.0/lib_mem_manager.html?cp=4_0_0_3_26"&gt;infocenter.nordicsemi.com/.../lib_mem_manager.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We tend to avoid dynamic memory allocation, unless absolutely needed, as there are many &amp;quot;gotcha&amp;#39;s&amp;quot; with it, like memory fragmentation etc. Unfortunately, I have little to no experience with dynamic allocation on embedded platforms, so I cannot give a recommendation on which library you should use.&lt;/p&gt;
&lt;p&gt;Cheers,
Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why was a malloc with heap_size = 0 successful?</title><link>https://devzone.nordicsemi.com/thread/96241?ContentTypeID=1</link><pubDate>Thu, 17 Aug 2017 14:30:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea8d43cb-00c9-4a06-a780-a07139c1088a</guid><dc:creator>Ken</dc:creator><description>&lt;p&gt;We are using the default libnosys, so that explains why it was successful.
Should we be using the malloc functions from nordic&amp;#39;s mem_manager library rather than the libnosys malloc functions.
Would this add the heap overflow protection?&lt;/p&gt;
&lt;p&gt;Or Is there a better nordic recommended library for use with the GCC compiler?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why was a malloc with heap_size = 0 successful?</title><link>https://devzone.nordicsemi.com/thread/96239?ContentTypeID=1</link><pubDate>Thu, 17 Aug 2017 13:15:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84d1c387-081f-4bda-984d-7818b908699c</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;What compiler/stdlib are you using? malloc is normally provided by an in-built library, unless you&amp;#39;re brave and declare your own.&lt;/p&gt;
&lt;p&gt;I know that the malloc implementation in libnosys (&lt;code&gt;-lnosys&lt;/code&gt; in your linker file, if using GCC) does not have any overflow check in function &lt;code&gt;_sbrk()&lt;/code&gt;, so if you&amp;#39;re using GCC + nosys; this will happen and it will most likely eat out of the bottom of the .stack.
Here&amp;#39;s the _sbrk() from libnosys, which basically has &lt;em&gt;no checks&lt;/em&gt;:
&lt;a href="https://github.com/bminor/newlib/blob/master/libgloss/libnosys/sbrk.c"&gt;github.com/.../sbrk.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cheers,
Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>