ucl_chunk_skipc (chunk, p);
}
else {
- if (p - c > 0) {
+ if (c != NULL && p - c > 0) {
/* We got macro name */
macro_len = (size_t) (p - c);
HASH_FIND (hh, parser->macroes, c, macro_len, macro);
macro_start, macro_len);
parser->state = parser->prev_state;
- if (macro_escaped == NULL) {
+ if (macro_escaped == NULL && macro != NULL) {
if (macro->is_context) {
ret = macro->h.context_handler (macro_start, macro_len,
macro_args,
macro->ud);
}
}
- else {
+ else if (macro != NULL) {
if (macro->is_context) {
ret = macro->h.context_handler (macro_escaped, macro_len,
macro_args,
UCL_FREE (macro_len + 1, macro_escaped);
}
+ else {
+ ret = false;
+ ucl_set_err (parser, UCL_EINTERNAL,
+ "internal error: parser has macro undefined", &parser->err);
+ }
/*
* Chunk can be modified within macro handler
*/
chunk = parser->chunks;
p = chunk->pos;
+
if (macro_args) {
ucl_object_unref (macro_args);
}
+
if (!ret) {
return false;
}
#include "ucl_chartable.h"
#include "kvec.h"
#include <stdarg.h>
-#include <stdio.h> /* for asprintf */
+#include <stdio.h> /* for snprintf */
#ifndef _WIN32
#include <glob.h>
#endif
#ifdef CURL_FOUND
+/* Seems to be broken */
+#define CURL_DISABLE_TYPECHECK 1
#include <curl/curl.h>
#endif
#ifdef HAVE_FETCH_H
close (fd);
ucl_create_err (err, "cannot mmap file %s: %s",
filename, strerror (errno));
+ *buf = NULL;
+
return false;
}
*buflen = st.st_size;
ucl_create_err (&parser->err, "cannot verify file %s: %s",
filebuf,
ERR_error_string (ERR_get_error (), NULL));
- if (siglen > 0) {
+ if (sigbuf) {
ucl_munmap (sigbuf, siglen);
}
return false;
}
- if (siglen > 0) {
+ if (sigbuf) {
ucl_munmap (sigbuf, siglen);
}
#endif
if (nest_obj == NULL) {
ucl_create_err (&parser->err, "cannot allocate memory for an object");
- if (buflen > 0) {
+ if (buf) {
ucl_munmap (buf, buflen);
}
nest_obj = ucl_object_new_full (UCL_OBJECT, params->priority);
if (nest_obj == NULL) {
ucl_create_err (&parser->err, "cannot allocate memory for an object");
- if (buflen > 0) {
+ if (buf) {
ucl_munmap (buf, buflen);
}
new_obj = ucl_object_typed_new (UCL_ARRAY);
if (new_obj == NULL) {
ucl_create_err (&parser->err, "cannot allocate memory for an object");
- if (buflen > 0) {
+ if (buf) {
ucl_munmap (buf, buflen);
}
nest_obj = ucl_object_new_full (UCL_OBJECT, params->priority);
if (nest_obj == NULL) {
ucl_create_err (&parser->err, "cannot allocate memory for an object");
- if (buflen > 0) {
+ if (buf) {
ucl_munmap (buf, buflen);
}
ucl_create_err (&parser->err,
"Conflicting type for key: %s",
params->prefix);
- if (buflen > 0) {
+ if (buf) {
ucl_munmap (buf, buflen);
}
/* Put all of the content of the include inside that object */
parser->stack->obj->value.ov = container;
- if (nest_obj != NULL) {
- st = UCL_ALLOC (sizeof (struct ucl_stack));
- if (st == NULL) {
- ucl_create_err (&parser->err, "cannot allocate memory for an object");
- ucl_object_unref (nest_obj);
- if (buflen > 0) {
- ucl_munmap (buf, buflen);
- }
+ st = UCL_ALLOC (sizeof (struct ucl_stack));
+ if (st == NULL) {
+ ucl_create_err (&parser->err, "cannot allocate memory for an object");
+ ucl_object_unref (nest_obj);
- return false;
+ if (buf) {
+ ucl_munmap (buf, buflen);
}
- st->obj = nest_obj;
- st->level = parser->stack->level;
- LL_PREPEND (parser->stack, st);
- parser->cur_obj = nest_obj;
+
+ return false;
}
+ st->obj = nest_obj;
+ st->level = parser->stack->level;
+ LL_PREPEND (parser->stack, st);
+ parser->cur_obj = nest_obj;
}
res = ucl_parser_add_chunk_full (parser, buf, buflen, params->priority,
}
if (len > 0) {
- asprintf (&load_file, "%.*s", (int)len, data);
-
+ load_file = malloc (len + 1);
if (!load_file) {
ucl_create_err (&parser->err, "cannot allocate memory for suffix");
return false;
}
+ snprintf (load_file, len + 1, "%.*s", (int)len, data);
+
if (!ucl_fetch_file (load_file, &buf, &buflen, &parser->err,
!try_load)) {
free (load_file);
if (old_obj != NULL) {
ucl_create_err (&parser->err, "Key %s already exists", prefix);
- if (buflen > 0) {
+ if (buf) {
ucl_munmap (buf, buflen);
}
}
}
else if (strcasecmp (target, "int") == 0) {
- asprintf(&tmp, "%.*s", (int)buflen, buf);
- iv = strtoll(tmp, NULL, 10);
+ tmp = malloc (buflen + 1);
+
+ if (tmp == NULL) {
+ ucl_create_err (&parser->err, "Memory allocation failed");
+ if (buf) {
+ ucl_munmap (buf, buflen);
+ }
+
+ return false;
+ }
+
+ snprintf (tmp, buflen + 1, "%.*s", (int)buflen, buf);
+ iv = strtoll (tmp, NULL, 10);
obj = ucl_object_fromint (iv);
+ free (tmp);
}
- if (buflen > 0) {
+ if (buf) {
ucl_munmap (buf, buflen);
}