This commit is contained in:
Kovid Goyal 2020-06-25 21:43:54 +05:30
parent 9a384c5045
commit 7ef911e17d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -387,10 +387,10 @@ static inline const char*
repr_csi_params(unsigned int *params, unsigned int num_params) { repr_csi_params(unsigned int *params, unsigned int num_params) {
if (!num_params) return ""; if (!num_params) return "";
static char buf[256]; static char buf[256];
unsigned int pos = 0; unsigned int pos = 0, i = 0;
while (pos < 200 && num_params && sizeof(buf) > pos + 1) { while (pos < 200 && i++ < num_params && sizeof(buf) > pos + 1) {
const char *fmt = num_params > 1 ? "%u " : "%u"; const char *fmt = i < num_params ? "%u, " : "%u";
int ret = snprintf(buf + pos, sizeof(buf) - pos - 1, fmt, params[num_params--]); int ret = snprintf(buf + pos, sizeof(buf) - pos - 1, fmt, params[i-1]);
if (ret < 0) return "An error occurred formatting the params array"; if (ret < 0) return "An error occurred formatting the params array";
pos += ret; pos += ret;
} }