esnme / ujson4c

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Object unpack may value to wrong output.

lvella opened this issue · comments

If one of the keys parsed by UJObjectUnpack() could is not found, the order which the found keys are stored in output objects is wrong. For instance, following code:

#include <stdio.h>
#include "ujdecode.h"

int main() {
	UJObject obj;
	void *state;
	const char input[] = "{\"a\": {}, \"b\": 200 }";
	size_t cbInput = sizeof(input) - 1;

	const wchar_t *keys[] = { L"a", L"b"};
	UJObject a, b;

	obj = UJDecode(input, cbInput, NULL, &state);

	int ret = UJObjectUnpack(obj, 2, "NN", keys, &a, &b);
	printf("Return value: %d, a = %g, b = %g\n", ret, UJNumericFloat(a), UJNumericFloat(b));

	UJFree(state);
}

will output:

Return value: 1, a = 200, b = 0