diff options
| author | Eric Fiselier <eric@efcs.ca> | 2016-04-29 07:23:20 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2016-04-29 07:23:20 +0000 |
| commit | 3ed9f6ebdeebcf770e20843bfb875f1f3c5f28f0 (patch) | |
| tree | 61dc8d94c72526919b54333d5c0641892d484051 | |
| parent | 1a5799fe3e28d3c2c8a683cc6e49ccf7ba1d4893 (diff) | |
| download | bcm5719-llvm-3ed9f6ebdeebcf770e20843bfb875f1f3c5f28f0.tar.gz bcm5719-llvm-3ed9f6ebdeebcf770e20843bfb875f1f3c5f28f0.zip | |
Fix PR21428 for long. Buffer was one byte too small in octal formatting case. Rename previously added test
llvm-svn: 268009
| -rw-r--r-- | libcxx/include/locale | 2 | ||||
| -rw-r--r-- | libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass.cpp (renamed from libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass) | 40 |
2 files changed, 32 insertions, 10 deletions
diff --git a/libcxx/include/locale b/libcxx/include/locale index d451278a87e..b1cac28fb84 100644 --- a/libcxx/include/locale +++ b/libcxx/include/locale @@ -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; diff --git a/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass b/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass.cpp index 5f5a859cb29..c9b61725324 100644 --- a/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass +++ b/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass.cpp @@ -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"); + } } |

