<div dir="ltr">Hi, Jef<div><br></div><div>I have compiled this sniplet:<div><br></div><div><div>main (int argc, char *argv[])</div><div>{</div><div><span class="" style="white-space:pre"> </span>int i;</div><div><span class="" style="white-space:pre"> </span>const mares_iconhd_model_t models[] = {</div><div><span class="" style="white-space:pre"> </span>{"Matrix", MATRIX},</div><div><span class="" style="white-space:pre"> </span>//<span class="" style="white-space:pre"> </span>{"Smart Apnea", SMARTAPNEA},</div><div><span class="" style="white-space:pre"> </span>{"Smart", SMART},</div><div><span class="" style="white-space:pre"> </span>{"Icon HD", ICONHD},</div><div><span class="" style="white-space:pre"> </span>{"Icon AIR", ICONHDNET},</div><div><span class="" style="white-space:pre"> </span>{"Puck Pro", PUCKPRO},</div><div><span class="" style="white-space:pre"> </span>{"Nemo Wide 2", NEMOWIDE2},</div><div><span class="" style="white-space:pre"> </span>{"Puck 2", PUCK2},</div><div><span class="" style="white-space:pre"> </span>};</div><div><br></div><div><span class="" style="white-space:pre"> </span>// Check the product name in the version packet against the list</div><div><span class="" style="white-space:pre"> </span>// with valid names, and return the corresponding model number.</div><div><span class="" style="white-space:pre"> </span>unsigned int model = 0;</div><div><span class="" style="white-space:pre"> </span>for ( i = 0; i < 7; ++i) {</div><div><span class="" style="white-space:pre"> </span>printf ("i: %d, sizeof: %d, strlen: %d\n",i,sizeof(models[i].name),strlen (models[i].name));</div><div><br></div><div><span class="" style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre">}</span></div></div><div><span class="" style="white-space:pre"><br></span></div><div><span class="" style="white-space:pre">and the corresponding ouput is:</span></div><div><span class="" style="white-space:pre"><br></span></div><div><span class="" style="white-space:pre"><br></span></div><div><span class="" style="white-space:pre">giorgio@giorgio-laptop:~$ ./prova
i: 0, sizeof: 17, strlen: 6
i: 1, sizeof: 17, strlen: 5
i: 2, sizeof: 17, strlen: 7
i: 3, sizeof: 17, strlen: 8
i: 4, sizeof: 17, strlen: 8
i: 5, sizeof: 17, strlen: 11
i: 6, sizeof: 17, strlen: 6</span><span class="" style="white-space:pre">
</span></div><div><span class="" style="white-space:pre"><br></span></div><div><span class="" style="white-space:pre"><br></span></div><div><span class="" style="white-space:pre">So it seems to me that either we use strlen or we use strcmp</span></div><div><span class="" style="white-space:pre"><br></span></div><div><span class="" style="white-space:pre">G</span></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-09-09 13:41 GMT+02:00 Jef Driesen <span dir="ltr"><<a href="mailto:jef@libdivecomputer.org" target="_blank">jef@libdivecomputer.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 2015-09-04 12:25, Giorgio Marzano wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Right now, I noticed a bug in the mares_iconhd_get_model function, line 120<br>
of mares_iconhd.c, where sizeof should be actually strlen.<br>
<br>
if (memcmp (device->version + 0x46, models[i].name, /*sizeof*/ strlen<br>
(models[i].name) - 1) == 0) {<br>
</blockquote>
<br></span>
This is not a bug. The name field is a 16 byte array, not a string. The initialization with a sting literal is convenient. The remainder of the array will automatically get padded with zero bytes, which is exactly what we need.<br>
<br>
The correct fix is to add a new entry containing "Mares Smart". Then, the next question is: what's the correct model number? According to the model number in the memory dump (e.g. byte at offset 0), it's 0x10 or SMART:<br>
<br>
{"Smart", SMART},<br>
+ {"Smart Apnea", SMART},<br>
{"Icon HD", ICONHD},<br>
<br>
But then how do we distinguish the normal smart from the apnea variant? That will be important, because both appear to use a different data format. The strange thing here is that the normal smart already had a freedive mode. The main difference is that we now not only get a summary of each freedive in the session, but also a detailed profile.<br>
<br>
I wonder if there is some kind of format indicator in the header that we can use to distinguish between dives with the enhanced apnea format and the more limited normal format.<span class="HOEnZb"><font color="#888888"><br>
<br>
Jef<br>
</font></span></blockquote></div><br></div>