Browse Source

deps: Replace invocations of sprintf with snprintf

Fixes deprecation warnings in Xcode 14/clang on macOS and reduces
chance of buffer overflows.
PatTheMav 3 years ago
parent
commit
bd12a3e919

+ 0 - 4
deps/libcaption/caption/caption.h

@@ -134,10 +134,6 @@ size_t caption_frame_to_text(caption_frame_t* frame, utf8_char_t* data);
 /*! \brief
     \param
 */
-#define CAPTION_FRAME_DUMP_BUF_SIZE 8192
-size_t caption_frame_dump_buffer(caption_frame_t* frame, utf8_char_t* buf);
-void caption_frame_dump(caption_frame_t* frame);
-
 #ifdef __cplusplus
 }
 #endif

+ 0 - 54
deps/libcaption/src/caption.c

@@ -403,57 +403,3 @@ size_t caption_frame_to_text(caption_frame_t* frame, utf8_char_t* data)
 
     return size;
 }
-////////////////////////////////////////////////////////////////////////////////
-size_t caption_frame_dump_buffer(caption_frame_t* frame, utf8_char_t* buf)
-{
-    int r, c;
-    size_t bytes, total = 0;
-    bytes = sprintf(buf, "   timestamp: %f\n   row: %02d    col: %02d    roll-up: %d\n",
-        frame->timestamp, frame->state.row, frame->state.col, caption_frame_rollup(frame));
-    total += bytes, buf += bytes;
-    bytes = sprintf(buf, "   00000000001111111111222222222233\t   00000000001111111111222222222233\n"
-                         "   01234567890123456789012345678901\t   01234567890123456789012345678901\n"
-                         "  %s--------------------------------%s\t  %s--------------------------------%s\n",
-        EIA608_CHAR_BOX_DRAWINGS_LIGHT_DOWN_AND_RIGHT, EIA608_CHAR_BOX_DRAWINGS_LIGHT_DOWN_AND_LEFT,
-        EIA608_CHAR_BOX_DRAWINGS_LIGHT_DOWN_AND_RIGHT, EIA608_CHAR_BOX_DRAWINGS_LIGHT_DOWN_AND_LEFT);
-    total += bytes;
-    buf += bytes;
-
-    for (r = 0; r < SCREEN_ROWS; ++r) {
-        bytes = sprintf(buf, "%02d%s", r, EIA608_CHAR_VERTICAL_LINE);
-        total += bytes, buf += bytes;
-
-        // front buffer
-        for (c = 0; c < SCREEN_COLS; ++c) {
-            caption_frame_cell_t* cell = frame_buffer_cell(&frame->front, r, c);
-            bytes = utf8_char_copy(buf, (!cell || 0 == cell->data[0]) ? EIA608_CHAR_SPACE : &cell->data[0]);
-            total += bytes, buf += bytes;
-        }
-
-        bytes = sprintf(buf, "%s\t%02d%s", EIA608_CHAR_VERTICAL_LINE, r, EIA608_CHAR_VERTICAL_LINE);
-        total += bytes, buf += bytes;
-
-        // back buffer
-        for (c = 0; c < SCREEN_COLS; ++c) {
-            caption_frame_cell_t* cell = frame_buffer_cell(&frame->back, r, c);
-            bytes = utf8_char_copy(buf, (!cell || 0 == cell->data[0]) ? EIA608_CHAR_SPACE : &cell->data[0]);
-            total += bytes, buf += bytes;
-        }
-
-        bytes = sprintf(buf, "%s\n", EIA608_CHAR_VERTICAL_LINE);
-        total += bytes, buf += bytes;
-    }
-
-    bytes = sprintf(buf, "  %s--------------------------------%s\t  %s--------------------------------%s\n",
-        EIA608_CHAR_BOX_DRAWINGS_LIGHT_UP_AND_RIGHT, EIA608_CHAR_BOX_DRAWINGS_LIGHT_UP_AND_LEFT,
-        EIA608_CHAR_BOX_DRAWINGS_LIGHT_UP_AND_RIGHT, EIA608_CHAR_BOX_DRAWINGS_LIGHT_UP_AND_LEFT);
-    total += bytes, buf += bytes;
-    return total;
-}
-
-void caption_frame_dump(caption_frame_t* frame)
-{
-    utf8_char_t buff[CAPTION_FRAME_DUMP_BUF_SIZE];
-    caption_frame_dump_buffer(frame, buff);
-    fprintf(stderr, "%s\n", buff);
-}

+ 7 - 7
deps/obs-scripting/obs-scripting-python-import.c

@@ -71,9 +71,9 @@ bool import_python(const char *python_path, python_version_t *python_version)
 
 	char temp[PATH_MAX];
 
-	sprintf(cur_version, VERSION_PATTERN, PY_MAJOR_VERSION_MAX,
-		PY_MINOR_VERSION_MAX);
-	sprintf(temp, FILE_PATTERN, cur_version);
+	snprintf(cur_version, sizeof(cur_version), VERSION_PATTERN,
+		 PY_MAJOR_VERSION_MAX, PY_MINOR_VERSION_MAX);
+	snprintf(temp, sizeof(temp), FILE_PATTERN, cur_version);
 
 	dstr_cat(&lib_candidate_path, temp);
 
@@ -87,10 +87,10 @@ bool import_python(const char *python_path, python_version_t *python_version)
 			break;
 		}
 
-		sprintf(cur_version, VERSION_PATTERN, PY_MAJOR_VERSION_MAX,
-			minor_version);
-		sprintf(next_version, VERSION_PATTERN, PY_MAJOR_VERSION_MAX,
-			--minor_version);
+		snprintf(cur_version, sizeof(cur_version), VERSION_PATTERN,
+			 PY_MAJOR_VERSION_MAX, minor_version);
+		snprintf(next_version, sizeof(next_version), VERSION_PATTERN,
+			 PY_MAJOR_VERSION_MAX, --minor_version);
 		dstr_replace(&lib_candidate_path, cur_version, next_version);
 	} while (minor_version > 5);
 

+ 2 - 2
deps/obs-scripting/obs-scripting-python.c

@@ -1666,8 +1666,8 @@ bool obs_scripting_load_python(const char *python_path)
 	if (python_path && *python_path) {
 #ifdef __APPLE__
 		char temp[PATH_MAX];
-		sprintf(temp, "%s/Python.framework/Versions/Current",
-			python_path);
+		snprintf(temp, sizeof(temp),
+			 "%s/Python.framework/Versions/Current", python_path);
 		os_utf8_to_wcs(temp, 0, home_path, PATH_MAX);
 		Py_SetPythonHome(home_path);
 #else