Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
[linux] use inline wrapper for strcat_s, strcpy_s, strncpy_s
Browse files Browse the repository at this point in the history
  • Loading branch information
q4a committed Jun 6, 2022
1 parent 2b9cba6 commit aa63dd6
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/libs/common/include/storm_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@

#include "safe_str_lib.h"

// use custom strcpy_s instead of safeclib: #define strcpy_s(dest, dmax, src)
#undef strcpy_s
// use inline wrapper for strcat_s from safeclib instead of #define strcat_s
#undef strcat_s
inline errno_t strcat_s(char *restrict dest, rsize_t size, const char *restrict src)
{
return _strcat_s_chk(dest, size, src, BOS(dest));
}

inline int strcpy_s(char *dest, size_t size, const char *src)
template <rsize_t size> inline errno_t strcat_s(char (&dest)[size], const char *src)
{
if (!dest)
return EINVAL;
return strcat_s(dest, size, src);
}

if (0 == size)
{
dest[0] = '\0';
return ERANGE;
}
// use inline wrapper for strcpy_s from safeclib instead of #define strcpy_s
#undef strcpy_s
inline errno_t strcpy_s(char *restrict dest, rsize_t size, const char *restrict src)
{
return _strcpy_s_chk(dest, size, src, BOS(dest));
}

if (!src)
{
dest[0] = '\0';
return EINVAL;
}
template <rsize_t size> inline errno_t strcpy_s(char (&dest)[size], const char *src)
{
return strcpy_s(dest, size, src);
}

size_t i;
for (i = 0; i < size; i++)
{
if ((dest[i] = src[i]) == '\0')
return 0;
}
dest[0] = '\0';
return ERANGE;
// use inline wrapper for strncpy_s from safeclib instead of #define strncpy_s
#undef strncpy_s
inline errno_t strncpy_s(char *restrict dest, rsize_t size, const char *restrict src, rsize_t count)
{
return _strncpy_s_chk(dest, size, src, count, BOS(dest), BOS(src));
}

template <std::size_t size> inline int strcpy_s(char (&dest)[size], const char *src)
template <rsize_t size> inline errno_t strncpy_s(char (&dest)[size], const char *src, rsize_t count)
{
return strcpy_s(dest, size, src);
return strncpy_s(dest, size, src, count);
}

// use custom sprintf_s instead of safeclib: #define sprintf_s(dest, dmax, ...)
#undef sprintf_s

template <size_t size> inline int sprintf_s(char (&buffer)[size], const char *format, ...)
template <rsize_t size> inline int sprintf_s(char (&buffer)[size], const char *format, ...)
{
va_list args;
va_start(args, format);
Expand All @@ -49,7 +49,7 @@ template <size_t size> inline int sprintf_s(char (&buffer)[size], const char *fo
return result;
}

inline int sprintf_s(char *buffer, size_t size, const char *format, ...)
inline int sprintf_s(char *buffer, rsize_t size, const char *format, ...)
{
va_list ap;
va_start(ap, format);
Expand Down

0 comments on commit aa63dd6

Please sign in to comment.