summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2020-06-10 20:52:10 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2020-06-10 20:52:10 +0200
commit5cfa736ad08cb37cd60a09752cd7df997f2370f8 (patch)
tree29641c7ad853c41459f021d2ec4f72eb9b0cde45 /tools.c
parent8a282ef267b73c4d4a6f03e174946fd23692f58e (diff)
downloadvdr-5cfa736ad08cb37cd60a09752cd7df997f2370f8.tar.gz
vdr-5cfa736ad08cb37cd60a09752cd7df997f2370f8.tar.bz2
Fixed memory handling in cString::Append()
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/tools.c b/tools.c
index 7330fce1..67136221 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 4.11 2018/03/04 10:28:04 kls Exp $
+ * $Id: tools.c 4.12 2020/06/10 20:52:10 kls Exp $
*/
#include "tools.h"
@@ -1099,12 +1099,16 @@ cString &cString::operator=(const char *String)
cString &cString::Append(const char *String)
{
- int l1 = strlen(s);
- int l2 = strlen(String);
- char *p = (char *)realloc(s, l1 + l2 + 1);
- if (p != s)
- strcpy(p, s);
- strcpy(p + l1, String);
+ if (String) {
+ int l1 = s ? strlen(s) : 0;
+ int l2 = strlen(String);
+ if (char *p = (char *)realloc(s, l1 + l2 + 1)) {
+ s = p;
+ strcpy(s + l1, String);
+ }
+ else
+ esyslog("ERROR: out of memory");
+ }
return *this;
}