1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

regedit: add padding to fit REG_MULTI_SZ to the text field

This fixes a bug loading REG_MULTI_SZ values into the editor dialog,
since ncurses fields don't handle newline characters.

Signed-off-by: Chris Davis <cd.rattan@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
This commit is contained in:
Chris Davis 2014-07-18 13:35:14 -07:00 committed by Michael Adam
parent c94c765f01
commit 42df2e643f

View File

@ -642,22 +642,35 @@ static WERROR fill_value_buffer(struct edit_dialog *edit,
break;
}
case REG_MULTI_SZ: {
const char **p, **a;
int rows, cols, max;
size_t padding, length, index;
const char **array, **arrayp;
char *buf = NULL;
if (!pull_reg_multi_sz(edit, &vitem->data, &a)) {
dynamic_field_info(edit->field[FLD_DATA], &rows, &cols, &max);
if (!pull_reg_multi_sz(edit, &vitem->data, &array)) {
return WERR_NOMEM;
}
for (p = a; *p != NULL; ++p) {
if (buf == NULL) {
buf = talloc_asprintf(edit, "%s\n", *p);
} else {
buf = talloc_asprintf_append(buf, "%s\n", *p);
}
/* try to fit each string on it's own line. each line
needs to be padded with whitespace manually, since
ncurses fields do not have newlines. */
for (index = 0, arrayp = array; *arrayp != NULL; ++arrayp) {
length = MIN(strlen(*arrayp), cols);
padding = cols - length;
buf = talloc_realloc(edit, buf, char,
talloc_array_length(buf) +
length + padding + 1);
if (buf == NULL) {
return WERR_NOMEM;
}
memcpy(&buf[index], *arrayp, length);
index += length;
memset(&buf[index], ' ', padding);
index += padding;
buf[index] = '\0';
}
set_field_buffer(edit->field[FLD_DATA], 0, buf);
talloc_free(buf);
}