changeset 248:3a2a29f801ed

Add check for NULL strings.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 16 Feb 2016 18:21:54 +0200
parents 2fc282c365a8
children 35cfda75606b
files th_string.c
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/th_string.c	Tue Feb 16 18:19:37 2016 +0200
+++ b/th_string.c	Tue Feb 16 18:21:54 2016 +0200
@@ -195,8 +195,13 @@
     const char *str, const char padMode, const char padChar,
     const int width, const int prec)
 {
-    int nwidth = width - strlen(str);
-    int ret = 0;
+    int nwidth, ret = 0;
+
+    // Check for null strings
+    if (str == NULL)
+        str = "(null)";
+
+    nwidth = width - strlen(str);
 
     // Prefix padding?
     if (padMode != '-' && nwidth > 0)