Commit Graph

22 Commits

Author SHA1 Message Date
David Korth
6765222c58 [unice68] unice68.c, exactread(): Fix a missing printf() format parameter.
Fixes two CodeQL warnings:
- Incorrect format parameter.
- Too few format parameters.
2025-04-15 22:29:53 -04:00
David Korth
2529100c11 [unice68] unice68.c: Fix some 64-bit compile warnings.
Ideally, we'd make it use size_t for all size parameters, but this is
old code, and doing that would require going through a lot of stuff,
so just cast it to int for now.

FIXME: unice68 is expecting fread() and fwrite() to return -1 on error,
but these functions return size_t, which is unsigned...
2025-04-11 18:28:19 -04:00
David Korth
cc3a501ae6 [unice68] unice68.c, set_binary_mode(): Suppress unused variable warnings. 2025-04-06 18:56:41 -04:00
David Korth
f0647da5eb Remove CheckHiddenVisibility.cmake.
The root CMakeLists.txt has a minimum CMake version of 3.5, and
CheckHiddenVisibility.cmake's workarounds are only needed for
CMake 3.2 and earlier.

Set CMP0063 unconditionally (added in CMake 3.3) and set the
CMAKE_<LANG>_VISIBILITY_PRESET and CMAKE_VISIBILITY_INLINES_HIDDEN
variables where CHECK_HIDDEN_VISIBILITY() was called before.

There should effectively be no code changes with this commit.
2025-01-18 22:34:24 -05:00
David Korth
d470035e61 Switch to CMake's POSITION_INDEPENDENT_CODE property instead of manually adding "-fpic -fPIC".
Something changed that caused the build on Xubuntu 16.04 (32-bit) to fail:

[ 63%] Linking CXX shared library ../../lib/libromdata.so
/usr/bin/ld: read-only segment has dynamic IFUNC relocations; recompile with -fPIC
/usr/bin/ld: failed to set dynamic section sizes: Bad value
collect2: error: ld returned 1 exit status
src/libromdata/CMakeFiles/romdata.dir/build.make:3614: recipe for target 'lib/libromdata.so.6.0' failed
make[2]: *** [lib/libromdata.so.6.0] Error 1

Setting POSITION_INDEPENDENT_CODE instead of "-fpic -fPIC" fixes this.

[extlib] Correctly set properties on the 'mspack' target instead of
'libmspack'. Otherwise, libmspack won't have either EXCLUDE_FROM_ALL
or POSITION_INDEPENDENT_CODE.
2025-01-05 14:02:13 -05:00
David Korth
33edbb9f9a [unice68] unice68_pack.c: Explicitly cast dreg_t conversions.
Fixes the following 64-bit MSVC warnings:

unice68_pack.c(243,43): warning C4244: '=': conversion from '__int64' to 'dreg_t', possible loss of data
unice68_pack.c(319,28): warning C4244: '=': conversion from '__int64' to 'dreg_t', possible loss of data
unice68_pack.c(325,36): warning C4244: '=': conversion from '__int64' to 'dreg_t', possible loss of data
unice68_pack.c(456,40): warning C4244: '=': conversion from '__int64' to 'dreg_t', possible loss of data
unice68_pack.c(488,36): warning C4244: '=': conversion from '__int64' to 'dreg_t', possible loss of data
2023-12-03 15:21:40 -05:00
David Korth
563bb5f6c8 [unice68] unice68_unpack.c: depack_bytes: Check chk_dst_range(), *and* add chk_src_range().
One of the afl-fuzz tests (000003?) was failing due to the source
range being out of bounds.

Also, add assert() to the checked chk_src_range() and chk_dst_range()
functions.
2023-10-11 01:39:25 -04:00
David Korth
13363cfe69 [unice68] unice68_unpack.c, get_1_bit(): If chk_src_range() fails, return immediately.
Otherwise, attempting to dereference a5 will segfault.

This fixes all of the unice68 segfaults found with afl-fuzz so far...
at least in debug builds. Release builds are still faulting for some
reason...

TODO: Continue running afl-fuzz. I suspect I'll need to add something
similar to all uses of chk_src_range() and chk_dst_range().
2023-10-11 01:32:31 -04:00
David Korth
36fae53018 [extlib] unice68.c: Fix build.
- unice68_depacker() now has size parameters.

- Fix format string errors.
2023-10-11 01:01:01 -04:00
David Korth
e763ab74d8 [unice68] Fix testing for -Wno-empty-body on gcc-5.4. (Xubuntu 16.04)
-Wno-shift-negative-value isn't available on gcc-5.4, and since both
flags were combined into a single string, both were tested at the same
time instead of testing each flag individually.

Test the flags individually so we can suppress the -Wempty-body
warnings in unice68 on Xubuntu 16.04.
2023-05-07 12:05:57 -04:00
David Korth
c67e06b6b2 Disable symbol visibility in several extlib modules using static linking.
PowerVR, basisu_astc, inih, libmspack-xenia, and unice68 were leaking
externally-visible symbols in the Linux builds of UI frontends.
2022-06-18 15:29:52 -04:00
David Korth
eadcdf9327 Remove "/Gz" for stdcall on i386 when building with MSVC.
I tested a release build and it saved a total of 10,752 bytes.

On the other hand, it had a rather huge maintenance overhead, since I had
to ensure that all extlibs had __cdecl set up in the headers properly,
and this had to be redone on every update.

The i386 build of LZ4 on AppVeyor was failing in tests because of missing
stdcall symbols. I decided not to bother adding stdcall support to LZ4
and simply revert stdcall entirely.
2021-03-31 22:24:17 -04:00
David Korth
4e3c7abb98 [extlib] unice68: unice68_depacker(): Added explicit size parameters.
This is needed in order to prevent buffer overflows.

Found using afl-2.56b.
2020-06-20 12:49:21 -04:00
David Korth
39eff90db2 [extlib] Set the 32-bit MSVC calling convention to cdecl before calling check_function_exists().
This seemingly broke detection of e.g. fileno() and setmode() on 32-bit.

FIXME: Use check_symbol_exists(), which doesn't have this problem.
2020-03-08 14:44:56 -04:00
David Korth
2b1ce8b3f2 [unice68] Check for fileno() and _fileno().
It's still not finding it on MSVC 2010, but we might as well
check for it anyway.
2018-10-06 12:54:20 -04:00
David Korth
ded8ecea19 [unice68] Fixed MSVC build errors.
- `inline` isn't defined in C mode in MSVC 2010 and 2013.
  (It might be in 2015 and 2017?)

- main() must be `__cdecl`, but we're defaulting to `__stdcall`
  in 32-bit builds.

- myfileno(): Added a missing semicolon.
2018-10-06 12:51:08 -04:00
David Korth
da90a646cd [unice68] CMakeLists.txt: Specify "-fpic -fPIC" for shared library compatibility.
This broke the travis-ci build:

/usr/bin/ld: ../../../lib/../extlib/unice68/CMakeFiles/unice68_lib.dir/unice68_unpack.c.o:
	relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
../../../lib/libunice68.a: error adding symbols: Bad value

I didn't see this locally because I was only building rpcli when testing
the SNDH unice68 functionality.
2018-10-06 12:00:32 -04:00
David Korth
997ee7ff87 [unice68] CMakeLists.txt: Write config files *after* checking includes and functions.
Otherwise, basename() won't be detected properly on the first pass.
2018-10-06 11:56:14 -04:00
David Korth
bb3b816448 [unice68] Fixed signed/unsigned comparison and fall-through warnings.
The fall-through is intentional, so fall-through comments were added.
2018-09-29 15:05:38 -04:00
David Korth
e827229667 [unice68] Renamed config.h to config.unice68.h; added HAVE_CONFIG_H to unice68_exe.
This fixes the build of unice68.

The unice68 executable can now be built in tree for testing purposes,
but it isn't built or installed as part of the normal build.
2018-09-29 15:01:05 -04:00
David Korth
a7bb4e5151 [unice68] Disable -Wempty-body and -Wshift-negative-value.
unice68_pack.c generates a lot of these warnings, and there doesn't
seem to be a straightforward fix.
2018-09-29 11:15:14 -04:00
David Korth
2d2c64f817 [extlib] unice68: Initial import of unice68-2.0.0.690.
This will be used to decompress Atari ST SNDH files.

Note that unice68 is GPLv3, so there's a compile-time option to
disable it.

TODO: Make it a DLL/SO instead and use dlopen().
2018-09-29 11:01:57 -04:00