From 42df2e643f68f5ec19e6a41eade29199a3266035 Mon Sep 17 00:00:00 2001 From: Chris Davis Date: Fri, 18 Jul 2014 13:35:14 -0700 Subject: 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 Reviewed-by: Andreas Schneider Reviewed-by: Michael Adam --- source3/utils/regedit_dialog.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/source3/utils/regedit_dialog.c b/source3/utils/regedit_dialog.c index 944fcc8aea..ce67065d8b 100644 --- a/source3/utils/regedit_dialog.c +++ b/source3/utils/regedit_dialog.c @@ -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); } -- cgit