Bug 1388789 - change return values of nsTextFormatter::vs{s,v}printf; r=froydnj

nsTextFormatter::vsnprintf is defined to return uint32_t(-1) on error.
However, it was not doing this.

nsTextFormatter::vssprintf is defined as infallible; enforce this by
having it return void.

MozReview-Commit-ID: LdOhIHzRvAT

--HG--
extra : rebase_source : 7164eb47a89ecebfa50d40684eea1325de0172ba
This commit is contained in:
Tom Tromey 2017-09-05 13:17:49 -06:00
Родитель 586209d1a8
Коммит 0d7e17591f
2 изменённых файлов: 11 добавлений и 10 удалений

Просмотреть файл

@ -1203,19 +1203,17 @@ StringStuff(SprintfStateStr* aState, const char16_t* aStr, uint32_t aLen)
return 0;
}
uint32_t
void
nsTextFormatter::ssprintf(nsAString& aOut, const char16_t* aFmt, ...)
{
va_list ap;
uint32_t rv;
va_start(ap, aFmt);
rv = nsTextFormatter::vssprintf(aOut, aFmt, ap);
nsTextFormatter::vssprintf(aOut, aFmt, ap);
va_end(ap);
return rv;
}
uint32_t
void
nsTextFormatter::vssprintf(nsAString& aOut, const char16_t* aFmt, va_list aAp)
{
SprintfStateStr ss;
@ -1226,8 +1224,7 @@ nsTextFormatter::vssprintf(nsAString& aOut, const char16_t* aFmt, va_list aAp)
ss.stuffclosure = &aOut;
aOut.Truncate();
int n = dosprintf(&ss, aFmt, aAp);
return n ? n - 1 : n;
dosprintf(&ss, aFmt, aAp);
}
/*
@ -1286,13 +1283,17 @@ nsTextFormatter::vsnprintf(char16_t* aOut, uint32_t aOutLen,
ss.base = aOut;
ss.cur = aOut;
ss.maxlen = aOutLen;
(void) dosprintf(&ss, aFmt, aAp);
int result = dosprintf(&ss, aFmt, aAp);
/* If we added chars, and we didn't append a null, do it now. */
if ((ss.cur != ss.base) && (*(ss.cur - 1) != '\0')) {
*(--ss.cur) = '\0';
}
if (result < 0) {
return -1;
}
n = ss.cur - ss.base;
return n ? n - 1 : n;
}

Просмотреть файл

@ -55,7 +55,7 @@ public:
* sprintf into an existing nsAString, overwriting any contents it already
* has. Infallible.
*/
static uint32_t ssprintf(nsAString& aOut, const char16_t* aFmt, ...);
static void ssprintf(nsAString& aOut, const char16_t* aFmt, ...);
private:
@ -64,7 +64,7 @@ private:
*/
static uint32_t vsnprintf(char16_t* aOut, uint32_t aOutLen, const char16_t* aFmt,
va_list aAp);
static uint32_t vssprintf(nsAString& aOut, const char16_t* aFmt, va_list aAp);
static void vssprintf(nsAString& aOut, const char16_t* aFmt, va_list aAp);
};
#endif /* nsTextFormatter_h___ */