Fix PR21428 for long. Buffer was one byte too small in octal formatting case. Rename previously added test
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@268009 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1375,7 +1375,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
|
||||
this->__format_int(__fmt+1, __len, true, __iob.flags());
|
||||
const unsigned __nbuf = (numeric_limits<long>::digits / 3)
|
||||
+ ((numeric_limits<long>::digits % 3) != 0)
|
||||
+ 1;
|
||||
+ 2;
|
||||
char __nar[__nbuf];
|
||||
int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
|
||||
char* __ne = __nar + __nc;
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
|
||||
// Testing to make sure that the max length values are correctly inserted
|
||||
|
||||
#include <iostream>
|
||||
#include <cctype>
|
||||
#include <sstream>
|
||||
#include <ios>
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
|
||||
template <typename T>
|
||||
@@ -31,7 +32,6 @@ void test_octal(const char *expected)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::oct << static_cast<T>(-1);
|
||||
|
||||
assert(ss.str() == expected);
|
||||
}
|
||||
|
||||
@@ -40,8 +40,6 @@ void test_dec(const char *expected)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::dec << static_cast<T>(-1);
|
||||
|
||||
// std::cout << ss.str() << " " << expected << std::endl;
|
||||
assert(ss.str() == expected);
|
||||
}
|
||||
|
||||
@@ -60,12 +58,22 @@ void test_hex(const char *expected)
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
test_octal<uint16_t>( "177777");
|
||||
test_octal< int16_t>( "177777");
|
||||
test_octal<uint32_t>( "37777777777");
|
||||
test_octal< int32_t>( "37777777777");
|
||||
test_octal<uint64_t>("1777777777777777777777");
|
||||
test_octal< int64_t>("1777777777777777777777");
|
||||
test_octal<uint64_t>("1777777777777777777777");
|
||||
if (sizeof(long) == sizeof(int64_t)) {
|
||||
test_octal< unsigned long>("1777777777777777777777");
|
||||
test_octal< long>("1777777777777777777777");
|
||||
}
|
||||
if (sizeof(long long) == sizeof(int64_t)) {
|
||||
test_octal< unsigned long long>("1777777777777777777777");
|
||||
test_octal< long long>("1777777777777777777777");
|
||||
}
|
||||
|
||||
test_dec<uint16_t>( "65535");
|
||||
test_dec< int16_t>( "-1");
|
||||
@@ -73,6 +81,14 @@ int main(int argc, char* argv[])
|
||||
test_dec< int32_t>( "-1");
|
||||
test_dec<uint64_t>("18446744073709551615");
|
||||
test_dec< int64_t>( "-1");
|
||||
if (sizeof(long) == sizeof(int64_t)) {
|
||||
test_dec<unsigned long>("18446744073709551615");
|
||||
test_dec< long>( "-1");
|
||||
}
|
||||
if (sizeof(long long) == sizeof(int64_t)) {
|
||||
test_dec<unsigned long long>("18446744073709551615");
|
||||
test_dec< long long>( "-1");
|
||||
}
|
||||
|
||||
test_hex<uint16_t>( "FFFF");
|
||||
test_hex< int16_t>( "FFFF");
|
||||
@@ -80,6 +96,12 @@ int main(int argc, char* argv[])
|
||||
test_hex< int32_t>( "FFFFFFFF");
|
||||
test_hex<uint64_t>("FFFFFFFFFFFFFFFF");
|
||||
test_hex< int64_t>("FFFFFFFFFFFFFFFF");
|
||||
|
||||
return 0;
|
||||
if (sizeof(long) == sizeof(int64_t)) {
|
||||
test_hex<unsigned long>("FFFFFFFFFFFFFFFF");
|
||||
test_hex< long>("FFFFFFFFFFFFFFFF");
|
||||
}
|
||||
if (sizeof(long long) == sizeof(int64_t)) {
|
||||
test_hex<unsigned long long>("FFFFFFFFFFFFFFFF");
|
||||
test_hex< long long>("FFFFFFFFFFFFFFFF");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user