Commit Graph

31 Commits

Author SHA1 Message Date
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
Louis Gombert
3372c9b584
Merge pull request #294 from phlash/case-insensitive-files
Support case-insensitive loading of content files
2024-05-06 22:17:03 +00:00
Azamat H. Hackimov
096cd84991 Cleanup hogfile code
Remove unused code related to old HogUtils executable, now superseded by HogMaker.
Stricter checks for hog header and hog file entry (check fread() sizes).
2024-05-06 22:50:07 +03:00
Phil Ashby
24e9b50779 Do not attempt case-sensitive processing on Windows 2024-05-06 19:08:31 +01:00
Phil Ashby
583aac6471 Movies now load from case-insensitive file names 2024-05-06 18:49:39 +01:00
Phil Ashby
b5ba5f2a91 Support case-insensitive loading of HOG files 2024-05-06 17:52:45 +01:00
Ryan C. Gordon
6c8977caf0
Heavy patching for compiler warnings.
The vast majority of this is fixing up `char *` that should be `const char *`
but a handful of other fixes, like potential buffer overflows that GCC
noticed, etc, were applied as well.

This removes `-Wno-write-strings` from CMakeLists.txt, as it is no longer
necessary, as there is no longer a flood of compiler warning spam when
building.

This does not fix all compiler warnings; there are still a handful, and they
are legitimate, but they can be dealt with in a future commit.
2024-04-29 00:18:56 -04:00
Chris Sarbora
1bc5648a9a
Remove MacOS (Classic) code and all references (3/3)
At this point, all remaining references to `MACINTOSH` are either part
of multi-value conditionals that `unifdef` was unable to determine the
final value for, or a `#define`, or a comment. I manually go through the
files with a Ctrl+Shift+F search (ignoring legacy/, to preserve useful
historic knowledge) and clean up each usage.

As part of that search, I discovered `lib/mac/` which I deleted wholly.

Test Plan:
On Mac, build both Debug and Release
```
cmake --build --preset mac --config Debug
cmake --build --preset mac --config Release
```
2024-04-27 07:44:40 -07:00
Chris Sarbora
e6ba1906c9
Remove MacOS (Classic) code and all references (1/3)
The MACINTOSH define refers to MacOS Classic (not OS X) which we do not
plan to support. Rather than carry the cruft forever, let's delete it.

NOTE: legacy/ is unused but we're keeping it around, so MACINTOSH uses
there are left alone.

Process used for this commit:
```
git rm -r mac
find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" \) \
  -exec unifdef -UMACINTOSH -o {} {} \;
git restore legacy
git add .
```

Test Plan:
On Mac, build both Debug and Release
```
cmake --build --preset mac --config Debug
cmake --build --preset mac --config Release
```
2024-04-27 07:38:14 -07:00
Azamat H. Hackimov
4826c37a69 Add BUILD_INTERFACE to cfile module
Other modules that depends on it, can reuse includes on linking.
There some files formally not belonging any packages (lib directory), as workaround there temporary include_directories(cfile) on root of project. After migrating all modules this can be removed.
2024-04-24 00:41:02 +03:00
Azamat H. Hackimov
63b4284658 Fix float reading in cfile
Whoah, big surprise float_t and double_t may have different length. Still waiting float32_t and float64_t types from C++23...
2024-04-24 00:40:41 +03:00
Azamat H. Hackimov
16464ee81a Fix regression in cf_ReadByte()
cfgetc returns int on success read, but if cast it to int8_t too early, 255 will become -1, or EOF.
2024-04-24 00:40:41 +03:00
Azamat H. Hackimov
c275d359c7 Reapply "Cfile module update"
This reverts commit 066b436fd9.
2024-04-24 00:40:39 +03:00
Thomas Otto
00389c50ea Some more CMake white space formatting
- tabs to spaces
 - use Unix line endings everywhere
 - newline at end of file
 - remove trailing white space
 - no space between keywords and opening parenthesis
 - use 2 spaces to indent
2024-04-21 11:46:32 +02:00
Kevin Bentley
1f45163248 Updated source to reflect the license that this code is released under. 2024-04-20 09:57:49 -06:00
Louis Gombert
c2b71b8147 Standardize CMake formatting
lowercase function names, blocks indent
2024-04-20 14:45:49 +02:00
C.W. Betts
7d7f5bf896 Quiet Clang Static Analyzer warnings.
Most of the warnings were caused by uninitialized values. Some were in plug-ins that didn't have a break in a switch, causing the memory to be deleted twice.
2024-04-19 17:42:17 -06:00
C.W. Betts
57078ae4b5 Change most sprintf to snprintf.
This also includes vsprintf to vsnprintf.
2024-04-19 12:31:28 -06:00
C.W. Betts
c88af830e6 Fix endian read-write for doubles. 2024-04-18 23:35:58 -06:00
Dan Raviv
aaefe86a2a Fix cf_SetSearchPath bad memory access (tested on macOS) 2024-04-18 10:33:21 -07:00
C.W. Betts
f9b8ff78ed
Update CFILE.cpp
add missing va_end
2024-04-17 19:16:39 -06:00
Azamat H. Hackimov
9e6ebbc8fb Remove dublicate byteswap.h
Linux-specific byteswap.h just includes BYTESWAP.H, so there no need platform-specific header.

Fixes "non-portable path to file" ([-Wnonportable-include-path]) warnings.
2024-04-18 03:20:36 +03:00
Thomas Otto
b909a4cf43 Convert min/max macros to std::min/max
Added explicit <float> or <int> template argument where needed.
Add -DNOMINMAX define for Windows.
2024-04-17 21:43:38 +02:00
Jeff Slutter
69a2e15625 Committing local fixes and changes I had. 2024-04-16 22:53:28 -05:00
Azamat H. Hackimov
38128ea134 Additional clang-format 2024-04-17 00:25:04 +03:00
Kevin Bentley
61be1317b2 More clanging 2024-04-16 14:46:12 -06:00
Kevin Bentley
c6640cc631 clang-format on everything. 2024-04-16 12:56:40 -06:00
Kevin Bentley
df209742fc Initial import 2024-04-15 21:43:29 -06:00