Browse Source

Add assertions to make sure size > 0

Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
pull/77/head
Christopher Arndt Filipe Coelho <falktx@falktx.com> 4 years ago
parent
commit
b5d98f4bd3
1 changed files with 3 additions and 0 deletions
  1. +3
    -0
      distrho/src/DistrhoPluginVST.cpp

+ 3
- 0
distrho/src/DistrhoPluginVST.cpp View File

@@ -71,18 +71,21 @@ static const writeMidiFunc writeMidiCallback = nullptr;

void strncpy(char* const dst, const char* const src, const size_t size)
{
DISTRHO_SAFE_ASSERT_RETURN(size > 0,);
std::memcpy(dst, src, std::min(std::strlen(src), size-1));
dst[size-1] = '\0';
}

void snprintf_param(char* const dst, const float value, const size_t size)
{
DISTRHO_SAFE_ASSERT_RETURN(size > 0,);
std::snprintf(dst, size-1, "%f", value);
dst[size-1] = '\0';
}

void snprintf_iparam(char* const dst, const int32_t value, const size_t size)
{
DISTRHO_SAFE_ASSERT_RETURN(size > 0,);
std::snprintf(dst, size-1, "%d", value);
dst[size-1] = '\0';
}


Loading…
Cancel
Save