summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/common/csf_common.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /dom/media/webrtc/common/csf_common.h
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--dom/media/webrtc/common/csf_common.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/dom/media/webrtc/common/csf_common.h b/dom/media/webrtc/common/csf_common.h
new file mode 100644
index 0000000000..8b01047553
--- /dev/null
+++ b/dom/media/webrtc/common/csf_common.h
@@ -0,0 +1,90 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef _CSF_COMMON_E58E5677_950A_424c_B6C2_CA180092E6A2_H
+#define _CSF_COMMON_E58E5677_950A_424c_B6C2_CA180092E6A2_H
+
+#include <assert.h>
+#include <memory>
+#include <vector>
+#include <stdlib.h>
+
+/*
+
+This header file defines:
+
+csf_countof
+csf_sprintf
+csf_vsprintf
+
+*/
+
+/*
+ General security tip: Ensure that "format" is never a user-defined string.
+ Format should ALWAYS be something that's built into your code, not user
+ supplied. For example: never write:
+
+ csf_sprintf(buffer, csf_countof(buffer), pUserSuppliedString);
+
+ Instead write:
+
+ csf_sprintf(buffer, csf_countof(buffer), "%s", pUserSuppliedString);
+
+*/
+
+#ifdef WIN32
+# if !defined(_countof)
+# if !defined(__cplusplus)
+# define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
+# else
+extern "C++" {
+template <typename _CountofType, size_t _SizeOfArray>
+char (*_csf_countof_helper(_CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
+# define _countof(_Array) sizeof(*_csf_countof_helper(_Array))
+}
+# endif
+# endif
+#else
+# define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
+#endif
+// csf_countof
+
+#define csf_countof(anArray) _countof(anArray)
+
+// csf_sprintf
+
+#ifdef _WIN32
+// Unlike snprintf, sprintf_s guarantees that the buffer will be null-terminated
+// (unless the buffer size is zero).
+# define csf_sprintf(/* char* */ buffer, \
+ /* size_t */ sizeOfBufferInCharsInclNullTerm, \
+ /* const char * */ format, ...) \
+ _snprintf_s(buffer, sizeOfBufferInCharsInclNullTerm, _TRUNCATE, format, \
+ __VA_ARGS__)
+#else
+# define csf_sprintf(/* char */ buffer, \
+ /* size_t */ sizeOfBufferInCharsInclNullTerm, \
+ /* const char * */ format, ...) \
+ snprintf(buffer, sizeOfBufferInCharsInclNullTerm, format, __VA_ARGS__); \
+ buffer[sizeOfBufferInCharsInclNullTerm - 1] = '\0'
+#endif
+
+// csf_vsprintf
+
+#ifdef _WIN32
+# define csf_vsprintf(/* char* */ buffer, \
+ /* size_t */ sizeOfBufferInCharsInclNullTerm, \
+ /* const char * */ format, /* va_list */ vaList) \
+ vsnprintf_s(buffer, sizeOfBufferInCharsInclNullTerm, _TRUNCATE, format, \
+ vaList); \
+ buffer[sizeOfBufferInCharsInclNullTerm - 1] = '\0'
+#else
+# define csf_vsprintf(/* char */ buffer, \
+ /* size_t */ sizeOfBufferInCharsInclNullTerm, \
+ /* const char * */ format, /* va_list */ vaList) \
+ vsprintf(buffer, format, vaList); \
+ buffer[sizeOfBufferInCharsInclNullTerm - 1] = '\0'
+#endif
+
+#endif