From 18880eab5551dff617d9a09712468cc275bfe87a Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Mon, 8 Jun 2015 13:42:45 +0200 Subject: [PATCH] Issue #218 - Do NOT allocate a 1 byte null String buffer. This is when setting a String config value through say tidyOptSetValue using say tidyOptSetValue(tdoc,id,""). If the length of the new string is zero then do not allocate a 1 byte buffer, set it to 0, for the option. Any previous buffer has already been released. This means API functions like tidyOptSaveSink will not return erroneous null String values! --- src/config.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 5248230..db11b87 100644 --- a/src/config.c +++ b/src/config.c @@ -379,7 +379,10 @@ static Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val ) { assert( option->id == optId && option->type == TidyString ); FreeOptionValue( doc, option, &doc->config.value[ optId ] ); - doc->config.value[ optId ].p = TY_(tmbstrdup)( doc->allocator, val ); + if ( TY_(tmbstrlen)(val)) /* Issue #218 - ONLY if it has LENGTH! */ + doc->config.value[ optId ].p = TY_(tmbstrdup)( doc->allocator, val ); + else + doc->config.value[ optId ].p = 0; /* should already be zero, but to be sure... */ } return status; }