diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-06-15 15:02:40 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-06-15 15:02:40 -0700 |
| commit | b90e66f7c7546aaf9c0c8a6bf14cc834f82fa680 (patch) | |
| tree | 2c9e5f87535084e91ebe26e6e43a3136dcc4c258 /node/Utils.hpp | |
| parent | 4446dbde5edfd8f7ec9730886e5d577259d73de2 (diff) | |
| download | infinitytier-b90e66f7c7546aaf9c0c8a6bf14cc834f82fa680.tar.gz infinitytier-b90e66f7c7546aaf9c0c8a6bf14cc834f82fa680.zip | |
ManagedRoute, which applies C++ RAII to injected routes. Move RoutingTable to attic.
Diffstat (limited to 'node/Utils.hpp')
| -rw-r--r-- | node/Utils.hpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/node/Utils.hpp b/node/Utils.hpp index 3f4cc765..04838f1c 100644 --- a/node/Utils.hpp +++ b/node/Utils.hpp @@ -225,18 +225,24 @@ public: } /** - * Perform a safe C string copy + * Perform a safe C string copy, ALWAYS null-terminating the result * - * @param dest Destination buffer - * @param len Length of buffer - * @param src Source string + * This will never ever EVER result in dest[] not being null-terminated + * regardless of any input parameter (other than len==0 which is invalid). + * + * @param dest Destination buffer (must not be NULL) + * @param len Length of dest[] (if zero, false is returned and nothing happens) + * @param src Source string (if NULL, dest will receive a zero-length string and true is returned) * @return True on success, false on overflow (buffer will still be 0-terminated) */ static inline bool scopy(char *dest,unsigned int len,const char *src) - throw() { if (!len) return false; // sanity check + if (!src) { + *dest = (char)0; + return true; + } char *end = dest + len; while ((*dest++ = *src++)) { if (dest == end) { |
