fix: replaced strcat * 4 by snprintf

This commit is contained in:
AngeD 2023-02-06 02:03:16 +01:00
parent 981b512c6e
commit 5e942e6cec

View File

@ -34,10 +34,11 @@ static size_t write_callback(char *response, size_t s, size_t n, void *buf)
static char* build_url(void) static char* build_url(void)
{ {
static const char base[] = const char base[] =
"https://api.binance.com/api/v3/ticker/price?symbols=["; "https://api.binance.com/api/v3/ticker/price?symbols=[";
size_t s = sizeof base; size_t s = sizeof base;
char* url; char* url;
char* tmp = (char*)s - 1;
for (size_t i = 0; WALLET[i].to; i++) { for (size_t i = 0; WALLET[i].to; i++) {
s += strlen(WALLET[i].from) + strlen(WALLET[i].to) + 3; // ["SYMBOL",] s += strlen(WALLET[i].from) + strlen(WALLET[i].to) + 3; // ["SYMBOL",]
@ -47,14 +48,9 @@ static char* build_url(void)
return 0; return 0;
} }
strcpy(url, base); strcpy(url, base);
tmp += (size_t)url;
for (size_t i = 0; WALLET[i].to; i++) { for (size_t i = 0; WALLET[i].to; i++) {
strcat(strcat(strcat(strcat( tmp += sprintf(tmp, "\"%s%s\",", WALLET[i].from, WALLET[i].to);
url,
"\""),
WALLET[i].from),
WALLET[i].to),
"\","
);
} }
url[strlen(url) - 1] = ']'; url[strlen(url) - 1] = ']';
return url; return url;