mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-23 06:54:30 +01:00
Use snprintf(...) instead of sprintf(...)
This commit is contained in:
committed by
Rusty Russell
parent
0f7b11bdc2
commit
9d9a9523d0
@@ -350,7 +350,7 @@ static void do_one_estimatefee(struct bitcoind *bitcoind,
|
||||
{
|
||||
char blockstr[STR_MAX_CHARS(u32)];
|
||||
|
||||
sprintf(blockstr, "%u", efee->blocks[efee->i]);
|
||||
snprintf(blockstr, sizeof(blockstr), "%u", efee->blocks[efee->i]);
|
||||
start_bitcoin_cli(bitcoind, NULL, process_estimatefee, false, NULL, efee,
|
||||
"estimatesmartfee", blockstr, efee->estmode[efee->i],
|
||||
NULL);
|
||||
@@ -682,7 +682,7 @@ void bitcoind_getblockhash_(struct bitcoind *bitcoind,
|
||||
void *arg)
|
||||
{
|
||||
char str[STR_MAX_CHARS(height)];
|
||||
sprintf(str, "%u", height);
|
||||
snprintf(str, sizeof(str), "%u", height);
|
||||
|
||||
start_bitcoin_cli(bitcoind, NULL, process_getblockhash, true, cb, arg,
|
||||
"getblockhash", str, NULL);
|
||||
|
||||
@@ -360,12 +360,12 @@ static void log_one_line(unsigned int skipped,
|
||||
char buf[101];
|
||||
|
||||
if (skipped) {
|
||||
sprintf(buf, "%s... %u skipped...", data->prefix, skipped);
|
||||
snprintf(buf, sizeof(buf), "%s... %u skipped...", data->prefix, skipped);
|
||||
write_all(data->fd, buf, strlen(buf));
|
||||
data->prefix = "\n";
|
||||
}
|
||||
|
||||
sprintf(buf, "%s+%lu.%09u %s%s: ",
|
||||
snprintf(buf, sizeof(buf), "%s+%lu.%09u %s%s: ",
|
||||
data->prefix,
|
||||
(unsigned long)diff.ts.tv_sec,
|
||||
(unsigned)diff.ts.tv_nsec,
|
||||
@@ -501,7 +501,7 @@ static void log_dump_to_file(int fd, const struct log_book *lr)
|
||||
}
|
||||
|
||||
start = lr->init_time.ts.tv_sec;
|
||||
len = sprintf(buf, "%zu bytes, %s", lr->mem_used, ctime(&start));
|
||||
len = snprintf(buf, sizeof(buf), "%zu bytes, %s", lr->mem_used, ctime(&start));
|
||||
write_all(fd, buf, len);
|
||||
|
||||
/* ctime includes \n... WTF? */
|
||||
@@ -579,7 +579,7 @@ static void json_add_time(struct json_result *result, const char *fieldname,
|
||||
{
|
||||
char timebuf[100];
|
||||
|
||||
sprintf(timebuf, "%lu.%09u",
|
||||
snprintf(timebuf, sizeof(timebuf), "%lu.%09u",
|
||||
(unsigned long)ts.tv_sec,
|
||||
(unsigned)ts.tv_nsec);
|
||||
json_add_string(result, fieldname, timebuf);
|
||||
|
||||
@@ -15,7 +15,7 @@ static void json_add_ptr(struct json_result *response, const char *name,
|
||||
const void *ptr)
|
||||
{
|
||||
char ptrstr[STR_MAX_CHARS(void *)];
|
||||
sprintf(ptrstr, "%p", ptr);
|
||||
snprintf(ptrstr, sizeof(ptrstr), "%p", ptr);
|
||||
json_add_string(response, name, ptrstr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user