Commit graph

123 commits

Author SHA1 Message Date
Daniel Gibson
ac6ec0cc45 Fix some typos 2024-07-25 03:24:20 +02:00
Daniel Gibson
6dc36c6175 Add some functions to handle UTF-8 strings
- convert to/from ISO8859-1 (Doom3's "High ASCII" encoding)
- count Unicode codepoints in UTF-8 string
- cut UTF-8 string off after N codepoints
- use the conversion function to replace iconv in sys/events.cpp
2024-06-02 13:14:30 +02:00
Daniel Gibson
ef529cf49a Bind F10 to open dhewm3Settings menu, unless F10 is already bound
Also fix MSVC build: For some reason Microsoft's sad excuse of a compiler
 only sets __cplusplus to a value from this millenium if the
/Zc:__cplusplus compiler option is set, but that's only supported from
VS2017 15.7 on. The alternative is to use _MSVC_LANG, which always holds
the version that __cplusplus *should* have...
2024-05-23 19:29:38 +02:00
Daniel Gibson
7023475c9d Add idStr::(V)Format(), make idList compatible with C++ foreach
idStr::(V)Format() is a static (v)printf-like function that returns
and idStr. Can be used like a better va(), or for
idStr mystr = idStr::Format( "number of items: %d", myarr.Num() );
2024-05-22 19:46:38 +02:00
Daniel Gibson
56b3c46ba8 Fix MSVC non-Release builds (_alloca()/assert() didn't play nice) 2023-03-02 18:04:48 +01:00
Daniel Gibson
477252308d Fix date/time handling in idParser::ExpandBuiltinDefine()
this was so broken, I think if anyone ever tried to use __DATE__ or
__TIME__ it must've crashed, either from free(curtime) (which was the
return value of ctime()) or from things like token[7] = NULL when token
was a pointer (to a single element!).

I think it could work now.

Also fixed potential memory leaks in cases that don't "return" anything
2023-01-05 09:07:04 +01:00
Daniel Gibson
957176d659 Fix GCC -W(maybe-)uninitialized warnings that at least kinda had a point 2023-01-05 07:51:59 +01:00
Daniel Gibson
5844af62ce Don't use "register" keyword, it was deprecated in C++11
.. and even removed in C++17 - and before that it probably didn't do
much in most compilers
2023-01-05 05:07:53 +01:00
Daniel Gibson
279a40a981 Fix -Wformat-security warnings - thanks James Addison!
This is based on https://github.com/dhewm/dhewm3/pull/500
by https://github.com/jayaddison

See also https://github.com/blendogames/quadrilateralcowboy/pull/4
2023-01-05 04:45:34 +01:00
Daniel Gibson
d679e393c3 Add D3_(v)snprintfC99() for C99-compatible implementations
These are now used by idStr::(v)snPrintf(), and in the future can
be used if a (v)snprintf() that's guaranteed not to call
common->Warning() or similar is needed (e.g. used during early startup)
2022-01-10 04:06:54 +01:00
Daniel Gibson
ea781c577e Use idStr::Copynz() instead of strncpy()
to guarantee \0-termination
2022-01-08 16:58:48 +01:00
Daniel Gibson
5e4e1d61be Merge branch 'debugger' 2021-07-16 02:21:16 +02:00
Daniel Gibson
d55b7fa6c9 Don't use stringDataAllocator in idStr, it's not thread-safe
idStr is used in both the main thread and the async sound thread, so
it should better be thread-safe.. idDynamicBlockAlloc is not.
Use realloc() and free() instead.

For some reason this caused a lot more crashes (due to inconsistencies
in the allocator's heap) with newer Linux distros (like XUbuntu 20.04)
and when using GCC9, while they rarely reproduced with GCC7 or on
XUbuntu 18.04

fixes #391
2021-06-24 03:26:51 +02:00
Daniel Gibson
c2b34e6fe8 Remove idBitMsg::Read/WriteInt64() again
not used anymore
2021-06-19 21:30:26 +02:00
HarrievG
7f7ed7e45f - Removing ugly (and wrong) include hack for SDL on MSCV+VCPKG.
This has been resolved anyway, and should never been submitted.
2021-06-17 05:44:23 +02:00
HarrievG
5e27330233 - 64bit debugger fixes 2021-06-17 05:44:23 +02:00
HarrievG
7a2ccee330 debugger 2021-06-17 05:44:23 +02:00
Daniel Gibson
2521c3dfdb (Hopefully) better workaround for miscompiled cross products, #147
according to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100839
the real compiler flag enabling this bullshit isn't
-fexpensive-optimizations but -ffp-contract=fast which for some(*)
reason is default in optimized builds.
I think it's best to disabled that optimization globally in case it
also breaks other code (I really don't want to spend several days to
hunt such an idiot bug again). I really doubt it makes any measurable
performance difference.
As https://twitter.com/stephentyrone/status/1399424911328874499 says
that clang might also enable this in the future (though to =on instead
of =fast which should be a bit saner but would still break our code),
just set this option for all GCC-ish compilers incl. clang.

(*) the reason of course is that GCC developers don't develop GCC for
    their users but to win idiotic SPEC benchmarks
2021-05-31 21:37:31 +02:00
Daniel Gibson
320c15f63a Fix dmap bug if compiled with GCC and x86 FMA enabled
Only happend if `ONATIVE` was enabled (or some other flag was set
that enables the FMA extension), the root cause was that the cross
product didn't return 0 when it should, but a small value < 0.
Caused some faces to be missing in maps compiled with dmap.
https://github.com/RobertBeckebans/RBDOOM-3-BFG/issues/436#issuecomment-851061826
has lots of explanation.

I think this is a compiler bug, this commit works around it.

fixes #147
2021-05-31 02:03:46 +02:00
Turo Lamminen
8cfeb51b84 Silence an uninitialized variable warning 2021-03-15 13:02:45 +02:00
Turo Lamminen
1ae9ff7d74 Don't use memset to zero non-trivial type volumeIntegrals_t 2021-03-15 13:02:45 +02:00
Turo Lamminen
59940c9b2f Don't memcpy non-trivial type idDrawVert in idSurface constructor 2021-03-15 13:02:45 +02:00
Turo Lamminen
8d2d41345d Don't use memset in idMat6::Zero 2021-03-15 13:02:45 +02:00
Turo Lamminen
30175c72ae Be more careful with memcpy in idMat6 constructor 2021-03-15 13:02:45 +02:00
Turo Lamminen
669e259787 Don't use memset in idMat5::Zero 2021-03-15 13:02:45 +02:00
Turo Lamminen
6a7bb7e305 Don't use memcpy in idMat5 constructor 2021-03-15 13:02:45 +02:00
Turo Lamminen
8fa3793410 Don't use memset in idMat4::Zero 2021-03-15 13:02:45 +02:00
Turo Lamminen
57f09de425 Don't use memcpy in idMat4 constructor 2021-03-15 13:02:45 +02:00
Turo Lamminen
37ed3e9e46 Don't use memset in idMat3::Zero 2021-03-15 13:02:45 +02:00
Turo Lamminen
c67c455180 Don't use memcpy in idMat3 constructor 2021-03-15 13:02:45 +02:00
Turo Lamminen
df9d8cf0ce Don't use memcpy in idMat2 constructor 2021-03-15 13:02:45 +02:00
Daniel Gibson
12fa3eb814 Disable broken idSIMD_SSE::UpSampleOGGTo44kHz()
It corrupted the stack when called with buffers allocated on the stack
and numSamples that are not a multiple of four, apparently, by writing
4 floats too many, at least in the 22KHz Stereo case..

This caused the crash described in
  https://github.com/dhewm/dhewm3/issues/303#issuecomment-678809662

Now it just uses the generic C code, like all platforms besides MSVC/x86
already do.
2020-09-05 20:28:03 +02:00
Daniel Gibson
aa77e49de7 Fix handling of paths with dots in dir names, fix #299, #301
idStr::StripFileExtension() (and SetFileExtension() which uses it) and
others didn't work correctly if there was a dot in a directory name,
because they just searched from last to first char for '.', so if the
current filename didn't have an extension to cut off, they'd just cut off
at any other '.' they found.
So D:\dev\doom3.data\base\maps\bla could turn into D:\dev\doom3
(or, for SetFileExtension(), D:\dev\doom3.map)

While at it, I made most of the idStr code that explicitly checked for '\\'
and '/' (and maybe ':' for AROS) use a little "bool isDirSeparator(int c)"
function so we don't have the #ifdefs for different platforms all over
the place.
2020-07-21 05:58:44 +02:00
Daniel Gibson
b756276b54 ID_MAYBE_INLINE for not-forced inlining
On Windows, ID_INLINE does __forceinline, which is bad if the function
calls alloca() and is called in a loop..
So use just __inline there so the compiler can choose not to inline
(if called in a loop).
This didn't cause actual stack overflows as far as I know, but it could
(and MSVC warns about it).
2020-01-11 16:15:34 +01:00
Daniel Gibson
dd7a6b2832 idLangDict: Workaround for Doom3: Lost Mission stringtables #265
The Doom3: Lost Mission (aka D3LE) mod uses string table entry keys that
don't follow the proper Doom3 scheme of "#str_01234", but look like
"#str_adil_exis_pda_01_audio_info" - the "hash" algorithm of idLangDict,
which basically just converts the number after "#str_" into an int,
probably doesn't work very well with this and there was an assertion
to prevent this..
However, it seems to work well enough, so now I only print one warning
for the first "invalid" key and otherwise accept those keys.

The stringtable (strings/*.lang) also has font-related entries
(like "#font" "Chainlink_Semi-Bold") that triggered another assertion,
now everything that starts with "#font" is silently skipped.
2020-01-05 02:34:53 +01:00
yamir
12fa28b260 Fix ppc64le build 2019-09-11 13:02:55 -01:00
Daniel Gibson
596d40d5c9 MSVC: Shut up Compiler warning in Matrix.h if asserts are disabled 2019-01-13 22:12:36 +01:00
Daniel Gibson
3ab553bcf9 Fix pot. Crash in idWinding2D::ExpandForAxialBox()
it could happen that i is 1 but numPlanes is still 0
(=> if for i = 0:  ( p[j] - p[i] ).LengthSqr() < 0.01f )
so planes[-1] would be accessed which of course is invalid and can crash
2018-12-09 04:16:43 +01:00
Kalamatee
46279bf11f import AROS changes 2017-04-02 00:42:28 +01:00
Turo Lamminen
5da6374663 Fix idStr self-assignment
Was calling memcpy with overlapping parameters which is inefficient,
undefined behavior and Valgrind complained about it.
2017-03-14 21:45:40 +01:00
Turo Lamminen
f26f70c717 Fix stack overflow in SSE code
This was checking the wrong variable so when count was < 4 it was writing
past the end of buffer and potentially breaking the stack.
2017-03-14 21:11:13 +01:00
Daniel Gibson
befe732dbb Fix new[]/delete missmatches and memory leaks found by clang's ASAN
Sometimes memory was allocated with new[] but freed with delete instead
of delete[], which is wrong.
And there were some small memory leaks, too.
Furtunately clang's AddressSanitizer detected all that so I could easily
fix it.

(There seem to be some more small memory leaks which are harder to fix,
though)
2015-12-17 18:11:03 +01:00
Daniel Gibson
48511003b6 Unix: On failed assertion, break gracefully into debugger
__builtin_trap() causes an illegal instruction and thus the process
can't resume afterwards.
raise(SIGTRAP) only breaks into the debugger and thus allows to
"ignore" the assertion while debugging.
2015-12-13 03:30:03 +01:00
leffmann
db461045bf make idlib build with Visual Studio 14 2015-10-11 00:36:25 +02:00
Daniel Gibson
1de6ab0d50 Fix some compiler warnings (wrong types, superfluous checks, printf-fuckup) 2015-09-27 18:12:16 +02:00
Tobias Frost
73fa334c2a Fixing some spelling errors: s/unkown/unknown, s/seperate/separate. (#107) 2015-02-25 22:01:00 +01:00
Daniel Gibson
f8de73862e math.h should #include sys/platform.h
Similar to f317b05
2012-11-13 23:58:50 +01:00
Daniel Gibson
f317b056c6 List.h needs sys/platform.h for ID_INLINE
Everytime List.h is included in a new file (and sys/platform.h isn't)
there are confusing compiler-errors..
So just #include sys/platform.h in List.h directly, because it uses
ID_INLINE which is defined there
2012-11-13 23:28:21 +01:00
Daniel Gibson
a7bfd05797 Use current type for BT_CLOSED enum
doesn't really make a difference code-wise, but removes one compiler warning.
2012-11-13 23:27:07 +01:00
Daniel Gibson
3202f0aa0f Get rid of some compiler warnings
GCC had shitloads of superfluous warnings wherever List.h and Str.h were
included.. get rid of them by using #pragma GCC diagnostic at some places
in List.h and Str.h.
Also add some casts, initialize some variables for other warnings
2012-11-13 23:24:13 +01:00