clang-tidy: add Chrome-inspired checks
[lttng-tools.git] / tests / utils / xml-utils / validate_xml.cpp
index bb67e56e17edea75706b56c50ec072c49f2433be..ee1e552f85fb5b2f18cb7b5c0e7f568d4277cb64 100644 (file)
@@ -1,45 +1,45 @@
 /*
- * Copyright (C) 2014 Jonathan Rajotte <jonathan.r.julien@gmail.com>
+ * Copyright (C) 2014 EfficiOS Inc.
  *
  * SPDX-License-Identifier: LGPL-2.1-only
  *
  */
 
- /*
-  * This script validate and xml from an xsd.
-  * argv[1] Path of the xsd
-  * argv[2] Path to the XML to be validated
-  */
+/*
+ * This script validate and xml from an xsd.
+ * argv[1] Path of the xsd
+ * argv[2] Path to the XML to be validated
+ */
+
+#include <common/macros.hpp>
+
+#include <lttng/lttng-error.h>
 
 #include <ctype.h>
+#include <dirent.h>
+#include <inttypes.h>
+#include <libxml/parser.h>
+#include <libxml/xmlschemas.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <inttypes.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
 
-#include <libxml/xmlschemas.h>
-#include <libxml/parser.h>
-
-#include <lttng/lttng-error.h>
-#include <common/macros.h>
-
+namespace {
 struct validation_ctx {
        xmlSchemaParserCtxtPtr parser_ctx;
        xmlSchemaPtr schema;
        xmlSchemaValidCtxtPtr schema_validation_ctx;
 };
+} /* namespace */
 
-enum command_err_code {
-       CMD_SUCCESS = 0,
-       CMD_ERROR
-};
+enum command_err_code { CMD_SUCCESS = 0, CMD_ERROR };
 
-static
-void xml_error_handler(void *ctx, const char *format, ...)
+static ATTR_FORMAT_PRINTF(2, 3) void xml_error_handler(void *ctx __attribute__((unused)),
+                                                      const char *format,
+                                                      ...)
 {
        char *err_msg;
        va_list args;
@@ -49,8 +49,7 @@ void xml_error_handler(void *ctx, const char *format, ...)
        ret = vasprintf(&err_msg, format, args);
        va_end(args);
        if (ret == -1) {
-               fprintf(stderr, "ERR: %s\n",
-                               "String allocation failed in xml error handle");
+               fprintf(stderr, "ERR: %s\n", "String allocation failed in xml error handle");
                return;
        }
 
@@ -58,9 +57,7 @@ void xml_error_handler(void *ctx, const char *format, ...)
        free(err_msg);
 }
 
-static
-void fini_validation_ctx(
-       struct validation_ctx *ctx)
+static void fini_validation_ctx(struct validation_ctx *ctx)
 {
        if (ctx->parser_ctx) {
                xmlSchemaFreeParserCtxt(ctx->parser_ctx);
@@ -77,9 +74,7 @@ void fini_validation_ctx(
        memset(ctx, 0, sizeof(struct validation_ctx));
 }
 
-static
-int init_validation_ctx(
-       struct validation_ctx *ctx, char *xsd_path)
+static int init_validation_ctx(struct validation_ctx *ctx, char *xsd_path)
 {
        int ret;
 
@@ -93,8 +88,7 @@ int init_validation_ctx(
                ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
                goto end;
        }
-       xmlSchemaSetParserErrors(ctx->parser_ctx, xml_error_handler,
-               xml_error_handler, NULL);
+       xmlSchemaSetParserErrors(ctx->parser_ctx, xml_error_handler, xml_error_handler, nullptr);
 
        ctx->schema = xmlSchemaParse(ctx->parser_ctx);
        if (!ctx->schema) {
@@ -108,8 +102,8 @@ int init_validation_ctx(
                goto end;
        }
 
-       xmlSchemaSetValidErrors(ctx->schema_validation_ctx, xml_error_handler,
-                       xml_error_handler, NULL);
+       xmlSchemaSetValidErrors(
+               ctx->schema_validation_ctx, xml_error_handler, xml_error_handler, nullptr);
        ret = 0;
 
 end:
@@ -122,7 +116,7 @@ end:
 static int validate_xml(const char *xml_file_path, struct validation_ctx *ctx)
 {
        int ret;
-       xmlDocPtr doc = NULL;
+       xmlDocPtr doc = nullptr;
 
        LTTNG_ASSERT(xml_file_path);
        LTTNG_ASSERT(ctx);
@@ -144,14 +138,16 @@ static int validate_xml(const char *xml_file_path, struct validation_ctx *ctx)
 
        ret = CMD_SUCCESS;
 end:
+       if (doc) {
+               xmlFreeDoc(doc);
+       }
        return ret;
-
-
 }
-int main(int argc, char **argv, char *env[])
+
+int main(int argc, char **argv)
 {
        int ret;
-       struct validation_ctx ctx = { 0 };
+       struct validation_ctx ctx = {};
 
        /* Check if we have all argument */
        if (argc < 3) {
This page took 0.024471 seconds and 4 git commands to generate.