regedit: add padding to fit REG_MULTI_SZ to the text field
authorChris Davis <cd.rattan@gmail.com>
Fri, 18 Jul 2014 20:35:14 +0000 (13:35 -0700)
committerMichael Adam <obnox@samba.org>
Wed, 1 Oct 2014 12:32:09 +0000 (14:32 +0200)
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>
source3/utils/regedit_dialog.c

index 944fcc8aeaef31c5cbd2537d9426a7e55a9b8f76..ce67065d8bc061cce86cf4f968f635dc08eae9db 100644 (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);
        }