<div dir="ltr">Absolutely correct<div>As I quoted previously from the man page<br></div><i>The functions snprintf() and vsnprintf() write at most size bytes (including the terminating null byte ('\0')) to str.<br></i>Note there is no qualification of what 'size' is referring to, only that it is a restriction of what is written, nothing to indicate that it's the length of str.<div><div>That's the whole problem - sloppy specifications!</div><br class="gmail-Apple-interchange-newline"></div><div>I have a standard question I always ask of people who are specifying anything: "what colour should it be?"</div><div>This avoids the exclamation from the developer one day before delivery of: "colour, colour - nobody told us it had to have a colour!!"</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 30, 2024 at 10:00 PM Bevin Brett <<a href="mailto:bevin_brett@hotmail.com">bevin_brett@hotmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg8602513823353657136">
<div dir="ltr">
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Getting rid of the struct and the indexing, what you have is</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
char ssid[30];</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
char buf[100]</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
snprintf (buf, sizeof (ssid), "SSID %s\n", ssid);<br>
<br>
</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
which is a request to write 5 chars ("SSID ") followed by any number of chars ending in a NUL (perhaps overrunning the end of ssid if there are no NUL in it) followed by \n and a trailing NUL into the first upto 30 characters of buf. The warning is assuming
(incorrectly) that ssid will contain less than 30 non-NULL characters, hence decides may need upto 37 characters (should have been 36) (5 + 29 + 1 + 1) and you have only supplied 30</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
/Bevin</div>
</div>
_______________________________________________<br>
Chchrobotics mailing list <a href="mailto:Chchrobotics@lists.ourshack.com" target="_blank">Chchrobotics@lists.ourshack.com</a><br>
<a href="https://lists.ourshack.com/mailman/listinfo/chchrobotics" rel="noreferrer" target="_blank">https://lists.ourshack.com/mailman/listinfo/chchrobotics</a><br>
Mail Archives: <a href="http://lists.ourshack.com/pipermail/chchrobotics/" rel="noreferrer" target="_blank">http://lists.ourshack.com/pipermail/chchrobotics/</a><br>
Meetings usually 3rd Monday each month. See <a href="http://kiwibots.org" rel="noreferrer" target="_blank">http://kiwibots.org</a> for venue, directions and dates.<br>
When replying, please edit your Subject line to reflect new subjects.</div></blockquote></div>