64 Commits

Author SHA1 Message Date
191f3bb2f9 stream: check for address overflows in memory_stream
Signed-off-by: Simon Rozman <simon@rozman.si>
2025-05-27 11:55:07 +02:00
496dc9cb34 Revise ternary operators
Where test expression is already or almost boolean type, using ternery
operator is excessive and possibly more difficult to read.

Signed-off-by: Simon Rozman <simon@rozman.si>
2025-05-27 10:23:25 +02:00
1b8053f95c Revise lambda declarations
Signed-off-by: Simon Rozman <simon@rozman.si>
2025-04-16 10:34:11 +02:00
487f6fa922 Clear warning suppression
Code analysis got quite good and we'd better keep warnings on our radar.

Either:
1. Research and resolve the reason for the warning.
2. Remove silencing and let code analysis complain.
3. Comment why some warning silencing is there.

Signed-off-by: Simon Rozman <simon@rozman.si>
2025-04-03 16:15:27 +02:00
91c9a71a5d Resolve code analysis warnings
Signed-off-by: Simon Rozman <simon@rozman.si>
2025-03-28 17:28:19 +01:00
bfd8aaff65 Stop throwing in destructors
When exception processing is unwinding the stack, any exception thrown
in destructors end up std::terminate()-in our process.

Since all workarounds to report errors from destructors seems an
overkill, and the only important place where we should notify the user
about a failure is the stdex::stream::cache::~cache() (data loss occurs
when failure happens here), and if we'd throw in stdex::stream::cache::
~cache(), our process would get terminated anyway so the data loss is
inevitable, let's just silence this for now and come up with a better
solution later if we get smarter anytime in the future.

Signed-off-by: Simon Rozman <simon@rozman.si>
2025-03-06 22:15:45 +01:00
8fd9fbf191 Bump Copyright year
Signed-off-by: Simon Rozman <simon@rozman.si>
2025-01-08 12:36:35 +01:00
09123326c1 stream: add missing UTF-8 BOM
We want to ensure non-UTF8 configured Windows machines interpret our
source code correctly.

Signed-off-by: Simon Rozman <simon@rozman.si>
2024-11-11 12:24:32 +01:00
0ae7fb6c7c stream: use indexing operator for pointer arithmetics 2024-10-22 17:25:54 +02:00
4477706f06 stream: trun off false-positive Xcode analysis warning 2024-10-22 17:24:56 +02:00
16e2384419 system: add safearray_accessor_with_size
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-10-18 23:47:10 +02:00
9fb899849d stream: weasel around false-positive GCC warning
As _countof is manually implemented on non-Windows platforms, GCC
knows it returns size_t, but fails to realize it will never be more than
0x400 in our case making truncation harmless.

Signed-off-by: Simon Rozman <simon@rozman.si>
2024-09-30 13:30:13 +02:00
5436dda7f6 assert: initial version
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-05-28 10:22:24 +02:00
3d3b7565bf socket: add missing namespace
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-04-22 13:56:10 +02:00
a70db017b0 stream: fix spelling
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-04-22 08:57:19 +02:00
0a719e3081 Xcode: turn on and resolve all warnings 2024-02-14 15:05:41 +01:00
0560c7bce9 Add missing UTF-8 BOM
This is required on Windows with default charset set to Windows-1252 or
another non-UTF-8 charset.

Signed-off-by: Simon Rozman <simon@rozman.si>
2024-02-14 12:33:29 +01:00
8ac0efa85d Xcode: resolve -Wsign-compare
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-02-14 12:28:39 +01:00
681a6955d8 Xcode: resolve -Wunknown-pragmas
This is a multi-platform project and while trying to reduce amount of

Signed-off-by: Simon Rozman <simon@rozman.si>
2024-02-14 12:26:52 +01:00
08a18d1519 macOS support
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-02-08 12:09:33 +01:00
ab94d7014f stream: cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-01-16 08:24:37 +01:00
38c6b40b21 Bump Copyright year
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-01-06 10:55:09 +01:00
37891e8a2a Simplify and unify template parameter naming
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:08 +01:00
2e65d0351c Trim excessive inline
Methods and templates are implicitly marked as inline already.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-11 11:33:27 +01:00
7eba65813e stream: fix cache::read() to return state_t::eof correctly
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-11 09:55:20 +01:00
d5bf60447b Cleanup 2023-12-08 16:22:09 +01:00
2440e5baca Cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-07 18:41:55 +01:00
8fc9a7e56b stream: allow invalid handle detection in cached_file
Otherwise one cannot distinguish between file open but in failed state
and file not open.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-06 15:25:48 +01:00
9967b41eae stream: make memory_file properly copyable and movable
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-06 11:02:12 +01:00
976662415b stream: unify size method and make it const
diag_file::size() was setting the m_state and returning 0 on error,
which violated original size() convention not to change stream state and
to return fsize_max on error.

Changing m_state prevented declaring size() method as const before.

cache::seek() was missing size() return value check.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-01 14:11:02 +01:00
3dfd62ec2f socket: add own cross-platform declaration
Like with stdex::locale_t, this frees us from using Windowsizms on other
platforms. Sockets came from Unix to Windows and not the other way
around in the first place.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-09 09:25:42 +01:00
2c45749f78 string, locale: make stdex::locale(_t) independent .hpp file
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-09 08:12:31 +01:00
ee8f54ee5f Fix to compile for Linux
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-08 13:48:41 +01:00
16a86cf350 Add #include wrapper to fix min/max <Windows.h> mess
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-18 12:51:49 +02:00
856be3a0d8 Revise #include to make each .hpp individually compilable
Mind that min/max Windows.h mess is Microsoft's problem, not ours.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-18 09:12:06 +02:00
a469860382 stream: revise cache init and cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:08 +02:00
00b05092af stream: reuse converter R/W methods
Where we need to read from/write to m_source and immediately apply its
state to our converter, we already have methods for this.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:08 +02:00
47e63b1f32 Use lambda as trampoline to simplify thread functions
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:08 +02:00
7cd4d099ff stream: cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:08 +02:00
ab8d37ee75 Turn assert() into _Analysis_assume_ on Release builds
While runtime asserts also served as MSVC Code Analysis hints, the lack
of asserts in Release builds provides no hints to Code Analysis which
rises a lot of warnings then.

Maybe I should learn how to use SAL to annotate <ptr, len> parameter
pairs to allow ptr==nullptr when and only when len==0? 😇

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00
36012a107b stream: cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00
b791621a2a stream: make std:thread member rather than derive from it
When deriving, C++ might believe the derived class is still movable. But
it's not and rather than deleting move constructor and operator, this
approach made simpler code.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00
9365f0252c stream: add socket
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00
e61720598f stream: revise string reading and writing
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00
86e7ed3690 stream: add support for collection reading and writing
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:06 +02:00
49b741c94f Replace errno_error with std::system_error
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-01 23:09:50 +02:00
b724ce1333 stream: fix wchar_t/UTF-16 confusion and revise readln and write_array
On non-Windows, wchar_t is UTF-32.  This adds preliminary support for UTF-32
and changes readln and write_array members to use charset_encoder for better
performance on non-Windows platforms.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-22 13:04:41 +02:00
6689aa5210 stream: add file::exists and file::readonly
We are targeting C++14, while C++17 already has std::filesystem::exists. 😢

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-20 13:00:20 +02:00
dcfc4752b5 stream: add stdex::sstring method variants 2023-09-20 12:09:58 +02:00
475e6734a7 stream: extend open/create disposition flags
User could not create file only if it did not exist.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-20 11:13:16 +02:00