[chbot] snprintf

Bevin Brett bevin_brett at hotmail.com
Tue Jul 30 11:00:20 BST 2024


Getting rid of the struct and the indexing, what you have is

    char ssid[30];
    char buf[100]

    snprintf (buf, sizeof (ssid), "SSID %s\n", ssid);

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

/Bevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20240730/7be3c025/attachment-0001.html>


More information about the Chchrobotics mailing list