Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit 136c868

Browse files
author
Andy Chu
committed
[oilshell] Check more errors when decoding.
This should give a better error message.
1 parent 9d62685 commit 136c868

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

decoder.c

+12-11
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,6 @@ static yajl_callbacks decode_callbacks = {
232232

233233
PyObject *_internal_decode(_YajlDecoder *self, char *buffer, unsigned int buflen)
234234
{
235-
yajl_handle parser = NULL;
236-
yajl_status yrc;
237-
238235
if (self->elements.used > 0) {
239236
py_yajl_ps_free(self->elements);
240237
py_yajl_ps_init(self->elements);
@@ -245,23 +242,27 @@ PyObject *_internal_decode(_YajlDecoder *self, char *buffer, unsigned int buflen
245242
}
246243

247244
/* callbacks, config, allocfuncs */
248-
parser = yajl_alloc(&decode_callbacks, NULL, (void *)(self));
249-
yrc = yajl_parse(parser, (const unsigned char *)(buffer), buflen);
250-
yajl_complete_parse(parser);
251-
yajl_free(parser);
245+
yajl_handle parser = yajl_alloc(&decode_callbacks, NULL, (void *)(self));
252246

247+
yajl_status yrc;
248+
yrc = yajl_parse(parser, (const unsigned char *)(buffer), buflen);
253249
if (yrc != yajl_status_ok) {
254-
//fprintf(stderr, "YAJL ERROR %d\n", yrc);
255-
//fprintf(stderr, "%s\n", yajl_status_to_string(yrc));
250+
//fprintf(stderr, "YAJL ERROR %s\n", yajl_status_to_string(yrc));
256251
PyErr_SetString(PyExc_ValueError, yajl_status_to_string(yrc));
257252
return NULL;
258253
}
259254

260-
if (self->root == NULL) {
261-
PyErr_SetString(PyExc_ValueError, "The root object is NULL");
255+
yrc = yajl_complete_parse(parser);
256+
if (yrc != yajl_status_ok) {
257+
//fprintf(stderr, "YAJL ERROR %s\n", yajl_status_to_string(yrc));
258+
PyErr_SetString(PyExc_ValueError, yajl_status_to_string(yrc));
262259
return NULL;
263260
}
264261

262+
yajl_free(parser);
263+
264+
assert(self->root != NULL);
265+
265266
// Callee now owns memory, we'll leave refcnt at one and
266267
// null out our pointer.
267268
PyObject *root = self->root;

0 commit comments

Comments
 (0)