Cleanup pass: dead code, needless copies, and a few small fixes - #465
Open
marekl11 wants to merge 1 commit into
Open
Cleanup pass: dead code, needless copies, and a few small fixes#465marekl11 wants to merge 1 commit into
marekl11 wants to merge 1 commit into
Conversation
Mostly hygiene, plus a handful of small bugs found alongside it.
Cleanup:
- SIOMessageConvert: ToSIOMessage copied the whole FJsonObject::Values map
per object emit (`auto` on a TMap); the two string converters took their
arguments by value; the condensed-writer typedefs and their two includes
were unused; the range-for loops copied their pairs.
- SocketIONative / SocketIOClientComponent: dropped `[&]` from ten lambdas
that capture every name they use explicitly, so it is clearer which
callbacks really do reach for a member. Left the ones that do alone.
- Removed a commented-out declaration, a dead `CastField` stub in
SocketIOFunctionLibrary, and two `#pragma endregion` in SIOJConvert with
no matching region.
- SIOJConvert::ReplaceJsonValueNamesWithMap serialized the whole subtree to
a string at every object level to feed two commented-out log lines.
Fixes:
- Break Json is unusable: all three sites resolve the pin class with
StaticLoadObject("class'SIOJPlugin.SIOJJsonObject'"), a module and class
name from before the module split. The load returns null and Compile()
dereferences it, so compiling a Blueprint containing the node crashes the
editor. Uses USIOJsonObject::StaticClass() now (SIOJson is already a
public dependency of that module).
- Conv_CompactBytesToTransforms / Conv_CompactPositionBytesToTransforms
size a float view for Num()/4 floats and then memcpy Num() bytes into it
before checking divisibility, so any input that is not a multiple of four
writes past the end. These take network-supplied bytes from Blueprint.
Length check moved ahead of the copy.
- CUFileComponent/CUFileSubsystem::SplitFullPath fell back to splitting on
TEXT("\\\\") - a two-character string - so a Windows-style path never
split and both out params were left untouched. SaveBytesToPath then
failed on the empty path.
- USIOJsonObject::EncodeJsonToSingleString discarded both Replace results
(Replace returns a new string), and the second searched for
LINE_TERMINATOR while claiming to remove tabs.
- USIOJsonObject::GetBinaryField had no JsonObj.IsValid() guard, unlike
every other accessor in the file, and logged a type mismatch without
returning - FJsonValueBinary::IsBinary is also true for array, object and
null values, and the downcast below it then reads a TArray member that is
not there.
- ToSIOMessage built std::string(nullptr, 0) for an empty binary value.
- ENABLE_CUPRECISE_TIMER was #defined unconditionally, so the #else branch
in Tock could never compile and the off mode did not exist. Wrapped in
#ifndef.
Also named FSocketIONative::kUnlimitedReconnectionAttempts. The component
initialized MaxReconnectionAttempts from a float literal (-1.f) into an
int32, the native used a bare -1 into a uint32, and the header said
"0 = infinity" - but sio compares m_reconn_made < m_reconn_attempts on an
unsigned, so 0 means zero attempts and only the wraparound made the default
unlimited. Behaviour is unchanged; it just says what it means now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mostly a cleanup pass over the plugin's own code (ThirdParty untouched), with a few small bugs I ran into while doing it. No behaviour changes beyond the fixes listed below.
Cleanup
ToSIOMessagecopied the wholeFJsonObject::Valuesmap on every object emit —autoon aTMapdeduces to a copy. Also made the range-for loops take their pairs by reference, andStdString/FStringFromStdtakeconst&instead of by value.[&]from ten lambdas that already capture everything they use explicitly. The ones that genuinely reach for a member are left alone, so it's now visible which those are.CastFieldstub inSocketIOFunctionLibrary, and two#pragma endregionwith no matching region.ReplaceJsonValueNamesWithMapwas serializing the whole subtree to a string at every object level to feed two commented-out log lines.Fixes
StaticLoadObject("class'SIOJPlugin.SIOJJsonObject'")— a module and class name from before the module split. The load returns null,Compile()dereferences it, and compiling a Blueprint containing the node takes the editor down. Now usesUSIOJsonObject::StaticClass();SIOJsonis already a public dependency of that module.Conv_CompactBytesToTransforms/Conv_CompactPositionBytesToTransformswrite past the array. Both size a float view forNum()/4floats and thenmemcpyNum()bytes into it before the divisibility check. Any input that isn't a multiple of four writes the trailing bytes out of bounds, and these are Blueprint-callable on network-supplied bytes. Moved the length check ahead of the copy.SplitFullPath's backslash fallback can't match. It splits onTEXT("\\\\"), which is the two-character string\, so a Windows-style path never splits and both out params keep whatever the caller had —SaveBytesToPaththen fails on the empty path.EncodeJsonToSingleStringdoes nothing. BothReplacecalls discard their result (Replacereturns a new string), and the second searches forLINE_TERMINATORwhile its comment says "remove tabs" — once assigned it would have inserted a tab per line break.GetBinaryFieldis missing two guards. NoJsonObj.IsValid()check, unlike every other accessor in the file, and it logs a type mismatch without returning.FJsonValueBinary::IsBinaryis also true for array, object and null values, so the unchecked downcast below reads aTArraymember that isn't there.ToSIOMessagebuiltstd::string(nullptr, 0)for an empty binary value.ENABLE_CUPRECISE_TIMERwas#defined unconditionally, soTock's#elsebranch could never compile and the off mode didn't exist. Wrapped in#ifndef.One naming change
FSocketIONative::kUnlimitedReconnectionAttempts. The component initialisedMaxReconnectionAttemptsfrom a float literal (-1.f) into anint32, the native used a bare-1into auint32, and the header said "0 = infinity" — but sio comparesm_reconn_made < m_reconn_attemptson an unsigned, so 0 means zero attempts and only the-1wraparound made the default unlimited. Nothing changes at runtime; it just says what it means, so a later tidy-up doesn't turn reconnection off.Happy to split any of this out if you'd rather take it in pieces.