Commit graph

144 commits

Author SHA1 Message Date
Kp 0ebcc64ac5 Test whether change_filename_extension succeeded before using its output 2022-10-09 23:15:20 +00:00
Kp b0ebe3b82c Tighten change_filename_extension handling of overflow 2022-10-09 23:15:20 +00:00
Kp a9142bb65a Use std::span for change_filename_extension arguments 2022-10-09 23:15:20 +00:00
Kp 38adcc7729 Simplify change_filename_extension
The called function skipped over a leading dot in the extension.  Remove
that logic and change all callers not to supply a leading dot.
2022-10-09 23:15:20 +00:00
Kp 9c4c49fe5e Return std::unique_ptr from d_strdup 2022-10-09 23:15:20 +00:00
Kp 1b170fe880 Pass std::span to print_exit_message 2022-09-24 17:47:53 +00:00
Kp ea5d0136dc Pass std::span to msgbox_warning 2022-09-24 17:47:53 +00:00
Kp 8f1055ca6b Use std::span for poison helper functions 2022-09-24 17:47:51 +00:00
Kp 0ffbc764af Store Windows HMP MIDIHDR inline in hmp_file
This avoids the need to make separate allocations for the individual
buffers, and to free them later.
2022-08-22 01:24:49 +00:00
Kp a70188e7a5 Move various static functions into anonymous namespace 2022-07-09 13:39:29 +00:00
Kp 522c696af0 Remove unnecessary members in splitpath_t
splitpath_t is designed for MS-DOS paths, even though Rebirth now runs
on many platforms that never used DOS conventions.  Most of the members
of splitpath_t are unused on all platforms.  Remove them, and switch to
returning an initialized version of the structure.
2022-06-11 15:00:02 +00:00
Kp 163a6222c2 Remove unnecessary endian instances in serial.h
The type aliases are sufficient.  Individual bytebuffer_t
implementations can define a `static constexpr` member `endian` from the
type alias and rely on `std::integral_constant<T, V>::operator()`
instead of defining a `static` method just to return an instance of the
`std::integral_constant`.
2022-05-05 02:59:11 +00:00
Kp 1c2e1c6946 Tighten type info for d_strdup
The allocated block is part of the dmem subsystem, so return a type that
reflects that.
2022-04-24 20:42:01 +00:00
Kp 3b5b69cb97 Improve error reporting for hmp_open / hmp2mid
Rework the error paths to return path-specific status codes so that the
caller can report exactly which step caused an HMP file to be rejected.
On error, print this reason numerically and, if the reason was a PhysFS
error, also print the PhysFS error code numerically and symbolically.
2022-03-19 22:55:58 +00:00
Kp 634d72760f Remove unused-but-set variable common/misc/hmp.cpp: d
Also delete a now useless loop, which existed solely to update the value
of `d`.
2022-01-07 04:26:22 +00:00
Kp b05905ab4d Delegate score comma handling to std::locale 2021-09-19 10:53:48 +00:00
Kp 3aa1140700 Optimize out warn_printf on some targets
Some targets only ever use GUI warn functions.  On those targets:
- initialize `warn_func` to `msgbox_warning` at compile time
- remove the runtime initialize of warn_func in main

On targets which do not call `clear_warn_func`, preprocess out its
declaration and definition.

Taken together, these changes allow some targets not to define
`warn_printf`.
2021-09-12 16:20:52 +00:00
Kp 1c13d3c8d3 Improve error reporting for PHYSFSX_openReadBuffered
Return the PHYSFS error code on failure, so that callers can report why
the open failed.
2021-07-25 23:00:56 +00:00
Kp a7cbf60922 Return error code from PHYSFSRWOPS_openRead*
This improves error reporting for movies.
2021-07-25 23:00:56 +00:00
Kp 15057af2f9 Replace __noreturn with C++11 [[noreturn]]
This allows non-GNU-C compilers to see the attribute.
2021-06-28 03:37:50 +00:00
Kp 079602b91a Inline string_array_t::tidy comparator
There is only one call, so the target can be moved into the
implementation.  This removes use of a call-by-pointer.
2020-12-27 22:03:09 +00:00
Kp 017c4ce933 Restore buffering on PCX loads
Commit 3114874713 delegated PCX loading to
SDL_image, and as an incidental change, switched to using an unbuffered
PHYSFS file.  On Linux, this has no perceptible difference in
performance.  On Windows, the unbuffered accesses cause enough of a
performance problem for users to notice and report an issue.  Add a new
helper to create an SDL_RWops around a buffered file, and use that for
PCX loading.

Fixes: 3114874713 ("Delegate PCX loading to SDL_image")
Reported-by: Q3BFG10K <https://github.com/dxx-rebirth/dxx-rebirth/issues/549>
Reported-by: aybe <https://github.com/dxx-rebirth/dxx-rebirth/issues/555>
Analyzed-by: arbruijn <https://github.com/dxx-rebirth/dxx-rebirth/issues/555#issuecomment-735442076>
2020-11-30 05:12:00 +00:00
Kp 9694df2063 Fix leak of PHYSFS handle if SDL_AllocRW fails
Previously, if SDL_AllocRW failed, then the handle would not be saved
into an SDL_RWops (since that object was not created), but it would also
not be closed immediately.
2020-11-30 05:12:00 +00:00
Edward E d7999c9fad Fix truncation of callback pointer on Windows
Previously fixed ec709efaa3,
but reverted 8a4ac70541
2020-10-29 03:40:19 +00:00
Kp 7fb4f7b396 Use std::array for editor mine filename 2020-10-12 03:28:25 +00:00
Kp 59ca93f219 Simplify copy+uppercase pattern in editor code
Change d_strupr to both copy and uppercase, instead of using strcpy to
copy and then a separate phase to rewrite the text as uppercase.
2020-09-28 03:32:15 +00:00
Kp 68b47307b4 Remove useless SDL_RWops precision test in SDL2
SDL2 increased the range of the seek type, so truncation is no longer a
concern.
2020-05-31 23:04:25 +00:00
Kp 3114874713 Delegate PCX loading to SDL_image
This adds a new dependency, but most systems likely already have
SDL_image installed.  Use of SDL_image can be disabled, but this is
discouraged, because various in-game interfaces assume the use of the
original background.

The old implementation automatically corrected for filename case.  The
new implementation expects that the supplied filename can be passed to
PYHSFS_openRead as-is.  All known uses in-game have been corrected to
satisfy this requirement.  If the new stricter match requirement becomes
a problem, a variant of PHYSFSRWOPS_openRead that adjusts filename case
could be created for use here.

- Update install instructions
- Update ebuild
- Update Arch PKGBUILD
2020-05-17 23:35:26 +00:00
Kp db7b4b3f88 Refer to <memory> directly, not through "compiler-make_unique.h" 2020-05-02 21:18:43 +00:00
Kp cc38cdf4b8 Qualify uses of std::make_unique 2020-05-02 21:18:42 +00:00
Kp 53761500f1 Qualify uses of std::array 2020-05-02 21:18:42 +00:00
Kp 3a5e203638 Fix Windows build of hmp.cpp
Reported-by: zicodxx <private>
Fixes: 2243cd7f58 ("Use xrange for loops with zero start and constant numerical end")
2019-05-17 02:13:22 +00:00
Kp 2243cd7f58 Use xrange for loops with zero start and constant numerical end
s/for\s*(\s*\(\w\+\)\s\+\(\w\+\)\s*=\s*0\+u\?\s*;\s*\2\s*\(!=\|<\)\s*\([0-9]\+\)u\?\s*;\s*\(++\s*\2\|\2\s*++\s*\))/range_for (const \1 \2, xrange(\4u))/
2019-05-04 18:27:36 +00:00
Kp a472f04035 Only test warn_func when it can be nullptr 2019-01-01 04:54:35 +00:00
Kp b08dac2971 Simplify handling warning function 2018-12-30 00:43:58 +00:00
Kp 12b57e84e6 Switch most in-tree http:// links to https://
For each link given as http://, verify that the site is accessible over
https:// and, if so, switch to it.  These domains were converted:

* llvm.org
* clang.llvm.org
* en.cppreference.com
* www.dxx-rebirth.com
* www.libsdl.org
* www.scons.org
2018-09-02 00:57:29 +00:00
Kp 047ddaf9ea Prevent buffer overrun in removeext 2018-08-26 18:10:36 +00:00
Kp 5526de4c10 Simplify case insensitive lookups 2018-06-13 02:02:58 +00:00
Kp 0f9db40e36 Simplify reporting fatal errors 2017-08-11 23:43:52 +00:00
Kp 9205296380 Print fatal errors to console before calling hook function
On Windows, the hook function blocks until the user dismisses the
message box.  Print the message before opening the message box so that
it is available on the console, if one exists.
2017-08-02 02:49:12 +00:00
Kp 8ccf0e5301 Add PHYSFS_read wrapper support
- Add wrappers for PHYSFS_read and its convenience functions.  Poison
  the memory before calling PHYSFS, so that any uninitialized bytes
  (likely caused by a short read) are reported if the caller tries to
  access the value anyway.
- Add SConstruct options to enable wrapping, so that users do not need
  to enumerate the wrapped functions manually.
- Fix link failure when using LTO+wrappers.
2017-07-26 03:15:58 +00:00
Kp a815541ef5 Fix check_header_includes=1 poison.h 2017-02-19 19:33:36 +00:00
Kp 6ac840c52c Fix pch=1 build
PCH mode causes the Valgrind-wrapper header to be included in places
it is not meant to be used, which leads to spurious compiler errors.

PCH mode causes the Valgrind-wrapper __real_* stub functions to see
the physfsx.h PHYSFS macros, which also causes errors.

Fortunately, both cases can be easily fixed.

Add preprocessor guards to the Valgrind-wrapper header to cause it to
compile out when the PCH phase runs.  It has no include guard, so it
will be rescanned with the proper macros when the two consuming files
are built normally.

Modify the Valgrind-wrapper __real_* stub functions to use
the standard macro avoidance trick so that they do not call the
physfsx.h PHYSFS macros.
2017-01-31 04:25:06 +00:00
Kp 2c4af523dd Use ugly preprocessor hook hack to fix Clang build failure
Clang rejects a declared (but never defined and never used) `static`
function.  Change the declaration to be the value of a macro that will
be expanded only when the function is both defined and used.

Reported-by: kreatordxx <https://github.com/dxx-rebirth/dxx-rebirth/issues/295>
Fixes: 55822d0b4d ("Add wrappers for more precise Valgrind physfs diagnostics")
2017-01-07 19:09:04 +00:00
Kp 55822d0b4d Add wrappers for more precise Valgrind physfs diagnostics 2017-01-01 23:19:21 +00:00
Kp 51a897e6a7 Use range_for for hmp reset_tracks 2016-10-29 23:16:18 +00:00
Kp aabd01c9ad Use range_for in hmp_open 2016-10-29 23:16:17 +00:00
Kp 6a8cc912e1 Switch hmp.cpp to use C++ casts 2016-09-04 19:10:43 +00:00
Kp 705bbff53a Remove bogus cast in Win32 MIDI get_event
Casting `&unsigned` to `(unsigned long *)` is wrong.  It happened to
work because these types are the same size on Windows and this code is
only used on Windows.  Remove the bogus cast and fix the function
prototype.
2016-09-04 19:10:43 +00:00
Kp 4293227a54 Move strutil qsort comparator casts into function 2016-09-04 19:10:42 +00:00