From 4ff789e24cb170393dfe699507dc171602178c1c Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Mon, 8 Aug 2022 15:39:23 +0200 Subject: [PATCH] UI: Fix snprintf calls with literals as buffer sizes --- UI/obs-app.cpp | 8 ++++---- UI/qt-wrappers.cpp | 2 +- UI/window-basic-main-profiles.cpp | 9 ++++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index 750e4827c..8ac3d376a 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -376,7 +376,7 @@ static void do_log(int log_level, const char *msg, va_list args, void *param) va_copy(args2, args); #endif - vsnprintf(str, 4095, msg, args); + vsnprintf(str, sizeof(str), msg, args); #ifdef _WIN32 if (IsDebuggerPresent()) { @@ -2658,16 +2658,16 @@ static void move_to_xdg(void) if (!home) return; - if (snprintf(old_path, 512, "%s/.obs-studio", home) <= 0) + if (snprintf(old_path, sizeof(old_path), "%s/.obs-studio", home) <= 0) return; /* make base xdg path if it doesn't already exist */ - if (GetConfigPath(new_path, 512, "") <= 0) + if (GetConfigPath(new_path, sizeof(new_path), "") <= 0) return; if (os_mkdirs(new_path) == MKDIR_ERROR) return; - if (GetConfigPath(new_path, 512, "obs-studio") <= 0) + if (GetConfigPath(new_path, sizeof(new_path), "obs-studio") <= 0) return; if (os_file_exists(old_path) && !os_file_exists(new_path)) { diff --git a/UI/qt-wrappers.cpp b/UI/qt-wrappers.cpp index d75178c6a..5cd56e258 100644 --- a/UI/qt-wrappers.cpp +++ b/UI/qt-wrappers.cpp @@ -42,7 +42,7 @@ static inline void OBSErrorBoxva(QWidget *parent, const char *msg, va_list args) { char full_message[4096]; - vsnprintf(full_message, 4095, msg, args); + vsnprintf(full_message, sizeof(full_message), msg, args); QMessageBox::critical(parent, "Error", full_message); } diff --git a/UI/window-basic-main-profiles.cpp b/UI/window-basic-main-profiles.cpp index e0b576a4f..f4dc8f44f 100644 --- a/UI/window-basic-main-profiles.cpp +++ b/UI/window-basic-main-profiles.cpp @@ -373,13 +373,15 @@ void OBSBasic::DeleteProfile(const char *profileName, const char *profileDir) char profilePath[512]; char basePath[512]; - int ret = GetConfigPath(basePath, 512, "obs-studio/basic/profiles"); + int ret = GetConfigPath(basePath, sizeof(basePath), + "obs-studio/basic/profiles"); if (ret <= 0) { blog(LOG_WARNING, "Failed to get profiles config path"); return; } - ret = snprintf(profilePath, 512, "%s/%s/*", basePath, profileDir); + ret = snprintf(profilePath, sizeof(profilePath), "%s/%s/*", basePath, + profileDir); if (ret <= 0) { blog(LOG_WARNING, "Failed to get path for profile dir '%s'", profileDir); @@ -404,7 +406,8 @@ void OBSBasic::DeleteProfile(const char *profileName, const char *profileDir) os_globfree(glob); - ret = snprintf(profilePath, 512, "%s/%s", basePath, profileDir); + ret = snprintf(profilePath, sizeof(profilePath), "%s/%s", basePath, + profileDir); if (ret <= 0) { blog(LOG_WARNING, "Failed to get path for profile dir '%s'", profileDir);