X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdictionary.c;h=4fbcdf2a1e16f237b2988b10d80800a3752c7343;hb=7ae167da42b6b2fb0701bcf6929b15cbceeede53;hp=ab4642a4da493c536b499a60e71479cbb14f7670;hpb=db8e899446fa2679235ce3091dc4eebe33429a99;p=pspp diff --git a/src/data/dictionary.c b/src/data/dictionary.c index ab4642a4da..4fbcdf2a1e 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -1471,12 +1471,15 @@ dict_get_documents (const struct dictionary *d) void dict_set_documents (struct dictionary *d, const struct string_array *new_docs) { - size_t i; - - dict_clear_documents (d); + /* Swap out the old documents, instead of destroying them immediately, to + allow the new documents to include pointers into the old ones. */ + struct string_array old_docs = STRING_ARRAY_INITIALIZER; + string_array_swap (&d->documents, &old_docs); - for (i = 0; i < new_docs->n; i++) + for (size_t i = 0; i < new_docs->n; i++) dict_add_document_line (d, new_docs->strings[i], false); + + string_array_destroy (&old_docs); } /* Replaces the documents for D by UTF-8 encoded string NEW_DOCS, dividing it