From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/webrtc/common/csf_common.h | 90 ++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 dom/media/webrtc/common/csf_common.h (limited to 'dom/media/webrtc/common/csf_common.h') 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 +#include +#include +#include + +/* + +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 +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 -- cgit v1.2.3