fix compilation on later glibc/gcc versions with stricter checks
[project/uci.git] / libuci.c
index bc68462fad19036288ba609a01fb20f580cc6810..947b029e970299fa99acabeb3f07ee6d9cc5ee6e 100644 (file)
--- a/libuci.c
+++ b/libuci.c
@@ -167,13 +167,15 @@ uci_get_errorstr(struct uci_context *ctx, char **dest, const char *prefix)
        default:
                break;
        }
-       if (dest)
-               asprintf(dest, format,
+       if (dest) {
+               err = asprintf(dest, format,
                        (prefix ? prefix : ""), (prefix ? ": " : ""),
                        (ctx->func ? ctx->func : ""), (ctx->func ? ": " : ""),
                        uci_errstr[err],
                        error_info);
-       else {
+               if (err < 0)
+                       *dest = NULL;
+       } else {
                strcat(error_info, "\n");
                fprintf(stderr, format,
                        (prefix ? prefix : ""), (prefix ? ": " : ""),