more sbstring stuff

This commit is contained in:
Enno Rehling 2018-11-24 12:46:28 +01:00
parent 3e54d307df
commit 1d71e76ad6

View file

@ -2192,31 +2192,29 @@ static void eval_regions(struct opstack **stack, const void *userdata)
int handle_end, begin = opop(stack).i; int handle_end, begin = opop(stack).i;
const arg_regions *aregs = (const arg_regions *)opop(stack).v; const arg_regions *aregs = (const arg_regions *)opop(stack).v;
char buf[256]; char buf[256];
size_t size = sizeof(buf) - 1;
variant var; variant var;
char *bufp = buf; sbstring sbs;
sbs_init(&sbs, buf, sizeof(buf));
if (aregs == NULL) { if (aregs == NULL) {
handle_end = begin; handle_end = begin;
} }
else { else if (i >= 0) {
if (i >= 0) handle_end = begin + i;
handle_end = begin + i;
else
handle_end = aregs->nregions + i;
} }
else {
handle_end = aregs->nregions + i;
}
for (i = begin; i < handle_end; ++i) { for (i = begin; i < handle_end; ++i) {
const char *rname = (const char *)regionname(aregs->regions[i], report); const char *rname = (const char *)regionname(aregs->regions[i], report);
bufp = STRLCPY(bufp, rname, size); sbs_strcat(&sbs, rname);
if (i + 1 < handle_end && size > 2) { if (i + 1 < handle_end) {
strcat(bufp, ", "); sbs_strcat(&sbs, ", ");
bufp += 2;
size -= 2;
} }
} }
*bufp = 0; var.v = strcpy(balloc(sbs_length(&sbs)), buf);
var.v = strcpy(balloc((size_t)(bufp - buf + 1)), buf);
opush(stack, var); opush(stack, var);
} }