Bug 1341880 - do not emit trailing \0 in PrintfState; r=glandium

MozReview-Commit-ID: 2di7CsDCWLF

--HG--
extra : rebase_source : f5469d4b3e818204848123ea163c7f0f08563f7c
This commit is contained in:
Tom Tromey 2017-02-27 13:29:54 -07:00
parent c7fb5e7910
commit 3f70992816
4 changed files with 8 additions and 16 deletions

View File

@ -880,10 +880,6 @@ mozilla::PrintfTarget::vprint(const char* fmt, va_list ap)
}
}
// Stuff trailing NUL
if (!emit("\0", 1))
return false;
return true;
}

View File

@ -105,7 +105,7 @@ private:
// Used in the implementation of Smprintf et al.
template<typename AllocPolicy>
class MOZ_STACK_CLASS SprintfState final : public mozilla::PrintfTarget, private AllocPolicy
class MOZ_STACK_CLASS SprintfState final : private mozilla::PrintfTarget, private AllocPolicy
{
public:
explicit SprintfState(char* base)
@ -119,6 +119,12 @@ class MOZ_STACK_CLASS SprintfState final : public mozilla::PrintfTarget, private
this->free_(mBase);
}
bool vprint(const char* format, va_list ap_list) {
// The "" here has a single \0 character, which is what we're
// trying to append.
return mozilla::PrintfTarget::vprint(format, ap_list) && append("", 1);
}
char* release() {
char* result = mBase;
mBase = nullptr;

View File

@ -265,7 +265,7 @@ GetAssertBehavior()
return gAssertBehavior;
}
struct FixedBuffer : public mozilla::PrintfTarget
struct FixedBuffer final : public mozilla::PrintfTarget
{
FixedBuffer() : curlen(0)
{
@ -285,11 +285,6 @@ FixedBuffer::append(const char* aBuf, size_t aLen)
return true;
}
// strip the trailing null, we add it again later
if (aBuf[aLen - 1] == '\0') {
--aLen;
}
if (curlen + aLen >= sizeof(buffer)) {
aLen = sizeof(buffer) - curlen - 1;
}

View File

@ -931,11 +931,6 @@ struct MOZ_STACK_CLASS PrintfAppend_CharT : public mozilla::PrintfTarget
return true;
}
// Printf sends us the final null terminator even though we don't want it
if (aStr[aLen - 1] == '\0') {
--aLen;
}
mString->AppendASCII(aStr, aLen);
return true;
}