Fix some hard coded buffer len of snprintf

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
Huang Qi 2023-03-20 16:46:48 +08:00 committed by Alan Carvalho de Assis
parent 86d084fe21
commit 8ae5a1b148
7 changed files with 17 additions and 14 deletions

View File

@ -344,7 +344,7 @@ int main(int argc, FAR char *argv[])
#ifdef CONFIG_LIBC_ENVPATH
filename = dirlist[i];
#else
snprintf(fullpath, 128, "%s/%s", MOUNTPT, dirlist[i]);
snprintf(fullpath, sizeof(fullpath), "%s/%s", MOUNTPT, dirlist[i]);
filename = fullpath;
#endif

View File

@ -250,8 +250,8 @@ int main(int argc, FAR char *argv[])
* interface
*/
snprintf(blockname, 32, "/dev/mtdblock%d", i);
snprintf(charname, 32, "/dev/mtd%d", i);
snprintf(blockname, sizeof(blockname), "/dev/mtdblock%d", i);
snprintf(charname, sizeof(charname), "/dev/mtd%d", i);
ret = ftl_initialize(i, part[i]);
if (ret < 0)
@ -336,7 +336,7 @@ int main(int argc, FAR char *argv[])
/* Open the master MTD partition character driver for writing */
snprintf(charname, 32, "/dev/mtd%d", i);
snprintf(charname, sizeof(charname), "/dev/mtd%d", i);
fd = open(charname, O_RDWR);
if (fd < 0)
{

View File

@ -198,7 +198,7 @@ int main(int argc, FAR char *argv[])
#ifdef CONFIG_LIBC_ENVPATH
filename = dirlist[i];
#else
snprintf(fullpath, 128, "%s/%s", MOUNTPT, dirlist[i]);
snprintf(fullpath, sizeof(fullpath), "%s/%s", MOUNTPT, dirlist[i]);
filename = fullpath;
#endif

View File

@ -305,7 +305,7 @@ int main(int argc, FAR char *argv[])
#ifdef CONFIG_LIBC_ENVPATH
filepath = g_hello_argv[0];
#else
snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_hello_argv[0]);
snprintf(fullpath, sizeof(fullpath), "%s/%s", MOUNTPT, g_hello_argv[0]);
filepath = fullpath;
#endif
@ -383,7 +383,7 @@ int main(int argc, FAR char *argv[])
posix_spawn_file_actions_dump(&file_actions);
snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_data);
snprintf(fullpath, sizeof(fullpath), "%s/%s", MOUNTPT, g_data);
ret = posix_spawn_file_actions_addopen(&file_actions, 0, fullpath,
O_RDONLY, 0644);
if (ret != 0)
@ -404,7 +404,7 @@ int main(int argc, FAR char *argv[])
#ifdef CONFIG_LIBC_ENVPATH
filepath = g_redirect_argv[0];
#else
snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_redirect_argv[0]);
snprintf(fullpath, sizeof(fullpath), "%s/%s", MOUNTPT, g_redirect_argv[0]);
filepath = fullpath;
#endif

View File

@ -82,7 +82,8 @@ static void net_stats(struct httpd_state *pstate, char *ptr)
for (i = 0; i < sizeof(g_netstats) / sizeof(net_stats_t); i++)
{
snprintf(buffer, 16, "%5u\n", ((net_stats_t *)&g_netstats)[i]);
snprintf(buffer, sizeof(buffer), "%5u\n",
((net_stats_t *)&g_netstats)[i]);
httpd_send_datachunk(pstate->ht_sockfd, buffer, strlen(buffer),
chunked_http_tx);
}
@ -104,7 +105,7 @@ static void file_stats(struct httpd_state *pstate, char *ptr)
chunked_http_tx = pstate->ht_chunked;
#endif
snprintf(buffer, 16, "%5u", httpd_fs_count(pcount));
snprintf(buffer, sizeof(buffer), "%5u", httpd_fs_count(pcount));
httpd_send_datachunk(pstate->ht_sockfd, buffer, strlen(buffer),
chunked_http_tx);
}

View File

@ -224,7 +224,8 @@ void vt100_setcursor(int chn, uint16_t row, uint16_t column)
/* Format the cursor position command. The origin is (1,1). */
len = snprintf(buffer, 16, g_fmt_cursorpos, row + 1, column + 1);
len = snprintf(buffer, sizeof(buffer), g_fmt_cursorpos,
row + 1, column + 1);
/* Send the VT100 CURSORPOS command */
@ -324,7 +325,7 @@ void vt100_foreground_color(int chn, uint8_t color)
/* Format the foreground color command. */
DEBUGASSERT(color < 10);
len = snprintf(buffer, 16, g_fmt_forecolor, color);
len = snprintf(buffer, sizeof(buffer), g_fmt_forecolor, color);
/* Send the VT100 foreground color command */
@ -347,7 +348,7 @@ void vt100_background_color(int chn, uint8_t color)
/* Format the background color command. */
DEBUGASSERT(color < 10);
len = snprintf(buffer, 16, g_fmt_backcolor, color);
len = snprintf(buffer, sizeof(buffer), g_fmt_backcolor, color);
/* Send the VT100 background color command */

View File

@ -753,7 +753,8 @@ static void vi_setcursor(FAR struct vi_s *vi, uint16_t row, uint16_t column)
/* Format the cursor position command. The origin is (1,1). */
len = snprintf(buffer, 16, g_fmtcursorpos, row + 1, column + 1);
len = snprintf(buffer, sizeof(buffer), g_fmtcursorpos,
row + 1, column + 1);
/* Send the VT100 CURSORPOS command */