zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit d688b58810c83f7fc9c3e1967268642854c07c34
parent 95a4588a68d24e1fa007efde14d8f7a86b01a0c4
Author: Johannes Lorenz <[email protected]>
Date:   Mon,  4 Jun 2018 21:12:46 +0200

Silence compiler warnings

* Implement and use fast_strcpy
* Update rtosc

Diffstat:
Msrc/Containers/ScratchString.cpp | 5+++--
Msrc/Effects/EffectMgr.cpp | 2+-
Msrc/Misc/Config.cpp | 2+-
Msrc/Misc/Part.cpp | 3+--
Msrc/Misc/Util.cpp | 6++++++
Msrc/Misc/Util.h | 13+++++++++++++
Msrc/Synth/WatchPoint.cpp | 7++++---
Msrc/UI/Fl_Osc_Tree.H | 4+++-
Msrc/main.cpp | 2+-
9 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/Containers/ScratchString.cpp b/src/Containers/ScratchString.cpp @@ -1,4 +1,5 @@ #include "ScratchString.h" +#include "../Misc/Util.h" #include <cstring> #include <cstdio> @@ -22,7 +23,7 @@ ScratchString::ScratchString(unsigned char num) ScratchString::ScratchString(const char *str) { if(str) - strncpy(c_str, str, SCRATCH_SIZE); + fast_strcpy(c_str, str, SCRATCH_SIZE); else memset(c_str, 0, sizeof(c_str)); } @@ -30,7 +31,7 @@ ScratchString::ScratchString(const char *str) ScratchString ScratchString::operator+(const ScratchString s) { ScratchString ss; - strncpy(ss.c_str, c_str, SCRATCH_SIZE); + fast_strcpy(ss.c_str, c_str, SCRATCH_SIZE); strncat(ss.c_str, s.c_str, SCRATCH_SIZE-strlen(c_str)); return ss; } diff --git a/src/Effects/EffectMgr.cpp b/src/Effects/EffectMgr.cpp @@ -107,7 +107,7 @@ static const rtosc::Ports local_ports = { d.broadcast(d.loc, "i", eff->getpreset()); //update parameters as well - strncpy(loc, d.loc, 1024); + fast_strcpy(loc, d.loc, sizeof(loc)); char *tail = strrchr(loc, '/'); if(!tail) return; diff --git a/src/Misc/Config.cpp b/src/Misc/Config.cpp @@ -30,7 +30,7 @@ namespace zyn { if(!strcmp("", args)) {\ data.reply(loc, "s", obj->name); \ } else { \ - strncpy(obj->name, rtosc_argument(msg, 0).s, length); \ + fast_strcpy(obj->name, rtosc_argument(msg, 0).s, length); \ data.broadcast(loc, "s", obj->name);\ rChangeCb \ } rBOIL_END diff --git a/src/Misc/Part.cpp b/src/Misc/Part.cpp @@ -27,7 +27,6 @@ #include "../Synth/PADnote.h" #include "../Containers/ScratchString.h" #include "../DSP/FFTwrapper.h" -#include "../Misc/Util.h" #include <cstdlib> #include <cstdio> #include <cstring> @@ -240,7 +239,7 @@ Part::Part(Allocator &alloc, const SYNTH_T &synth_, const AbsTime &time_, interpolation(interpolation) { if(prefix_) - strncpy(prefix, prefix_, sizeof(prefix)); + fast_strcpy(prefix, prefix_, sizeof(prefix)); else memset(prefix, 0, sizeof(prefix)); diff --git a/src/Misc/Util.cpp b/src/Misc/Util.cpp @@ -55,6 +55,12 @@ float VelF(float velocity, unsigned char scaling) return powf(velocity, x); } +char *fast_strcpy(char *dest, const char *src, size_t buffersize) +{ + *dest = 0; + return strncat(dest, src, buffersize-1); +} + /* * Get the detune in cents */ diff --git a/src/Misc/Util.h b/src/Misc/Util.h @@ -31,6 +31,19 @@ bool fileexists(const char *filename); using std::min; using std::max; +/** + * Copy string to another memory location, including the terminating zero byte + * @param dest Destination memory location + * @param src Source string + * @param buffersize Maximal number of bytes that you can write to @p dest + * @return A pointer to @p dest + * @warning @p dest and @p src shall not overlap + * @warning if buffersize is larger than strlen(src)+1, unused bytes in @p dest + * are not overwritten. Secure information may be released. Don't use this if + * you want to send the string somewhere else, e.g. via IPC. + */ +char *fast_strcpy(char *dest, const char *src, size_t buffersize); + //Velocity Sensing function extern float VelF(float velocity, unsigned char scaling); diff --git a/src/Synth/WatchPoint.cpp b/src/Synth/WatchPoint.cpp @@ -20,6 +20,7 @@ */ #include "WatchPoint.h" +#include "../Misc/Util.h" #include <cstring> #include <rtosc/thread-link.h> @@ -30,9 +31,9 @@ WatchPoint::WatchPoint(WatchManager *ref, const char *prefix, const char *id) { identity[0] = 0; if(prefix) - strncpy(identity, prefix, 128); + fast_strcpy(identity, prefix, sizeof(identity)); if(id) - strncat(identity, id, 128); + strncat(identity, id, sizeof(identity)); } bool WatchPoint::is_active(void) @@ -78,7 +79,7 @@ void WatchManager::add_watch(const char *id) //Apply to a free slot for(int i=0; i<MAX_WATCH; ++i) { if(!active_list[i][0]) { - strncpy(active_list[i], id, 128); + fast_strcpy(active_list[i], id, MAX_WATCH_PATH); new_active = true; sample_list[i] = 0; break; diff --git a/src/UI/Fl_Osc_Tree.H b/src/UI/Fl_Osc_Tree.H @@ -10,6 +10,7 @@ of the License, or (at your option) any later version. */ #pragma once +#include <cassert> #include <rtosc/ports.h> #include "Fl_Osc_Interface.h" #include <FL/Fl_Tree.H> @@ -77,7 +78,8 @@ class Fl_Osc_Tree: public Fl_Tree } else { char tmpa[1024]; char tmpb[1024]; - strncpy(tmpa, path.c_str(), 1024); + assert(path.length() < 1024); + strncpy(tmpa, path.c_str(), sizeof(tmpa)); char *pound = index(tmpa, '#'); int N = atoi(pound+1); *pound = 0; diff --git a/src/main.cpp b/src/main.cpp @@ -516,7 +516,7 @@ int wmidi = -1; exit(1); } else { - strncpy(master->last_xmz, filename, XMZ_PATH_MAX); + fast_strcpy(master->last_xmz, filename, XMZ_PATH_MAX); master->last_xmz[XMZ_PATH_MAX-1] = 0; master->applyparameters(); cout << "Master file loaded." << endl;