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!
This commit is contained in:
Geoff McLane 2015-06-08 13:42:45 +02:00
parent 3f72b6e335
commit 18880eab55

View file

@ -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;
}