Skip to content

Commit 927afad

Browse files
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 <[email protected]>
1 parent cdae258 commit 927afad

File tree

7 files changed

+12
-10
lines changed

7 files changed

+12
-10
lines changed

Release/include/cpprest/producerconsumerstream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class basic_producer_consumer_buffer : public streams::details::streambuf_state_
4747
/// </summary>
4848
basic_producer_consumer_buffer(size_t alloc_size)
4949
: streambuf_state_manager<_CharType>(std::ios_base::out | std::ios_base::in)
50+
, m_mode(std::ios_base::in)
5051
, m_alloc_size(alloc_size)
5152
, m_allocBlock(nullptr)
5253
, m_total(0)

Release/src/http/listener/http_server_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void http_server_api::unregister_server_api()
5050
throw http_exception(_XPLATSTR("Server API was cleared while listeners were still attached"));
5151
}
5252

53-
s_server_api.release();
53+
s_server_api.reset();
5454
}
5555

5656
void http_server_api::unsafe_register_server_api(std::unique_ptr<http_server> server_api)

Release/src/http/listener/http_server_httpsys.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ using namespace http::details;
3232
using namespace http::experimental::listener;
3333
using namespace http::experimental::details;
3434

35-
#define CHUNK_SIZE 64 * 1024
35+
#define CHUNK_SIZE (64 * 1024)
3636

3737
namespace web
3838
{

Release/src/pch/stdafx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
// Windows Header Files:
4141
#ifndef __cplusplus_winrt
4242
#include <winhttp.h>
43-
#endif !__cplusplus_winrt
43+
#endif // !__cplusplus_winrt
4444

4545
#else // LINUX or APPLE
4646
#define __STDC_LIMIT_MACROS

Release/src/streams/fileio_win32.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void CALLBACK IoCompletionCallback(PTP_CALLBACK_INSTANCE instance,
111111

112112
EXTENDED_OVERLAPPED* pExtOverlapped = static_cast<EXTENDED_OVERLAPPED*>(pOverlapped);
113113
pExtOverlapped->func(result, static_cast<DWORD>(numberOfBytesTransferred), static_cast<LPOVERLAPPED>(pOverlapped));
114-
delete pOverlapped;
114+
delete pExtOverlapped;
115115
}
116116
#endif
117117

@@ -399,10 +399,10 @@ size_t _write_file_async(_In_ streams::details::_file_info_impl* fInfo,
399399

400400
size_t result = static_cast<size_t>(-1);
401401

402-
if (wrResult == TRUE)
402+
if (wrResult)
403403
{
404404
// If WriteFile returned true, it must be because the operation completed immediately.
405-
// However, we didn't pass in an address for the number of bytes written, so
405+
// However, we didn't pass in an address for the number of bytes written, so
406406
// we have to retrieve it using 'GetOverlappedResult,' which may, in turn, fail.
407407
DWORD written = 0;
408408
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,
496496

497497
size_t result = static_cast<size_t>(-1);
498498

499-
if (wrResult == TRUE)
499+
if (wrResult)
500500
{
501501
// If ReadFile returned true, it must be because the operation completed immediately.
502502
// 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
941941

942942
LARGE_INTEGER size;
943943

944-
if (GetFileSizeEx(fInfo->m_handle, &size) == TRUE)
944+
if (GetFileSizeEx(fInfo->m_handle, &size))
945945
return utility::size64_t(size.QuadPart / char_size);
946946
else
947947
return 0;

Release/src/utilities/asyncrt_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ datetime __cdecl datetime::from_string(const utility::string_t& dateString, date
11481148
{
11491149
tzHours = 8;
11501150
}
1151-
else if ((tzCh == _XPLATSTR('+') || tzCh == _XPLATSTR('-')) && ascii_isdigit2(str[1]) &&
1151+
else if ((str[0] == _XPLATSTR('+') || str[0] == _XPLATSTR('-')) && ascii_isdigit2(str[1]) &&
11521152
ascii_isdigit(str[2]) && ascii_isdigit5(str[3]) && ascii_isdigit(str[4]))
11531153
{
11541154
tzCh = str[0];

Release/tests/functional/utils/datetime.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ SUITE(datetime)
304304
_XPLATSTR("01 Jan 1971 00:00:61 GMT"),
305305
_XPLATSTR("01 Jan 1899 00:00:00 GMT"), // underflow
306306
_XPLATSTR("01 Jan 1969 00:00:00 CEST"), // bad tz
307-
_XPLATSTR("01 Jan 1970 00:00:00 +2400"), // bad tzoffsets
307+
_XPLATSTR("14 Jan 2019 23:16:21 G0100"), // bad tzoffsets
308+
_XPLATSTR("01 Jan 1970 00:00:00 +2400"),
308309
_XPLATSTR("01 Jan 1970 00:00:00 -3000"),
309310
_XPLATSTR("01 Jan 1970 00:00:00 +2160"),
310311
_XPLATSTR("01 Jan 1970 00:00:00 -2400"),

0 commit comments

Comments
 (0)