chrome newer version(14) does not give a null terminated string as part of NPVariant

236 Views Asked by At

chrome newer version(14) does not give a null terminated string as part of NPVariant whereas firefox acts differently and gives a null terminated string. Is that expected ??

What can we do other than extracting a string,allocating memory and add null character and then deallocating the same..... all this just to add a null character??

1

There are 1 best solutions below

0
On

NPVariant NPStrings have never been required to include a NULL terminated string. Sometimes they did anyway. What they do include, however, is a "length" to indicate how long the string is; I generally just convert it to a std::string like so:

retVal = std::string(npVar->value.stringValue.UTF8Characters, npVar->value.stringValue.UTF8Length);

That is how FireBreath does it; https://github.com/firebreath/FireBreath/blob/master/src/NpapiCore/NpapiBrowserHost.cpp#L253