Skip to content

Various compiler warning fixes#1800

Draft
dpogue wants to merge 10 commits intoH-uru:masterfrom
dpogue:warning-fixes
Draft

Various compiler warning fixes#1800
dpogue wants to merge 10 commits intoH-uru:masterfrom
dpogue:warning-fixes

Conversation

@dpogue
Copy link
Copy Markdown
Member

@dpogue dpogue commented Sep 24, 2025

Fixes various warnings (mostly in CoreLib) from Xcode and Visual Studio around uninitialized local variables, unused values, improper use of getcwd, and some (but not all) signed/unsigned and int sizing warnings in hsStream.

This also enables CMP0156 which is supposed to deduplicate linked libraries to avoid warnings from Xcode.

I've tried to keep each commit reasonably self-contained, so we can drop anything that we don't have agreement on.

@dpogue dpogue force-pushed the warning-fixes branch 5 times, most recently from 6fa8b1f to 84cd602 Compare September 27, 2025 05:54
Copy link
Copy Markdown
Contributor

@dgelessus dgelessus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generally looks good.

I'm a little cautious about size_t in the context of file IO, because when done wrong, it can introduce problems with large files that go unnoticed in 64-bit builds and only affect 32-bit builds.

This isn't a realistic problem for us right now, because so much of the hsStream code hardcodes file sizes/offsets as uint32_t (and fixing that isn't the topic of this PR). But to avoid future issues, we should use size_t in IO code only for sizes/offsets of memory buffers (as for Read/Write for example). Sizes/offsets within files/streams should not be size_t. For now, unfortunately, the appropriate type is uint32_t, but at some point we should add an equivalent of POSIX off_t for file sizes/offsets. I've commented on the specific cases where I think size_t isn't appropriate.

}
#else
char *cwd_a = getcwd(nullptr, 0);
char cwd_a[1024];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
char cwd_a[1024];
char cwd_a[PATH_MAX];

The super-ideal POSIX solution would be to call pathconf to dynamically get PATH_MAX for the path ".", but we already use the PATH_MAX macro constant in a few other places, so for now this is fine I think. (Plus, according to gnulib, many getcwd implementations don't work properly for paths longer than PATH_MAX anyway.)

Comment on lines -99 to -100
// Note: GetAsHexString() returns a pointer to a static string;
// do not rely on the contents of this string between calls!
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good riddance!

Comment on lines +424 to +431
uint32_t startChunkPos = startPos % kEncryptChunkSize;
size_t startChunkPos = startPos % kEncryptChunkSize;
// Amount of data in the partial first chunk (0 if we're aligned)
uint32_t startAmt = (startChunkPos != 0) ? std::min(kEncryptChunkSize - startChunkPos, bytes) : 0;
size_t startAmt = (startChunkPos != 0) ? std::min(kEncryptChunkSize - startChunkPos, bytes) : 0;

uint32_t totalNumRead = IRead(bytes, buffer);
size_t totalNumRead = IRead(bytes, buffer);

uint32_t numMidChunks = (totalNumRead - startAmt) / kEncryptChunkSize;
uint32_t endAmt = (totalNumRead - startAmt) % kEncryptChunkSize;
size_t numMidChunks = (totalNumRead - startAmt) / kEncryptChunkSize;
size_t endAmt = (totalNumRead - startAmt) % kEncryptChunkSize;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same story as for plEncryptedStream - offsets should stay uint32_t for now.

for (size_t i = nOldMods; i < nOldMods + nNewMods; i++)
{
refMsg = new plObjRefMsg(GetKey(), plRefMsg::kOnCreate, i, plObjRefMsg::kModifier);
refMsg = new plObjRefMsg(GetKey(), plRefMsg::kOnCreate, static_cast<int8_t>(i), plObjRefMsg::kModifier);
Copy link
Copy Markdown
Contributor

@dgelessus dgelessus Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like it would be better to allow larger indices in plObjRefMsg itself?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't change this without changing the stream layout for the message. There really shouldn't be any RefMsgs serialized anywhere, but it's not impossible, so we need to be careful about that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we have, in a few places, widened the internal storage and added something like hsAssert(fValue <=std::numeric_limits<oldType_t>::max(), "overflow"); to the serialization routine (example). It might not be a bad idea to do that.

plAttachMsg is a plRefMsg that can go over the wire, btw. It's pretty trivial to send those from Python. Thankfully, plAttachMsg is not a subclass of plObjRefMsg.

@Hoikas Hoikas marked this pull request as draft January 31, 2026 18:56
@dpogue dpogue force-pushed the warning-fixes branch 2 times, most recently from 8dbe5d0 to 2ad5dda Compare March 10, 2026 01:40
dpogue and others added 10 commits March 21, 2026 18:57
Co-Authored-By: Adam Johnson <AdamJohnso@gmail.com>
Behaviour is undefined if the buffer parameter is null.

Co-Authored-By: dgelessus <dgelessus@users.noreply.github.com>
Co-Authored-By: dgelessus <dgelessus@users.noreply.github.com>
Co-Authored-By: dgelessus <dgelessus@users.noreply.github.com>
Co-Authored-By: dgelessus <dgelessus@users.noreply.github.com>
@dgelessus
Copy link
Copy Markdown
Contributor

Looking at this again, would it make sense to split the integer size and signedness commits into a separate PR? All the other commits look like straightforward, independent fixes - they don't need to be blocked on figuring out the details of the integer types.

In my last review, there's only one remaining comment that's not about integer types, which is that the result array for getcwd should use PATH_MAX as the length, instead of hardcoding 1024.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants