<?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 code bug? in Classic/Legacy CodeWarrior</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/code-bug/m-p/195158#M5071</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Me again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now with a doubt about a small portion of code... I use cppcheck to find error that compiler can not detect. Well, it acuse this error, but I can't still figrue it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code:&lt;/P&gt;&lt;PRE&gt;byte* const Tabla_CamposDir[]={&amp;nbsp; DIR_hora,&amp;nbsp; DIR_cta_cte,&amp;nbsp; DIR_calle,&amp;nbsp; DIR_numero,&amp;nbsp; DIR_ubicacion,&amp;nbsp; DIR_pasajero,&amp;nbsp; DIR_demora,&amp;nbsp; DIR_comentario,&amp;nbsp; DIR_zona,&amp;nbsp; DIR_base,&amp;nbsp; DIR_calle1,&amp;nbsp; NULL,&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; // NOTHING&amp;nbsp; DIR_tarjeta,&amp;nbsp; DIR_pactado,&amp;nbsp; DIR_calle2,&amp;nbsp; DIR_opcional1,&amp;nbsp; DIR_opcional2,&amp;nbsp; DIR_opcional3};&amp;nbsp; void DIRECCION_resetCampos (void){&amp;nbsp; word i, j;&amp;nbsp; byte* ptr;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (i=0; i&amp;lt;(sizeof(Tabla_CamposDir)/2); i++){&amp;nbsp;&amp;nbsp;&amp;nbsp; ptr = Tabla_CamposDir[i];&amp;nbsp;&amp;nbsp;&amp;nbsp; // Erase 6 bytes of each buffer (minimum length)&amp;nbsp;&amp;nbsp;&amp;nbsp; if (ptr != NULL){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (j=0; j&amp;lt;6; j++){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *(ptr + j) = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;What's inside Tabla_CamposDir are all arrays of at least 7bytes each, I mean:&lt;/P&gt;&lt;PRE&gt;byte DIR_hora[7];byte DIR_cta_cte[10];&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The cppcheck says:&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Buffer access out-of-bounds: Tabla_CamposDir&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;at&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;ptr = Tabla_CamposDir[i];&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If that's rigth.... How can I solve it? Maybe I'm blind, but I can't figure it out!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks to you all!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 09:49:57 GMT</pubDate>
    <dc:creator>sebasira</dc:creator>
    <dc:date>2020-10-29T09:49:57Z</dc:date>
    <item>
      <title>code bug?</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/code-bug/m-p/195158#M5071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Me again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now with a doubt about a small portion of code... I use cppcheck to find error that compiler can not detect. Well, it acuse this error, but I can't still figrue it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code:&lt;/P&gt;&lt;PRE&gt;byte* const Tabla_CamposDir[]={&amp;nbsp; DIR_hora,&amp;nbsp; DIR_cta_cte,&amp;nbsp; DIR_calle,&amp;nbsp; DIR_numero,&amp;nbsp; DIR_ubicacion,&amp;nbsp; DIR_pasajero,&amp;nbsp; DIR_demora,&amp;nbsp; DIR_comentario,&amp;nbsp; DIR_zona,&amp;nbsp; DIR_base,&amp;nbsp; DIR_calle1,&amp;nbsp; NULL,&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; // NOTHING&amp;nbsp; DIR_tarjeta,&amp;nbsp; DIR_pactado,&amp;nbsp; DIR_calle2,&amp;nbsp; DIR_opcional1,&amp;nbsp; DIR_opcional2,&amp;nbsp; DIR_opcional3};&amp;nbsp; void DIRECCION_resetCampos (void){&amp;nbsp; word i, j;&amp;nbsp; byte* ptr;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (i=0; i&amp;lt;(sizeof(Tabla_CamposDir)/2); i++){&amp;nbsp;&amp;nbsp;&amp;nbsp; ptr = Tabla_CamposDir[i];&amp;nbsp;&amp;nbsp;&amp;nbsp; // Erase 6 bytes of each buffer (minimum length)&amp;nbsp;&amp;nbsp;&amp;nbsp; if (ptr != NULL){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (j=0; j&amp;lt;6; j++){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *(ptr + j) = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;What's inside Tabla_CamposDir are all arrays of at least 7bytes each, I mean:&lt;/P&gt;&lt;PRE&gt;byte DIR_hora[7];byte DIR_cta_cte[10];&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The cppcheck says:&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Buffer access out-of-bounds: Tabla_CamposDir&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;at&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;ptr = Tabla_CamposDir[i];&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If that's rigth.... How can I solve it? Maybe I'm blind, but I can't figure it out!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks to you all!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:49:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/code-bug/m-p/195158#M5071</guid>
      <dc:creator>sebasira</dc:creator>
      <dc:date>2020-10-29T09:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: code bug?</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/code-bug/m-p/195159#M5072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sebastian,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; sizeof(Tabla_CamposDir)/2 is only the number of elements in the array if the sizeof a byte* is 2. I am not familar with cppchecker, but you would need to check what size it assumes a pointer to a byte const is. If cppcheck thought sizeof(byte *) was 4, then it would indeed flag a access out-of-bounds.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A better way for calculating the number of elements would be : sizeof(Tabla_CamposDir)/sizeof(Table_CamposDir[0])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Jan 2012 12:40:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/code-bug/m-p/195159#M5072</guid>
      <dc:creator>djsimpson</dc:creator>
      <dc:date>2012-01-08T12:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: code bug?</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/code-bug/m-p/195160#M5073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi David!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Well, you're the winner!!! LOL!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for taking a look at it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;You're rigth, I didn't notice that the size of pointer to byte could be different. With the modification you suggest no errors are thrown&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jan 2012 20:25:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/code-bug/m-p/195160#M5073</guid>
      <dc:creator>sebasira</dc:creator>
      <dc:date>2012-01-09T20:25:18Z</dc:date>
    </item>
  </channel>
</rss>

