Commit 304c9c5f authored by Thomas Jahns's avatar Thomas Jahns 🤸

Beautify array print output.

parent cadf6323
...@@ -269,14 +269,15 @@ static void print_struct(const struct mdt_info *info, const char *line_prefix) ...@@ -269,14 +269,15 @@ static void print_struct(const struct mdt_info *info, const char *line_prefix)
static char * print_int_array(int size, int * array) { static char * print_int_array(int size, int * array) {
size_t tmp_size = 3 + size * (1 + 3 * sizeof(int)) + 1; size_t tmp_size = 3 + (size_t)size * (1 + 3 * sizeof(int)) + 1;
char * tmp = malloc(tmp_size); char * tmp = malloc(tmp_size);
int pos = sprintf(tmp, "{");
snprintf(tmp, tmp_size, "{"); if (size > 0) {
for (int i = 0; i < size; i++) { pos += sprintf(tmp + pos, "%d", array[0]);
snprintf(tmp, tmp_size, "%s,%d", tmp, array[i]); for (int i = 1; i < size; i++)
pos += sprintf(tmp + pos, ",%d", array[i]);
} }
snprintf(tmp, tmp_size, "}"); strncat(tmp+pos, "}", tmp_size - (size_t)pos);
return tmp; return tmp;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment