Jan Engelhardt
3c9234c4c0
mem_malloc type triviality checks (8/8)
...
(Manual modification.) Change mem_malloc callsites with
non-fundamental types to mem_rmalloc.
2024-09-16 22:12:14 +02:00
Jan Engelhardt
c7da9daee2
mem_malloc type triviality checks (2/8)
...
Automated replacement with
```
git grep -l mem_malloc |
xargs perl -i -lpe 's{\((\w+) \*\)mem_malloc\(sizeof\(\1\) \* (\S+)\)}{mem_rmalloc<$1>($2)}'
```
2024-09-16 22:12:12 +02:00
Louis Gombert
705c67a1be
Merge pull request #546 from winterheart/logging
...
Enhance logging facility
2024-09-10 09:27:13 +02:00
Azamat H. Hackimov
9d2aaf12f2
Convert cfile to use new logging facility
2024-09-10 03:00:25 +03:00
Jan Engelhardt
69dbf5bca7
Resolve alloc-dealloc-mismatch in CFile::FreeSymbols
...
==89545==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs operator delete) on 0x5020001007f0
f0 operator delete(void*, unsigned long) (/lib64/libasan.so.8+0xfe1f8)
f1 InfFile::FreeSymbols() $GIT/cfile/inffile.cpp:63
f2 InfFile::Close() $GIT/cfile/inffile.cpp:115
f3 LoadServerConfigFile() $GIT/Descent3/dedicated_server.cpp:355
0x5020001007f0 is located 0 bytes inside of 11-byte region [0x5020001007f0,0x5020001007fb)
allocated by thread T0 here:
f0 operator new[](unsigned long) (/lib64/libasan.so.8+0xfd458)
f1 InfFile::AddSymbol(char const*, char const*) $GIT/cfile/inffile.cpp:49
f2 InfFile::ParseLine(char*, int) $GIT/cfile/inffile.cpp:187
2024-09-09 10:38:17 +02:00
Jan Engelhardt
5f0bdf8184
Fix spello "it's"
2024-09-03 13:26:51 +02:00
Jan Engelhardt
571c0199e9
Resolve use-after-free in cf_CopyFile
...
==92396==ERROR: AddressSanitizer: heap-use-after-free on address 0x504000034ae8 at pc 0x000000f86037 bp 0x7fffffffa9d0 sp 0x7fffffffa9c8
READ of size 4 at 0x504000034ae8 thread T0
f0 cf_CopyFile(std::filesystem::__cxx11::path const&, std::filesystem::__cxx11::path const&, int) $GIT/cfile/cfile.cpp:856
f1 _extractscript(char*, char*) $GIT/Descent3/OsirisLoadandBind.cpp:3109
f2 Osiris_ExtractScriptsFromHog(int, bool) $GIT/Descent3/OsirisLoadandBind.cpp:3185
f3 InitIOSystems $GIT/Descent3/init.cpp:1549
f4 InitD3Systems1(bool) $GIT/Descent3/init.cpp:1827
2024-08-30 01:25:56 +02:00
Azamat H. Hackimov
79db9aa3e2
Move platform-specific defines and macros to own file crossplat.h
2024-08-20 23:09:27 +03:00
Thomas Roß
bdf992a8fd
[CMake] Add cfile tests to 'tests' folder in IDEs.
2024-08-20 20:03:02 +02:00
Azamat H. Hackimov
b911d81c2a
LINUX: Use ddio_DoForeachFile()
...
Replace ddio_FindFileStart() with ddio_DoForeachFile().
2024-08-15 11:47:43 +03:00
Louis Gombert
60c5dbf1fe
CMake: add all headers to target sources
...
This can help with CMake IDE integration and file indexing.
2024-08-09 17:09:14 +02:00
Chris Sarbora
3da53e567f
Programmatically replace all __LINUX__
with POSIX
...
Steps:
```sh
srcs=$(mktemp)
find . -name "*.cpp" -or -name "*.c" -or -name "*.h" -or -name "*.hpp" -or -name "*.cc" -or -name "*.hh" > $srcs
xargs sed -i 's/ifndef __LINUX__/if !defined(POSIX)/' < $srcs
xargs sed -i 's/ifdef __LINUX__/if defined(POSIX)/' < $srcs
xargs sed -i 's/defined(__LINUX__)/defined(POSIX)/' < $srcs
```
2024-07-12 18:11:54 -05:00
Louis Gombert
de75a80ae7
Merge pull request #475 from winterheart/cfile-std-filesystem
...
cfile / ddio: use most of functions to std::filesystem::path
2024-07-06 23:25:12 +00:00
Azamat H. Hackimov
2fce643ae8
Use case-insensitive search for cf_OpenLibrary() on all platforms
2024-07-05 01:50:57 +03:00
Azamat H. Hackimov
7a1f08e811
Fix unittests on macOS
...
Surprisingly on macOS FS is case-insensitive.
2024-07-05 01:50:57 +03:00
Azamat H. Hackimov
b3affdb105
Use new cf_FindRealFileNameCaseInsensitive() function in code
...
A little speed-up for our slowpoke.
2024-07-05 01:50:57 +03:00
Azamat H. Hackimov
1a3c012228
Refactor cf_FindRealFileNameCaseInsensitive() function
...
Implementing cf_FindRealFileNameCaseInsensitive_new() based on std::fs::directory_iterator, which runs faster and more reliable.
cf_FindRealFileNameCaseInsensitive_new() works exactly as cf_FindRealFileNameCaseInsensitive().
Benchmark on Release build:
```
-------------------------------------------------------------------
Benchmark Time CPU Iterations
-------------------------------------------------------------------
cfile_no_exist_old 11607 ns 11399 ns 63035
cfile_no_exist_new 9302 ns 9196 ns 70041
cfile_exist_relative_old 2701 ns 2480 ns 282695
cfile_exist_relative_new 867 ns 866 ns 798478
cfile_exist_absolute_old 3415 ns 3167 ns 228323
cfile_exist_absolute_new 1182 ns 1181 ns 574782
```
2024-07-05 01:50:57 +03:00
Azamat H. Hackimov
f44f6a4bbd
CFILE: change signature of cf_FindRealFileNameCaseInsenstive()
...
Moved directory parameter to 3rd position and make it optional.
2024-07-05 01:50:57 +03:00
Azamat H. Hackimov
65520373e6
CFILE: Remove duplicated code in open_file_in_directory()
...
Refactoring platform-dependent parts of code into common part, greatly reduce LOC.
2024-07-05 01:50:57 +03:00
Azamat H. Hackimov
c5712208f6
CFILE: Additional unit tests for cfile functions
2024-07-05 01:50:57 +03:00
Azamat H. Hackimov
15ec76dd64
CFILE: Change cf_FindRealFileNameCaseInsenstive() to use std::fs::path
2024-07-05 01:50:57 +03:00
Azamat H. Hackimov
dad20b0830
CFILE: Add unittest framework
2024-07-05 01:50:57 +03:00
C.W. Betts
21e1384a3c
Create an overloaded cf_ReadInt and cf_ReadShort that takes a bool to indicate little endian reads.
...
As suggested by @winterheart
2024-07-02 18:34:45 -06:00
Azamat H. Hackimov
81555afd15
CFILE: convert cf_Diff() to use std::fs::path
...
Convert cf_Diff() and underlying functions to use std::filesystem::path
2024-07-01 12:50:49 +03:00
Azamat H. Hackimov
c47210be75
CFILE: convert cf_CopyFile() cf_CopyFileTime() to use std::fs::path
...
Convert cf_CopyFile() cf_CopyFileTime() and underlying functions to use std::filesystem::path
2024-07-01 12:50:49 +03:00
Azamat H. Hackimov
8d14ae025c
CFILE: migrate more functions to use std::fs::path
...
Convert cf_IsFileInHog(), cf_OpenFileInLibrary() and cf_GetfileCRC() functions to use std::fs::path.
2024-07-01 12:50:49 +03:00
Azamat H. Hackimov
0ea758084f
CFILE: refactor internal paths and extensions
...
Refactor paths and extensions to use std::map. Rewriting related code in manage.cpp.
2024-07-01 12:50:48 +03:00
Azamat H. Hackimov
33e8802363
CFILE: make path_entry
struct using std::fs::path
...
Simplify related code in `cf_SetSearchPath()`.
2024-07-01 12:50:48 +03:00
Azamat H. Hackimov
82084e9176
Convert some of cfile functions to use std::filesystem
...
Make cfopen(), open_file_in_directory() and cfexist() use std::filesystem::path arguments.
2024-07-01 12:50:48 +03:00
Azamat H. Hackimov
59487976f6
Isolate misc module
...
Isolate misc module for better dependency handling.
2024-06-27 01:26:35 +03:00
Azamat H. Hackimov
db8aa64d2f
Make mem module isolated from project
...
Properly define MEM_USE_RTL definition only for mem library. Link other dependant modules with mem.
2024-06-20 00:43:51 +03:00
GravisZro
1c7e3053f2
Replace "PSPATHNAME_LEN" and "MAX_PATH" with "_MAX_PATH"
2024-06-01 22:19:41 -04:00
GravisZro
f7ae658fe2
Modernize struct/enum/unions type declarations
2024-05-30 03:35:17 -04:00
GravisZro
9cf9781369
Properly format/use variadic macros
2024-05-24 20:57:17 -04:00
Azamat H. Hackimov
a0929aefe2
Rename ddio_common to ddio
2024-05-24 22:18:14 +03:00
Azamat H. Hackimov
6bc3c71a83
Reordering ddio_common module
...
Merge ddio_lnx and ddio_win into ddio_common module.
2024-05-24 22:17:44 +03:00
GravisZro
5e5e0c99c3
Replace "short" with "int16_t" and fix missing headers
2024-05-23 23:49:31 -04:00
GravisZro
26b7776f43
Replace "ubyte" with "uint8_t"
2024-05-23 23:07:26 -04:00
GravisZro
1618040db5
Replace "unsigned char" with "uint8_t"
2024-05-23 22:58:46 -04:00
GravisZro
2147cfa68b
Replace "unsigned int" with "uint32_t"
2024-05-23 22:51:16 -04:00
Azamat H. Hackimov
3fa32ff386
Reorder headers related to linux module
2024-05-19 12:21:43 +03:00
Azamat H. Hackimov
43caa3d53c
CFILE: Remove throwing exception in cf_ReadBytes()
...
All functions, that uses cf_ReadBytes(), checks return size, but don't handle potential exceptions. That leads to segfaults on reading of damaged files (i.e. broken savegames).
2024-05-16 23:27:56 +03:00
Azamat H. Hackimov
c505df182b
CFILE: Use smart pointers for entries of library
2024-05-16 23:12:07 +03:00
Azamat H. Hackimov
f123dbe770
Replacing raw pointer with shared_ptr in cfile.
2024-05-16 22:31:43 +03:00
Azamat H. Hackimov
b84678de96
Move HOG2 magic check into hogfile
...
Remove unused cf_ReadHogFileEntry() function.
2024-05-16 19:18:31 +03:00
Azamat H. Hackimov
6703b25d34
Minor fixes to cfile
2024-05-16 18:21:30 +03:00
Jason Yundt
d5e893fcb4
Prevent potential uninitialized memory access
...
Before this change, cf_OpenLibrary() did something along the lines of
this:
char id[4];
fread(id, 4, 1, fp);
strncmp(id, "HOG2", 4);
If fread() finishes successfully, then that code is fine. However,
fread() might encounter an error or bump into the end of a file. In
those scenarios, the value of id will not necessarily be initialized
[1]. In other words, when fread() fails, strncmp() might operate on
uninitialized memory.
This change makes sure that the value of id only gets used if fread()
succeeds. Additionally, this change fixes a GCC warning about ignoring
fread()’s return value.
[1]: <https://en.cppreference.com/w/cpp/io/c/fread >
2024-05-12 20:38:35 -04:00
Jason Yundt
e042925001
Stop using hard coded value for HOG2 id length
...
Before this change, cf_OpenLibrary() was inconsistent. Sometimes, it
would refer to the size of a HOG2 id using the literal 4. Other times it
would refer to the size of a HOG2 id using strlen(HOG_TAG_STR). There
was a good reason for this. Some compilers allow you to do this:
char id[strlen(HOG_TAG_STR)];
Other compilers throw an error if you try to do that [1].
This commit makes cf_OpenLibrary() more consistent. It makes it so that
cf_OpenLibrary() always uses the same constant expression when referring
to HOG_TAG_STR’s length.
[1]: <https://devblogs.microsoft.com/oldnewthing/20221114-00/?p=107393 >
2024-05-12 20:38:32 -04:00
JeodC
a4ab78192c
Join license header with historical commentrs
...
Join the license header with historical comments using a separator so IDEs can correctly parse the initial header.
Also use .gitattributes to ensure all files are LF.
2024-05-08 14:41:19 -04:00
C.W. Betts
c6da74b069
Mark functions and variables as static ( #185 )
...
* Begin by marking functions and variables as static when needed.
* More work.
* More work.
* More pokes.
* More work.
* More work.
* Initial work on the netgames.
* Revert changes to the license header on source files.
* clutter.cpp poke.
* One final poke.
* Move some declarations to headers:
Move paged_in_count and paged_in_num to gamesequence.h
Move DoneLightInstance and StartLightInstance to polymodel.h
* Look over the AI script/plug-ins.
* Going over the changes one last time.
* Fix rebase errors.
* More migration from bare statics to static inlines.
2024-05-07 23:35:28 +02:00