<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Memory overlapping !!! in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143480#M3063</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&amp;gt;&lt;BR /&gt;&amp;gt;Can you show the code of the function actually defining the array?&lt;BR /&gt;&amp;gt;&lt;BR /&gt;The code you showed does not define the array.&lt;BR /&gt;given that code I would wonder how this&lt;BR /&gt;&lt;PRE&gt;UTIL_LongToAscii function is working, I could imagine that this function is the returning a pointer to a local array,
and if so thats not reliably working in C.

My guess is that UTIL_LongToAscii has a prototype like
char* UTIL_LongToAscii(U32 u32Value,U8 u8NumberOfIntegerDigits, U8 u8NumberOfDecimalDigits);
and that does only work if UTIL_LongToAscii would allocate the buffer on the heap (with malloc), but that's not what I would do for a
HC12. Definitely not.

So instead it should have a prototype like:

&lt;/PRE&gt;void UTIL_LongToAsciiIntoBuffer(U32 u32Value, char* buffer, unsigned int bufferSize, U8 u8NumberOfIntegerDigits, U8 u8NumberOfDecimalDigits);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And then be called with a reasonably sized buffer.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 08:44:07 GMT</pubDate>
    <dc:creator>CompilerGuru</dc:creator>
    <dc:date>2020-10-29T08:44:07Z</dc:date>
    <item>
      <title>Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143471#M3054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi there,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I've seen twice a memory overlap made by the compiler/linker, without warning... The second one is critical as I don't find a workaround for that&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'm using both CW3.1 and CW5.9&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;1. First bug&lt;/DIV&gt;&lt;DIV&gt;---------------&lt;/DIV&gt;&lt;DIV&gt;I'm setting an array at a specified memory adress like that :&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;char u8CopyRamToFlash [FLASH_PAGE_SIZE] @0x000000CB = {0};&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;I'm using a HC08QB8 and if there is no RAM left, then the linker put variables inside the u8CopyRamToFlash&amp;nbsp; array without warning&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Workaround : check al lthe time that there is no overlapping due to RAM size limitation&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2. Second bug : critical no workaround found&lt;/DIV&gt;&lt;DIV&gt;----------------------------------------------------------&lt;/DIV&gt;&lt;DIV&gt;I'm using then HCS08AW.&lt;/DIV&gt;&lt;DIV&gt;I've the folowing code :&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;void GLCD_Printf (char *au8Text, FONT_DEF *stFont, char u8Type) { while(*au8Text != 0) {&amp;nbsp; LcdPutchar (*au8Text, stFont, u8Type);&amp;nbsp; au8Text++; }}void LcdPutchar (char u8Char, FONT_DEF *stFont, char u8Type){ char u8CharColumn=0,u8RightSide=0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ....}&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;First of all the function GLCD_Printf() was working perfectly on 8051 and works until the second character is displayed with HCS08AW.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;*au8Text is the pointer to an array with undefined size, pushed in the stack at adress 0x084A. It contains the adress of the array 0x0838. In this location I can find the data 0x04 0x05 0x05 which is normal.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Once jumping into LcdPutChar, then the first line is u8CharColomn=0 and this variable is located in 0x083A which overlaps the au8Text....&lt;/DIV&gt;&lt;DIV&gt;Again, this issue come after the second displayed character&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;And there I don't find any workaround...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Any suggestion highly appreciated. Automotive customers are waiting their prototypes....&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;Best regards&lt;/DIV&gt;&lt;DIV&gt;Stephane Rey&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:44:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143471#M3054</guid>
      <dc:creator>stephane</dc:creator>
      <dc:date>2020-10-29T08:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143472#M3055</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For point 1:&lt;/DIV&gt;&lt;DIV&gt;-------------&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In default configuration, the linker does not report overlap between object defined at an absolute address using the @modifier and object allocated by the linker.&lt;/DIV&gt;&lt;DIV&gt;I would recommend to change the application .prm file to remove memory area used to allocate u8CopyRamToFlash&amp;nbsp;from any area defined in the MEMORY block.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Alternatively you can ask the linker to generate a warning (or error) message when there is an overlap between variable defined with an absolute address and variable allocated by the linker.&lt;/DIV&gt;&lt;DIV&gt;In order to achieve that:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - Start the IDE&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - Open your project&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - Open the target settings dialog (press ALT+F7)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - Switch to the "Linker for HC12" Panel&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - Press the "Message" button&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - In the "Disabled" Tab select line"L1912: Object &amp;lt;obj&amp;gt; overlaps with another (last addr: &amp;lt;addr&amp;gt;, object address: &amp;lt;objadr&amp;gt;"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; - If you want the Linker to generate a Warning when an overlap is detected, Click on "Warning". If you want the linker to generate an error message click on "Error"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - Click on "OK" to close the "SmartLinker Message Settings" dialog.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; - Click OK to close the Target settings dialog.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Linker should generate a message now in case of overlap.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For Point 2:&lt;/DIV&gt;&lt;DIV&gt;------------------&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Can you please check if you do not have a stack overflow here?&lt;/DIV&gt;&lt;DIV&gt;Just check the value of SP when you are in LcdPutchar.&lt;/DIV&gt;&lt;DIV&gt;Are you inside of memory area, where the linker has allocated data?&lt;/DIV&gt;&lt;DIV&gt;If this is the case, increase the stack size (In the .prm file increase the size specified in the STACKSIZE command).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If this does not help, I would recommend you to submit a service request for that.&lt;BR /&gt;&lt;BR /&gt;Click &lt;A href="https://www.freescale.com/webapp/servicerequest.create_SR.framework?regFlag=fromOpenSR" rel="nofollow" target="_blank"&gt;here&lt;/A&gt; to submit a service request.&lt;BR /&gt;&lt;BR /&gt;Make sure to attach a reproducible project and installed product information to the service request.&lt;BR /&gt;To generate the required information:&lt;BR /&gt;- Start CodeWarrior&lt;BR /&gt;- Open the project&lt;BR /&gt;- Select "Help" -&amp;gt; "Pack and Go" and follow instructions on the screen.&lt;BR /&gt;&lt;BR /&gt;Attach the generated .zip file to the SR.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;CrasyCat&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Aug 2007 16:07:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143472#M3055</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2007-08-21T16:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143473#M3056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Thanks for this answer CrasyCat...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Point1 is solved by changing the prm... Good point. I've also changed the overlap message category.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For Point 2, the stack size is largely good . The stack is set like that :&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MSTACK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp; READ_WRITE&amp;nbsp;&amp;nbsp; 0x076F TO 0x086F;&lt;/DIV&gt;&lt;DIV&gt;and STACKSIZE = 100&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Moreover as I'm usually doing, I've set a byte to value 0x55 in the bottom stack to check stack overflows... If the value changes then overflow has occured... In in my issue this is not the case.&lt;/DIV&gt;&lt;DIV&gt;In my project, the overlapped value is at adress 0x0838, far from the bottom stack.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I've copied the first message to freescale support without joining the project. I'm trying right now to reproduce the issue in a blank project in order to let freescale investigate further...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Stephane&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Aug 2007 19:36:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143473#M3056</guid>
      <dc:creator>stephane</dc:creator>
      <dc:date>2007-08-21T19:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143474#M3057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello Stephane,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;A minor point - with&amp;nbsp;your dedicated segment for the stack, I suspect you might&amp;nbsp;have intended&amp;nbsp;a stack size of 0x100, rather than 100.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Aug 2007 20:21:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143474#M3057</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2007-08-21T20:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143475#M3058</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;You have eagle eye Mac,&lt;/DIV&gt;&lt;DIV&gt;Thanks for your feedback. I've made the mistake when copying the code there, the exact code in the PRM is :&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */    Z_RAM                    =  READ_WRITE   0x0070 TO 0x00FF;    RAM                      =  READ_WRITE   0x0100 TO 0x086F;    MSTACK                   =  READ_WRITE   0x076F TO 0x086F;    ROM                      =  READ_ONLY    0x1860 TO 0xFFAF;    ROM1                     =  READ_ONLY    0x0870 TO 0x17FF;    ROM2                     =  READ_ONLY    0xFFC0 TO 0xFFCB;END   PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */    DEFAULT_RAM                         /* non-zero page variables */                                        INTO  RAM;    _PRESTART,                          /* startup code */    STARTUP,                            /* startup data structures */    ROM_VAR,                            /* constant variables */    STRINGS,                            /* string literals */    VIRTUAL_TABLE_SEGMENT,              /* C++ virtual table segment */    DEFAULT_ROM,    COPY                                /* copy down information: how to initialize variables */                                        INTO  ROM; /* ,ROM1,ROM2: To use "ROM1,ROM2" as well, pass the option -OnB=b to the compiler */    .stack     INTO  MSTACK ;    _DATA_ZEROPAGE,                     /* zero page variables */    MY_ZEROPAGE                         INTO  Z_RAM;ENDSTACKSIZE 0x100VECTOR 0 _Startup&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;so the stacksize is 256 bytes (0x100)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Since my last post I tried many things and nothing more.... defining the array size doesn't solve the issue... I don't know how to do a workaround there... And even if I find something, I need to understand why in order to prevent other parts of the code to crash...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Stephane&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:44:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143475#M3058</guid>
      <dc:creator>stephane</dc:creator>
      <dc:date>2020-10-29T08:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143476#M3059</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;You are not eventually using the address of a local array while the function containing the array did already return? That does not work in C.&lt;BR /&gt;I'm just wondering that both the pointer and the array are on the stack, but the pointer has a lower address.&lt;BR /&gt;If the pointer and the array are not both in the same function, then this wont work, and the overlapping is per language.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Aug 2007 20:49:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143476#M3059</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2007-08-21T20:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143477#M3060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I'm not sure to understand what you are saying Daniel...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When looking inside the stack, the pointer is at the adress 0x084A and the array is at 0x0838.&lt;/DIV&gt;&lt;DIV&gt;Both are in the stack. The pointer value is correct.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The array is defined in one function as a local array and the pointer of this array&amp;nbsp;is given as a parameter when calling an other function&lt;/DIV&gt;&lt;DIV&gt;This second function starts by defining some local variables (so in stack) which have no relation with the array but on the same location than the array...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Is it a C language bad usage ?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Stephane&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Aug 2007 21:01:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143477#M3060</guid>
      <dc:creator>stephane</dc:creator>
      <dc:date>2007-08-21T21:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143478#M3061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Your description sounds as if it would be ok, but in the end there is something wrong.&lt;BR /&gt;Can you show the code of the function actually defining the array?&lt;BR /&gt;That might clear it up.&lt;BR /&gt;&lt;BR /&gt;What I meant was to actually return the address of an local array, I saw such code in the past.&lt;BR /&gt;E.g.&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;void fun(char** ptr){  char buf="Hello";  *ptr= buf; // illegal! buf is gone when fun returns.}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;But it is ok to use the buf buffer inside of fun to call other functions with it.&lt;BR /&gt;&lt;BR /&gt;Also check that the nothing writes behind the end of the array.&lt;BR /&gt;&lt;BR /&gt;In the initial mail you also wrote of a "pointer to an array with undefined size", I wonder if this just states that the pointer does not know the size of the array it points to (in C pointers never know), or if this is really a pointer to an array, however I dont think that there are pointers to arrays with no size specified in C.&lt;BR /&gt;&lt;BR /&gt;Anyway, all locals have to be above the SP (SP grows downwards), how does the SP look like before/during the function call?&lt;BR /&gt;For me the description sounds like the bug (regardless what it is) happens at the calling site not in the functions shown in the initial post.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;PS: just to double check, you are using the small memory model? In the tiny memory model, the stack could not be in around 0x800.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:44:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143478#M3061</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2020-10-29T08:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143479#M3062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi Daniel,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks for your support. I'm not an english mother tongue speaker, so I may not be so accurate when describing my issue. I do apologize for that.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The project has been created in small model.&lt;/DIV&gt;&lt;DIV&gt;The stack starts in 0x86F down to 0x76F (256 bytes) and is far from overflow.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Here is the full code.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;GLCD_DisplayValue&lt;/STRONG&gt;,&amp;nbsp;makes conversion from&amp;nbsp;a decimal value into ASCII in order to display on a graphic LCD.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;/*-------------------------------------------------------------------------------Convert a digital value into an ASCII string GLCD_DisplayValue (U32 u32Value, U8 u8NumberOfIntegerDigits, U8 u8NumberOfDecimalDigits)  u32Value                = 32 bits Value to display  u8NumberOfIntegerDigits = Number of interger digits.       If this number is higher than the number of integer       digits, it will display the non significant '0'  u8NumberOfDecimalDigits = Number of decimal digits  *stFont                 = font to use     -------------------------------------------------------------------------------*/void GLCD_DisplayValue (U32 u32Value, U8 u8NumberOfIntegerDigits, U8 u8NumberOfDecimalDigits, FONT_DEF *stFont, U8 u8Type) { U8 *au8ValueToDisplay; au8ValueToDisplay = UTIL_LongToAscii(u32Value, u8NumberOfIntegerDigits, u8NumberOfDecimalDigits);  /* Display the string */ GLCD_Printf(au8ValueToDisplay, stFont, u8Type);}&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;The array &lt;STRONG&gt;au8ValueToDisplay&lt;/STRONG&gt; contains the ASCII chars to display. The function call the &lt;STRONG&gt;GLCD_Printf&lt;/STRONG&gt; function with the pointer to the array as one of the parameters.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When arriving in &lt;STRONG&gt;GLCD_Printf&lt;/STRONG&gt;, everything works well.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;/*-------------------------------------------------------------------------------Print a string on the LCD GLCD_Printf (U8 *au8Text)   *au8Text = string to display  *stFont  = font to use-------------------------------------------------------------------------------*/void GLCD_Printf (U8 *au8Text, FONT_DEF *stFont, U8 u8Type) { while(*au8Text != 0) {  LcdPutchar (*au8Text, stFont, u8Type);  au8Text++; }}&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;STRONG&gt;au8Text&lt;/STRONG&gt; pointer is located in 0x84A and contains the value 0x838. The array (located in 0x838) contains the 3 ASCII bytes and everything is still correct there.&lt;/DIV&gt;&lt;DIV&gt;The function call &lt;STRONG&gt;LcdPutchar&lt;/STRONG&gt; in a loop to display char after char as long as the NULL char has been detected. char is given as a parameter of &lt;STRONG&gt;LcdPutchar&lt;/STRONG&gt;.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;/*-------------------------------------------------------------------------------Print a char on the LCD GLCD_Putchar (U8 u8Char)  u8Char = char to display-------------------------------------------------------------------------------*/void LcdPutchar (U8 u8Char, FONT_DEF *stFont, U8 u8Type){ U8 u8CharColumn=0,u8RightSide=0;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;When reaching the function, the pointer in 0x84A and the array in 0x838...0x83A are still correct.&lt;/DIV&gt;&lt;DIV&gt;But when running the &lt;STRONG&gt;U8 u8CharColumn=0&lt;/STRONG&gt;, this variable located in 0x83A overwrites the last char of my array .... When coming back for the second time in the function, the char in 0x839 is then overwritten, and so on....&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This code has been compiled with Keil C compiler for 8051 and was working well. This is why I was assuming the code correct and a bug in the compiler HC08... But I may have badly used the C language.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Do you see in my method something wrong ?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Best&lt;/DIV&gt;&lt;DIV&gt;Stephane&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:44:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143479#M3062</guid>
      <dc:creator>stephane</dc:creator>
      <dc:date>2020-10-29T08:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143480#M3063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&amp;gt;&lt;BR /&gt;&amp;gt;Can you show the code of the function actually defining the array?&lt;BR /&gt;&amp;gt;&lt;BR /&gt;The code you showed does not define the array.&lt;BR /&gt;given that code I would wonder how this&lt;BR /&gt;&lt;PRE&gt;UTIL_LongToAscii function is working, I could imagine that this function is the returning a pointer to a local array,
and if so thats not reliably working in C.

My guess is that UTIL_LongToAscii has a prototype like
char* UTIL_LongToAscii(U32 u32Value,U8 u8NumberOfIntegerDigits, U8 u8NumberOfDecimalDigits);
and that does only work if UTIL_LongToAscii would allocate the buffer on the heap (with malloc), but that's not what I would do for a
HC12. Definitely not.

So instead it should have a prototype like:

&lt;/PRE&gt;void UTIL_LongToAsciiIntoBuffer(U32 u32Value, char* buffer, unsigned int bufferSize, U8 u8NumberOfIntegerDigits, U8 u8NumberOfDecimalDigits);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And then be called with a reasonably sized buffer.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:44:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143480#M3063</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2020-10-29T08:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143481#M3064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Ups, a typo. buf was supposed to be an array like this;&lt;BR /&gt;&lt;PRE&gt;char buf[]="Hello";

Daniel
&lt;/PRE&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:44:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143481#M3064</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2020-10-29T08:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143482#M3065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello Stephane,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Another alternative to that proposed by Daniel might be to simply define a global array of a suitable size&amp;nbsp;to hold the ASCII digits, and&amp;nbsp;write to&amp;nbsp;this buffer&amp;nbsp;within the &lt;FONT face="Courier New"&gt;UTIL_LongToAscii()&lt;/FONT&gt; function.&amp;nbsp; It is possible that this is what the original code may have intended.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Aug 2007 10:05:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143482#M3065</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2007-08-23T10:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143483#M3066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi Daniel and Bicmac,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I could make the code working by changing first the prototype of the UTIL_LongToAscii function as you said AND by defining the size of the array in the calling function DisplayValue.... Without specifying the size it doesn't work...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This way is still nice as I have not to define the array as a global array&lt;/DIV&gt;&lt;DIV&gt;I'm still surprise that what I've wrote is working in one compiler but not an other one.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Stephane&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by stephane on &lt;SPAN class="date_text"&gt;2007-08-23&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;08:35 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Aug 2007 14:34:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143483#M3066</guid>
      <dc:creator>stephane</dc:creator>
      <dc:date>2007-08-23T14:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143484#M3067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&amp;gt;I'm still surprise that what I've wrote is working in one compiler but not an other one.&lt;BR /&gt;&lt;BR /&gt;pure coincidence.&lt;BR /&gt;Looks like the other compiler did generate code which did by chance not overwrite the stack locations used for the array. However memory below the SP can be polluted at any time by an interrupt handler for example,&lt;BR /&gt;so such cases can cause bugs very difficult to find. Even with the other compiler, maybe at certain times the code did not work and you just did not notice at the times you looked there.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Aug 2007 23:24:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143484#M3067</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2007-08-23T23:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Memory overlapping !!!</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143485#M3068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;you're right but that's not a great new as there are some machines in the field with this code !&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In in cases, now it just works fine.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you so much for your support. I do appreciate.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Best.&lt;/DIV&gt;&lt;DIV&gt;Stephane&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Aug 2007 15:47:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Memory-overlapping/m-p/143485#M3068</guid>
      <dc:creator>stephane</dc:creator>
      <dc:date>2007-08-24T15:47:07Z</dc:date>
    </item>
  </channel>
</rss>

