If snprint_keyword() failed to correctly set up sbuf, don't print it.
Instead, return an error.

Signed-off-by: Benjamin Marzinski <[email protected]>
---
 libmpathutil/parser.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libmpathutil/parser.c b/libmpathutil/parser.c
index 014d9b83..8d3ac53a 100644
--- a/libmpathutil/parser.c
+++ b/libmpathutil/parser.c
@@ -152,7 +152,7 @@ int
 snprint_keyword(struct strbuf *buff, const char *fmt, struct keyword *kw,
                const void *data)
 {
-       int r;
+       int r = 0;
        char *f;
        struct config *conf;
        STRBUF_ON_STACK(sbuf);
@@ -190,8 +190,10 @@ snprint_keyword(struct strbuf *buff, const char *fmt, 
struct keyword *kw,
                }
        } while (*fmt++);
 out:
-       return __append_strbuf_str(buff, get_strbuf_str(&sbuf),
-                                  get_strbuf_len(&sbuf));
+       if (r >= 0)
+               r = __append_strbuf_str(buff, get_strbuf_str(&sbuf),
+                                       get_strbuf_len(&sbuf));
+       return r;
 }
 
 static const char quote_marker[] = { '\0', '"', '\0' };
-- 
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

Reply via email to