Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
f7d58e81
"googlemock/vscode:/vscode.git/clone" did not exist on "fbef0711cfce7b8f149aac773d30ae48ce3e166c"
Commit
f7d58e81
authored
Sep 26, 2011
by
vladlosev
Browse files
Adds a new macro simplifying use of snprinf on MS platforms.
parent
1b2e5099
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
9 deletions
+18
-9
include/gtest/internal/gtest-port.h
include/gtest/internal/gtest-port.h
+17
-0
src/gtest-printers.cc
src/gtest-printers.cc
+1
-9
No files found.
include/gtest/internal/gtest-port.h
View file @
f7d58e81
...
@@ -1682,6 +1682,23 @@ inline void Abort() { abort(); }
...
@@ -1682,6 +1682,23 @@ inline void Abort() { abort(); }
}
// namespace posix
}
// namespace posix
// MSVC "deprecates" snprintf and issues warnings wherever it is used. In
// order to avoid these warnings, we need to use _snprintf or _snprintf_s on
// MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate
// function in order to achieve that. We use macro definition here because
// snprintf is a variadic function.
#if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
// MSVC 2005 and above support variadic macros.
# define GTEST_SNPRINTF_(buffer, size, format, ...) \
_snprintf_s(buffer, size, size, format, __VA_ARGS__)
#elif defined(_MSC_VER)
// Windows CE does not define _snprintf_s and MSVC prior to 2005 doesn't
// complain about _snprintf.
# define GTEST_SNPRINTF_ _snprintf
#else
# define GTEST_SNPRINTF_ snprintf
#endif
// The maximum number a BiggestInt can represent. This definition
// The maximum number a BiggestInt can represent. This definition
// works no matter BiggestInt is represented in one's complement or
// works no matter BiggestInt is represented in one's complement or
// two's complement.
// two's complement.
...
...
src/gtest-printers.cc
View file @
f7d58e81
...
@@ -55,14 +55,6 @@ namespace {
...
@@ -55,14 +55,6 @@ namespace {
using
::
std
::
ostream
;
using
::
std
::
ostream
;
#if GTEST_OS_WINDOWS_MOBILE // Windows CE does not define _snprintf_s.
# define snprintf _snprintf
#elif _MSC_VER >= 1400 // VC 8.0 and later deprecate snprintf and _snprintf.
# define snprintf _snprintf_s
#elif _MSC_VER
# define snprintf _snprintf
#endif // GTEST_OS_WINDOWS_MOBILE
// Prints a segment of bytes in the given object.
// Prints a segment of bytes in the given object.
void
PrintByteSegmentInObjectTo
(
const
unsigned
char
*
obj_bytes
,
size_t
start
,
void
PrintByteSegmentInObjectTo
(
const
unsigned
char
*
obj_bytes
,
size_t
start
,
size_t
count
,
ostream
*
os
)
{
size_t
count
,
ostream
*
os
)
{
...
@@ -77,7 +69,7 @@ void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
...
@@ -77,7 +69,7 @@ void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
else
else
*
os
<<
'-'
;
*
os
<<
'-'
;
}
}
snprintf
(
text
,
sizeof
(
text
),
"%02X"
,
obj_bytes
[
j
]);
GTEST_SNPRINTF_
(
text
,
sizeof
(
text
),
"%02X"
,
obj_bytes
[
j
]);
*
os
<<
text
;
*
os
<<
text
;
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment