[Scummvm-git-logs] scummvm master -> 39e24cac2e1403141c38fd814182c98d0c1bbcce

dwatteau noreply at scummvm.org
Wed Apr 16 14:11:57 UTC 2025


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
febb29ee3b BACKENDS: MACOS: Fix various warnings in macosx-audiocd.cpp
39e24cac2e BACKENDS: MACOS: Use two getfsstat() calls instead of allocating a giant buffer


Commit: febb29ee3b359eeb89e43034381cdc53ec43df5a
    https://github.com/scummvm/scummvm/commit/febb29ee3b359eeb89e43034381cdc53ec43df5a
Author: Donovan Watteau (contrib at dwatteau.fr)
Date: 2025-04-16T16:11:53+02:00

Commit Message:
BACKENDS: MACOS: Fix various warnings in macosx-audiocd.cpp

Allocate the `struct statfs` buffer on the heap instead of the stack,
fixing a -Wframe-larger-than warning.

Fix a -Wsign-compare warning with the GCC 32-bit builds.

Add a couple more headers for getfsstat(), as given by its manual page
(although it builds just fine without them).

Changed paths:
    backends/audiocd/macosx/macosx-audiocd.cpp


diff --git a/backends/audiocd/macosx/macosx-audiocd.cpp b/backends/audiocd/macosx/macosx-audiocd.cpp
index 53a8c2824f6..10757ae6735 100644
--- a/backends/audiocd/macosx/macosx-audiocd.cpp
+++ b/backends/audiocd/macosx/macosx-audiocd.cpp
@@ -42,6 +42,8 @@
 
 #ifdef MACOSX
 
+#include <sys/param.h>
+#include <sys/ucred.h>
 #include <sys/stat.h>
 #include <sys/mount.h>
 
@@ -195,16 +197,19 @@ enum {
 
 MacOSXAudioCDManager::DriveList MacOSXAudioCDManager::detectAllDrives() {
 	// Fetch the lists of drives
-	struct statfs driveStats[kMaxDriveCount];
-	int foundDrives = getfsstat(driveStats, sizeof(driveStats), MNT_WAIT);
-	if (foundDrives <= 0)
+	struct statfs *driveStats = (struct statfs *)malloc(sizeof(struct statfs) * kMaxDriveCount);
+	int foundDrives = getfsstat(driveStats, sizeof(struct statfs) * kMaxDriveCount, MNT_WAIT);
+	if (foundDrives <= 0) {
+		free(driveStats);
 		return DriveList();
+	}
 
 	DriveList drives;
 	for (int i = 0; i < foundDrives; i++)
 		drives.push_back(Drive(Common::Path(driveStats[i].f_mntonname, Common::Path::kNativeSeparator),
 			Common::Path(driveStats[i].f_mntfromname, Common::Path::kNativeSeparator), driveStats[i].f_fstypename));
 
+	free(driveStats);
 	return drives;
 }
 
@@ -287,7 +292,7 @@ bool MacOSXAudioCDManager::findTrackNames(const Common::Path &drivePath) {
 				char *endPtr = nullptr;
 				long trackID = strtol(trackIDString, &endPtr, 10);
 
-				if (trackIDString != endPtr && trackID > 0 && trackID < UINT_MAX) {
+				if (trackIDString != endPtr && trackID > 0 && (unsigned long)trackID < UINT_MAX) {
 					_trackMap[trackID - 1] = drivePath.appendComponent(fileName);
 				} else {
 					warning("Invalid track file name: '%s'", fileName.c_str());


Commit: 39e24cac2e1403141c38fd814182c98d0c1bbcce
    https://github.com/scummvm/scummvm/commit/39e24cac2e1403141c38fd814182c98d0c1bbcce
Author: Donovan Watteau (contrib at dwatteau.fr)
Date: 2025-04-16T16:11:53+02:00

Commit Message:
BACKENDS: MACOS: Use two getfsstat() calls instead of allocating a giant buffer

For the statfs buffer used by detectAllDrives(), only allocate what is
needed, instead of an arbitrary value.

Calling getfsstat() a first time with a NULL pointer will return the
number of mounted file systems. We can then use that a allocate a
buffer at the right size for the next getfsstat() call.

It looks like we can then reasonably expect MNT_NOWAIT to be enough
for the second call that immediately follows...

Idea from criezy.

Changed paths:
    backends/audiocd/macosx/macosx-audiocd.cpp


diff --git a/backends/audiocd/macosx/macosx-audiocd.cpp b/backends/audiocd/macosx/macosx-audiocd.cpp
index 10757ae6735..cd7c2e2d924 100644
--- a/backends/audiocd/macosx/macosx-audiocd.cpp
+++ b/backends/audiocd/macosx/macosx-audiocd.cpp
@@ -190,15 +190,14 @@ void MacOSXAudioCDManager::close() {
 	_trackMap.clear();
 }
 
-enum {
-	// Some crazy high number that we'll never actually hit
-	kMaxDriveCount = 256
-};
-
 MacOSXAudioCDManager::DriveList MacOSXAudioCDManager::detectAllDrives() {
+	int foundDrives = getfsstat(nullptr, 0, MNT_WAIT);
+	if (foundDrives <= 0)
+		return DriveList();
+
 	// Fetch the lists of drives
-	struct statfs *driveStats = (struct statfs *)malloc(sizeof(struct statfs) * kMaxDriveCount);
-	int foundDrives = getfsstat(driveStats, sizeof(struct statfs) * kMaxDriveCount, MNT_WAIT);
+	struct statfs *driveStats = (struct statfs *)malloc(sizeof(struct statfs) * foundDrives);
+	foundDrives = getfsstat(driveStats, sizeof(struct statfs) * foundDrives, MNT_NOWAIT);
 	if (foundDrives <= 0) {
 		free(driveStats);
 		return DriveList();




More information about the Scummvm-git-logs mailing list