mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-17 07:12:06 +08:00
Replace all sprintf with snprintf
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:

committed by
Petro Karashchenko

parent
134b8b538f
commit
7c37421266
@@ -297,19 +297,22 @@ void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, FAR const char *msg,
|
||||
nsh_output(vtbl, "%s:\n", msg);
|
||||
for (i = 0; i < nbytes; i += 16)
|
||||
{
|
||||
sprintf(line, "%04x: ", i);
|
||||
snprintf(line, sizeof(line), "%04x: ", i);
|
||||
size = strlen(line);
|
||||
|
||||
for (j = 0; j < 16; j++)
|
||||
{
|
||||
size = strlen(line);
|
||||
if (i + j < nbytes)
|
||||
{
|
||||
sprintf(&line[size], "%02x ", buffer[i + j]);
|
||||
snprintf(&line[size], sizeof(line) - size,
|
||||
"%02x ", buffer[i + j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
strlcpy(&line[size], " ", sizeof(line) - size);
|
||||
}
|
||||
|
||||
size += strlen(&line[size]);
|
||||
}
|
||||
|
||||
for (j = 0; j < 16; j++)
|
||||
@@ -317,8 +320,9 @@ void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, FAR const char *msg,
|
||||
if (i + j < nbytes)
|
||||
{
|
||||
ch = buffer[i + j];
|
||||
sprintf(&line[strlen(line)], "%c",
|
||||
ch >= 0x20 && ch <= 0x7e ? ch : '.');
|
||||
snprintf(&line[size], sizeof(line) - size,
|
||||
"%c", ch >= 0x20 && ch <= 0x7e ? ch : '.');
|
||||
size += strlen(&line[size]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user