From 5a61c81cc21e6f18b83b3b6962d5d18c777fcb73 Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Sat, 27 Jun 2015 12:58:47 +0200 Subject: Teach copy_string to return NULL on empty string In subsurface we store no value as a NULL pointer everywhere, but sometimes some structures returns a empty field as a empty string. This teaches our helper copy_string to return NULL if you try to copy a empty string. This fixes a bug where we store buddy and divemaster in git as empty strings if they passed via MainTab::saveTaggedStrings(). Suggested-by: Linus Torvalds Signed-off-by: Anton Lundin Signed-off-by: Dirk Hohndel --- dive.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dive.h b/dive.h index f07c9d9b2..318f822e7 100644 --- a/dive.h +++ b/dive.h @@ -32,7 +32,7 @@ static inline int same_string(const char *a, const char *b) static inline char *copy_string(const char *s) { - return s ? strdup(s) : NULL; + return (s && *s) ? strdup(s) : NULL; } #include -- cgit v1.2.3-70-g09d2