2
0
mirror of https://github.com/boostorg/nowide.git synced 2026-02-22 03:22:32 +00:00

Merge pull request #58 from Flamefire/static_analyzer

Fix issues found by static analyzer
This commit is contained in:
Alexander Grund
2020-01-06 10:57:33 +01:00
committed by GitHub
6 changed files with 56 additions and 14 deletions

View File

@@ -85,7 +85,10 @@ namespace nowide {
{
wchar_t **p;
int argc;
wargv_ptr(const wargv_ptr &); // Non-copyable
// Non-copyable
wargv_ptr(const wargv_ptr &);
wargv_ptr &operator=(const wargv_ptr &);
public:
wargv_ptr() : p(CommandLineToArgvW(GetCommandLineW(), &argc))
{}
@@ -110,7 +113,10 @@ namespace nowide {
class wenv_ptr
{
wchar_t *p;
wenv_ptr(const wenv_ptr &); // Non-copyable
// Non-copyable
wenv_ptr(const wenv_ptr &);
wenv_ptr &operator=(const wenv_ptr &);
public:
wenv_ptr() : p(GetEnvironmentStringsW())
{}

View File

@@ -13,6 +13,7 @@
#include <boost/config.hpp>
#include <boost/nowide/replacement.hpp>
#include <boost/version.hpp>
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_NOWIDE_DYN_LINK)
#ifdef BOOST_NOWIDE_SOURCE
@@ -63,5 +64,11 @@
#define BOOST_NOWIDE_USE_FSTREAM_REPLACEMENTS 0
#endif
#if BOOST_VERSION < 106500 && defined(BOOST_GCC) && BOOST_GCC_VERSION >= 70000
#define BOOST_NOWIDE_FALLTHROUGH __attribute__((fallthrough))
#else
#define BOOST_NOWIDE_FALLTHROUGH BOOST_FALLTHROUGH
#endif
#endif // boost/nowide/config.hpp
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -8,7 +8,7 @@
#ifndef BOOST_NOWIDE_UTF_HPP_INCLUDED
#define BOOST_NOWIDE_UTF_HPP_INCLUDED
#include <boost/config.hpp>
#include <boost/nowide/config.hpp>
#include <boost/cstdint.hpp>
namespace boost {
@@ -219,7 +219,7 @@ namespace nowide {
if(!is_trail(tmp))
return illegal;
c = (c << 6) | (tmp & 0x3F);
BOOST_FALLTHROUGH;
BOOST_NOWIDE_FALLTHROUGH;
case 2:
if(BOOST_UNLIKELY(p == e))
return incomplete;
@@ -227,7 +227,7 @@ namespace nowide {
if(!is_trail(tmp))
return illegal;
c = (c << 6) | (tmp & 0x3F);
BOOST_FALLTHROUGH;
BOOST_NOWIDE_FALLTHROUGH;
case 1:
if(BOOST_UNLIKELY(p == e))
return incomplete;
@@ -269,8 +269,8 @@ namespace nowide {
switch(trail_size)
{
case 3: c = (c << 6) | (static_cast<unsigned char>(*p++) & 0x3F); BOOST_FALLTHROUGH;
case 2: c = (c << 6) | (static_cast<unsigned char>(*p++) & 0x3F); BOOST_FALLTHROUGH;
case 3: c = (c << 6) | (static_cast<unsigned char>(*p++) & 0x3F); BOOST_NOWIDE_FALLTHROUGH;
case 2: c = (c << 6) | (static_cast<unsigned char>(*p++) & 0x3F); BOOST_NOWIDE_FALLTHROUGH;
case 1: c = (c << 6) | (static_cast<unsigned char>(*p++) & 0x3F);
}

View File

@@ -74,7 +74,7 @@ namespace nowide {
}
bool is_open()
{
return buf_->is_open();
return buf_.is_open();
}
bool is_open() const
{
@@ -134,7 +134,7 @@ namespace nowide {
}
bool is_open()
{
return buf_->is_open();
return buf_.is_open();
}
bool is_open() const
{
@@ -198,7 +198,7 @@ namespace nowide {
}
bool is_open()
{
return buf_->is_open();
return buf_.is_open();
}
bool is_open() const
{

View File

@@ -187,14 +187,13 @@ void test_codecvt_err()
wchar_t buf[4];
wchar_t *const to = buf;
wchar_t *const to_end = buf + 4;
wchar_t *to_next = to;
char const *err_utf = "1\xFF\xFF\xd7\xa9";
{
std::mbstate_t mb = std::mbstate_t();
char const *from = err_utf;
char const *from_end = from + std::strlen(from);
char const *from_next = from;
to_next = to;
wchar_t *to_next = to;
TEST(cvt.in(mb, from, from_end, from_next, to, to_end, to_next) == cvt_type::ok);
TEST(from_next == from + 5);
TEST(to_next == to + 4);
@@ -228,7 +227,6 @@ std::wstring codecvt_to_wide(std::string const &s)
std::locale l(std::locale::classic(), new boost::nowide::utf8_codecvt<wchar_t>());
cvt_type const &cvt = std::use_facet<cvt_type>(l);
std::vector<wchar_t> output(s.size() + 1);
std::mbstate_t mb = std::mbstate_t();
char const *from = s.c_str();
@@ -251,7 +249,6 @@ std::string codecvt_to_narrow(std::wstring const &s)
std::locale l(std::locale::classic(), new boost::nowide::utf8_codecvt<wchar_t>());
cvt_type const &cvt = std::use_facet<cvt_type>(l);
std::vector<wchar_t> output(s.size() + 1);
std::mbstate_t mb = std::mbstate_t();
wchar_t const *from = s.c_str();

View File

@@ -435,6 +435,37 @@ void test_fstream(const char *filename)
TEST(nw::remove(filename) == 0);
}
template<typename T>
bool is_open(T &stream)
{
// There are const and non const versions of is_open
// Test both
TEST(stream.is_open() == const_cast<const T &>(stream).is_open());
return stream.is_open();
}
template<typename T>
void do_test_is_open(const char *filename)
{
T f;
TEST(!is_open(f));
f.open(filename);
TEST(f);
TEST(is_open(f));
f.close();
TEST(f);
TEST(!is_open(f));
}
void test_is_open(const char *filename)
{
// Note the order: Output before input so file exists
do_test_is_open<nw::ofstream>(filename);
do_test_is_open<nw::ifstream>(filename);
do_test_is_open<nw::fstream>(filename);
TEST(nw::remove(filename) == 0);
}
int main(int, char **argv)
{
const std::string exampleFilename = std::string(argv[0]) + "-\xd7\xa9-\xd0\xbc-\xce\xbd.txt";
@@ -445,6 +476,7 @@ int main(int, char **argv)
test_ofstream_write(exampleFilename.c_str());
test_ifstream_open_read(exampleFilename.c_str());
test_fstream(exampleFilename.c_str());
test_is_open(exampleFilename.c_str());
std::cout << "Complex IO - Sanity Check" << std::endl;
// Don't use chars the std stream can't properly handle