Static analyzer (PVS Studio) fixes (#1372)

* [init] Initialize stream mode to in by default

* [leak] Fix memory leak of server api ptr

Should call delete on pointer instead of releasing it to the caller.

* [macro] Ensure priority of macro computation

Enclose macro args in round brackets to ensure operators priority.

* [prep] Fix comment after preprocessor macro

* [ub] Use typed pointer in delete operation

* Delete of void pointer is UB.  See section 5.3.5/3.  SO question:
https://stackoverflow.com/questions/941832/is-it-safe-to-delete-a-void-pointer
* Windows APIs used here return FALSE in case of failure, and
non-FALSE on success.  There is no info in spec that only TRUE
value indicates success.  Correct way to implement check for
success call is to compare with false like result != FALSE.

* [fmt] Fix military RFC1123 time format parsing

Ensure + or - sign is used for time zone offset in RFC1123 military
time format.

* Remove redundant != FALSE.

Co-authored-by: Billy Robert O'Neal III <bion@microsoft.com>
This commit is contained in:
Dmitry Tsarevich 2020-04-01 02:02:07 +03:00 коммит произвёл GitHub
Родитель cdae258bfb
Коммит 927afad909
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 12 добавлений и 10 удалений

Просмотреть файл

@ -47,6 +47,7 @@ public:
/// </summary>
basic_producer_consumer_buffer(size_t alloc_size)
: streambuf_state_manager<_CharType>(std::ios_base::out | std::ios_base::in)
, m_mode(std::ios_base::in)
, m_alloc_size(alloc_size)
, m_allocBlock(nullptr)
, m_total(0)

Просмотреть файл

@ -50,7 +50,7 @@ void http_server_api::unregister_server_api()
throw http_exception(_XPLATSTR("Server API was cleared while listeners were still attached"));
}
s_server_api.release();
s_server_api.reset();
}
void http_server_api::unsafe_register_server_api(std::unique_ptr<http_server> server_api)

Просмотреть файл

@ -32,7 +32,7 @@ using namespace http::details;
using namespace http::experimental::listener;
using namespace http::experimental::details;
#define CHUNK_SIZE 64 * 1024
#define CHUNK_SIZE (64 * 1024)
namespace web
{

Просмотреть файл

@ -40,7 +40,7 @@
// Windows Header Files:
#ifndef __cplusplus_winrt
#include <winhttp.h>
#endif !__cplusplus_winrt
#endif // !__cplusplus_winrt
#else // LINUX or APPLE
#define __STDC_LIMIT_MACROS

Просмотреть файл

@ -111,7 +111,7 @@ void CALLBACK IoCompletionCallback(PTP_CALLBACK_INSTANCE instance,
EXTENDED_OVERLAPPED* pExtOverlapped = static_cast<EXTENDED_OVERLAPPED*>(pOverlapped);
pExtOverlapped->func(result, static_cast<DWORD>(numberOfBytesTransferred), static_cast<LPOVERLAPPED>(pOverlapped));
delete pOverlapped;
delete pExtOverlapped;
}
#endif
@ -399,10 +399,10 @@ size_t _write_file_async(_In_ streams::details::_file_info_impl* fInfo,
size_t result = static_cast<size_t>(-1);
if (wrResult == TRUE)
if (wrResult)
{
// If WriteFile returned true, it must be because the operation completed immediately.
// However, we didn't pass in an address for the number of bytes written, so
// However, we didn't pass in an address for the number of bytes written, so
// we have to retrieve it using 'GetOverlappedResult,' which may, in turn, fail.
DWORD written = 0;
result = GetOverlappedResult(fInfo->m_handle, pOverlapped.get(), &written, FALSE) ? static_cast<size_t>(written)
@ -496,7 +496,7 @@ size_t _read_file_async(_In_ streams::details::_file_info_impl* fInfo,
size_t result = static_cast<size_t>(-1);
if (wrResult == TRUE)
if (wrResult)
{
// If ReadFile returned true, it must be because the operation completed immediately.
// However, we didn't pass in an address for the number of bytes written, so
@ -941,7 +941,7 @@ utility::size64_t __cdecl _get_size(_In_ concurrency::streams::details::_file_in
LARGE_INTEGER size;
if (GetFileSizeEx(fInfo->m_handle, &size) == TRUE)
if (GetFileSizeEx(fInfo->m_handle, &size))
return utility::size64_t(size.QuadPart / char_size);
else
return 0;

Просмотреть файл

@ -1148,7 +1148,7 @@ datetime __cdecl datetime::from_string(const utility::string_t& dateString, date
{
tzHours = 8;
}
else if ((tzCh == _XPLATSTR('+') || tzCh == _XPLATSTR('-')) && ascii_isdigit2(str[1]) &&
else if ((str[0] == _XPLATSTR('+') || str[0] == _XPLATSTR('-')) && ascii_isdigit2(str[1]) &&
ascii_isdigit(str[2]) && ascii_isdigit5(str[3]) && ascii_isdigit(str[4]))
{
tzCh = str[0];

Просмотреть файл

@ -304,7 +304,8 @@ SUITE(datetime)
_XPLATSTR("01 Jan 1971 00:00:61 GMT"),
_XPLATSTR("01 Jan 1899 00:00:00 GMT"), // underflow
_XPLATSTR("01 Jan 1969 00:00:00 CEST"), // bad tz
_XPLATSTR("01 Jan 1970 00:00:00 +2400"), // bad tzoffsets
_XPLATSTR("14 Jan 2019 23:16:21 G0100"), // bad tzoffsets
_XPLATSTR("01 Jan 1970 00:00:00 +2400"),
_XPLATSTR("01 Jan 1970 00:00:00 -3000"),
_XPLATSTR("01 Jan 1970 00:00:00 +2160"),
_XPLATSTR("01 Jan 1970 00:00:00 -2400"),