зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1350097 - handle very long floating point output in cvt_f; r=froydnj
Bug 1350097 points out a case where the assertion in cvt_f, added in https://bugzilla.mozilla.org/show_bug.cgi?id=1060419#c127, triggers. Before this addition, code calling this printf variant would end up just printing something invalid, as the truncated value would be emitted. This patch increases the buffer size to be sufficient for DBL_MAX. MozReview-Commit-ID: AVphURGa6jL --HG-- extra : rebase_source : c7a2dad8e496434a631441ccc25dfee2db1ea71a
This commit is contained in:
Родитель
749b78d5ae
Коммит
8e0d0b9741
|
@ -8,6 +8,7 @@
|
|||
#include "mozilla/IntegerPrintfMacros.h"
|
||||
#include "mozilla/SizePrintfMacros.h"
|
||||
|
||||
#include <cfloat>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "jsprf.h"
|
||||
|
@ -61,6 +62,10 @@ BEGIN_TEST(testPrintf)
|
|||
CHECK(print_one("1.500000", "%f", 1.5f));
|
||||
CHECK(print_one("1.5", "%g", 1.5));
|
||||
|
||||
// Regression test for bug#1350097. The bug was an assertion
|
||||
// failure caused by printing a very long floating point value.
|
||||
print_one("ignore", "%lf", DBL_MAX);
|
||||
|
||||
CHECK(print_one("2727", "%" PRIu32, (uint32_t) 2727));
|
||||
CHECK(print_one("aa7", "%" PRIx32, (uint32_t) 2727));
|
||||
CHECK(print_one("2727", "%" PRIu64, (uint64_t) 2727));
|
||||
|
|
|
@ -255,7 +255,8 @@ bool
|
|||
mozilla::PrintfTarget::cvt_f(double d, const char* fmt0, const char* fmt1)
|
||||
{
|
||||
char fin[20];
|
||||
char fout[300];
|
||||
// The size is chosen such that we can print DBL_MAX. See bug#1350097.
|
||||
char fout[320];
|
||||
int amount = fmt1 - fmt0;
|
||||
|
||||
MOZ_ASSERT((amount > 0) && (amount < (int)sizeof(fin)));
|
||||
|
@ -277,7 +278,7 @@ mozilla::PrintfTarget::cvt_f(double d, const char* fmt0, const char* fmt1)
|
|||
}
|
||||
#endif
|
||||
size_t len = SprintfLiteral(fout, fin, d);
|
||||
MOZ_ASSERT(len <= sizeof(fout));
|
||||
MOZ_RELEASE_ASSERT(len <= sizeof(fout));
|
||||
|
||||
return emit(fout, len);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче