浏览代码

UI: Fix snprintf calls with literals as buffer sizes

PatTheMav 3 年之前
父节点
当前提交
4ff789e24c
共有 3 个文件被更改,包括 11 次插入8 次删除
  1. 4 4
      UI/obs-app.cpp
  2. 1 1
      UI/qt-wrappers.cpp
  3. 6 3
      UI/window-basic-main-profiles.cpp

+ 4 - 4
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)) {

+ 1 - 1
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);
 }

+ 6 - 3
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);