Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Update libucl to the latest version
Baptiste Daroussin committed 12 years ago
commit a925fe84f2bda1dc6b02f5aeccbdfdae09783f3f
parent 9bd5449
3 files changed +51 -33
modified external/libucl/src/ucl_chartable.h
@@ -30,16 +30,17 @@ static const unsigned char ucl_chartable[255] = {
UCL_CHARACTER_VALUE_END, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED,
UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED,
UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED,
-
UCL_CHARACTER_WHITESPACE, UCL_CHARACTER_WHITESPACE|UCL_CHARACTER_VALUE_END,
-
UCL_CHARACTER_WHITESPACE, UCL_CHARACTER_WHITESPACE,
-
UCL_CHARACTER_WHITESPACE|UCL_CHARACTER_VALUE_END, UCL_CHARACTER_DENIED,
+
UCL_CHARACTER_WHITESPACE|UCL_CHARACTER_WHITESPACE_UNSAFE,
+
UCL_CHARACTER_WHITESPACE_UNSAFE|UCL_CHARACTER_VALUE_END,
+
UCL_CHARACTER_WHITESPACE_UNSAFE, UCL_CHARACTER_WHITESPACE_UNSAFE,
+
UCL_CHARACTER_WHITESPACE_UNSAFE|UCL_CHARACTER_VALUE_END, UCL_CHARACTER_DENIED,
UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED,
UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED,
UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED,
UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED,
UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED,
UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED,
-
UCL_CHARACTER_WHITESPACE|UCL_CHARACTER_VALUE_STR /*   */,
+
UCL_CHARACTER_WHITESPACE|UCL_CHARACTER_WHITESPACE_UNSAFE|UCL_CHARACTER_VALUE_STR /*   */,
UCL_CHARACTER_VALUE_STR /* ! */, UCL_CHARACTER_VALUE_STR /* " */,
UCL_CHARACTER_VALUE_END /* # */, UCL_CHARACTER_VALUE_STR /* $ */,
UCL_CHARACTER_VALUE_STR /* % */, UCL_CHARACTER_VALUE_STR /* & */,
modified external/libucl/src/ucl_internal.h
@@ -68,10 +68,11 @@ enum ucl_character_type {
	UCL_CHARACTER_KEY = 1,
	UCL_CHARACTER_KEY_START = 1 << 1,
	UCL_CHARACTER_WHITESPACE = 1 << 2,
-
	UCL_CHARACTER_VALUE_END = 1 << 3,
-
	UCL_CHARACTER_VALUE_STR = 1 << 4,
-
	UCL_CHARACTER_VALUE_DIGIT = 1 << 5,
-
	UCL_CHARACTER_VALUE_DIGIT_START = 1 << 6
+
	UCL_CHARACTER_WHITESPACE_UNSAFE = 1 << 3,
+
	UCL_CHARACTER_VALUE_END = 1 << 4,
+
	UCL_CHARACTER_VALUE_STR = 1 << 5,
+
	UCL_CHARACTER_VALUE_DIGIT = 1 << 6,
+
	UCL_CHARACTER_VALUE_DIGIT_START = 1 << 7
};

struct ucl_macro {
modified external/libucl/src/ucl_parser.c
@@ -88,19 +88,7 @@ start:
		}
	}
	else if (*p == '/' && chunk->remain >= 2) {
-
		if (p[1] == '/' && parser->state != UCL_STATE_SCOMMENT &&
-
				parser->state != UCL_STATE_MCOMMENT) {
-
			ucl_chunk_skipc (chunk, *++p);
-
			chunk->pos = p;
-
			while (p < chunk->end) {
-
				if (*p == '\n') {
-
					ucl_chunk_skipc (chunk, *++p);
-
					goto start;
-
				}
-
				ucl_chunk_skipc (chunk, *++p);
-
			}
-
		}
-
		else if (p[1] == '*') {
+
		if (p[1] == '*') {
			ucl_chunk_skipc (chunk, *++p);
			comments_nested ++;
			ucl_chunk_skipc (chunk, *++p);
@@ -210,7 +198,7 @@ static inline bool
ucl_lex_is_comment (const unsigned char c1, const unsigned char c2)
{
	if (c1 == '/') {
-
		if (c2 == '/' || c2 == '*') {
+
		if (c2 == '*') {
			return true;
		}
	}
@@ -650,6 +638,10 @@ ucl_parse_key (struct ucl_parser *parser,
	/* Create a new object */
	nobj = ucl_object_new ();
	nobj->key = malloc (end - c + 1);
+
	if (nobj->key == NULL) {
+
		ucl_set_err (chunk, 0, "cannot allocate memory for a key", err);
+
		return false;
+
	}
	if (parser->flags & UCL_FLAG_KEY_LOWERCASE) {
		ucl_strlcpy_tolower (nobj->key, c, end - c + 1);
	}
@@ -776,6 +768,7 @@ ucl_parse_value (struct ucl_parser *parser, struct ucl_chunk *chunk, UT_string *
	struct ucl_stack *st;
	ucl_object_t *obj = NULL;
	unsigned int stripped_spaces;
+
	int str_len;

	p = chunk->pos;

@@ -867,9 +860,17 @@ ucl_parse_value (struct ucl_parser *parser, struct ucl_chunk *chunk, UT_string *
								UCL_CHARACTER_WHITESPACE)) {
							stripped_spaces ++;
						}
-
						obj->value.sv = malloc (chunk->pos - c + 1 - stripped_spaces);
-
						ucl_strlcpy (obj->value.sv, c, chunk->pos - c + 1 - stripped_spaces);
-
						ucl_unescape_json_string (obj->value.sv);
+
						str_len = chunk->pos - c + 1 - stripped_spaces;
+
						if (str_len <= 0) {
+
							ucl_set_err (chunk, 0, "string value must not be empty", err);
+
							return false;
+
						}
+
						obj->value.sv = malloc (str_len);
+
						if (obj->value.sv == NULL) {
+
							ucl_set_err (chunk, 0, "cannot allocate memory for a string", err);
+
							return false;
+
						}
+
						ucl_strlcpy (obj->value.sv, c, str_len);
						obj->type = UCL_STRING;
					}
					parser->state = UCL_STATE_AFTER_VALUE;
@@ -885,9 +886,24 @@ ucl_parse_value (struct ucl_parser *parser, struct ucl_chunk *chunk, UT_string *
					return false;
				}
				if (!ucl_maybe_parse_boolean (obj, c, chunk->pos - c)) {
-
					obj->value.sv = malloc (chunk->pos - c + 1);
-
					ucl_strlcpy (obj->value.sv, c, chunk->pos - c + 1);
-
					ucl_unescape_json_string (obj->value.sv);
+
					/* TODO: remove cut&paste */
+
					/* Cut trailing spaces */
+
					stripped_spaces = 0;
+
					while (ucl_test_character (*(chunk->pos - 1 - stripped_spaces),
+
							UCL_CHARACTER_WHITESPACE)) {
+
						stripped_spaces ++;
+
					}
+
					str_len = chunk->pos - c + 1 - stripped_spaces;
+
					if (str_len <= 0) {
+
						ucl_set_err (chunk, 0, "string value must not be empty", err);
+
						return false;
+
					}
+
					obj->value.sv = malloc (str_len);
+
					if (obj->value.sv == NULL) {
+
						ucl_set_err (chunk, 0, "cannot allocate memory for a string", err);
+
						return false;
+
					}
+
					ucl_strlcpy (obj->value.sv, c, str_len);
					obj->type = UCL_STRING;
				}
				parser->state = UCL_STATE_AFTER_VALUE;
@@ -1036,7 +1052,7 @@ ucl_parse_macro_value (struct ucl_parser *parser,
		p ++;
		/* Skip spaces at the beginning */
		while (p < chunk->end) {
-
			if (ucl_test_character (*p, UCL_CHARACTER_WHITESPACE)) {
+
			if (ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE)) {
				ucl_chunk_skipc (chunk, *p);
				p ++;
			}
@@ -1075,7 +1091,7 @@ ucl_parse_macro_value (struct ucl_parser *parser,
	/* We are at the end of a macro */
	/* Skip ';' and space characters and return to previous state */
	while (p < chunk->end) {
-
		if (!ucl_test_character (*p, UCL_CHARACTER_WHITESPACE) && *p != ';') {
+
		if (!ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE) && *p != ';') {
			break;
		}
		ucl_chunk_skipc (chunk, *p);
@@ -1142,7 +1158,7 @@ ucl_state_machine (struct ucl_parser *parser, UT_string **err)
			break;
		case UCL_STATE_KEY:
			/* Skip any spaces */
-
			while (p < chunk->end && ucl_test_character (*p, UCL_CHARACTER_WHITESPACE)) {
+
			while (p < chunk->end && ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE)) {
				ucl_chunk_skipc (chunk, *p);
				p ++;
			}
@@ -1196,7 +1212,7 @@ ucl_state_machine (struct ucl_parser *parser, UT_string **err)
			p = chunk->pos;
			break;
		case UCL_STATE_MACRO_NAME:
-
			if (!ucl_test_character (*p, UCL_CHARACTER_WHITESPACE)) {
+
			if (!ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE)) {
				ucl_chunk_skipc (chunk, *p);
				p ++;
			}
@@ -1210,7 +1226,7 @@ ucl_state_machine (struct ucl_parser *parser, UT_string **err)
				}
				/* Now we need to skip all spaces */
				while (p < chunk->end) {
-
					if (!ucl_test_character (*p, UCL_CHARACTER_WHITESPACE)) {
+
					if (!ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE)) {
						if (ucl_lex_is_comment (p[0], p[1])) {
							/* Skip comment */
							if (!ucl_skip_comments (parser, err)) {