<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr"></div><div dir="ltr">Ok, good point, if we ignore the history of the language. Ignore the warning and what itis pointing. Heck let ignore the fact you read a terse man page.</div><div dir="ltr"><br></div><div dir="ltr">Why are you use snprintf, instead of sprintf, and what did you want tohappen, because the all the non string saffety trick are valid formatting rules. Aka use %*s and two variables </div><div dir="ltr"><br><blockquote type="cite">On 30 Jul 2024, at 11:55 PM, Robin Gilks <gb7ipd@gmail.com> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><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>
<span>_______________________________________________</span><br><span>Chchrobotics mailing list Chchrobotics@lists.ourshack.com</span><br><span>https://lists.ourshack.com/mailman/listinfo/chchrobotics</span><br><span>Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/</span><br><span>Meetings usually 3rd Monday each month. See http://kiwibots.org for venue, directions and dates.</span><br><span>When replying, please edit your Subject line to reflect new subjects.</span></div></blockquote></body></html>