Fix PR21428 for long. Buffer was one byte too small in octal formatting case. Rename previously added test

llvm-svn: 268009
This commit is contained in:
Eric Fiselier 2016-04-29 07:23:20 +00:00
parent 1a5799fe3e
commit 3ed9f6ebde
2 changed files with 32 additions and 10 deletions

View File

@ -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;

View File

@ -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);
}
@ -50,22 +48,32 @@ void test_hex(const char *expected)
{
std::stringstream ss;
ss << std::hex << static_cast<T>(-1);
std::string str = ss.str();
for (size_t i = 0; i < str.size(); ++i )
str[i] = std::toupper(str[i]);
assert(str == 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");
}
}