Commit 14e2ee20 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Better error handling in Archive.read()

Inspired by jsdoor's equivalent change.
parent 7448a68a
Pipeline #2796 passed with stage
in 9 minutes and 38 seconds
......@@ -522,17 +522,28 @@ js_read(JSContext *cx, uintN argc, jsval *arglist)
for(;;) {
result = archive_read_data_block(ar, &buff, &size, &offset);
if(result != ARCHIVE_OK)
if(result == ARCHIVE_EOF)
break;
else if(result != ARCHIVE_OK) {
JS_ReportError(cx, "archive_read_next_header() returned %d: %s"
,result, archive_error_string(ar));
retval = JS_FALSE;
break;
}
char* np = realloc(p, total + size);
if(np == NULL)
if(np == NULL) {
JS_ReportError(cx, "realloc failure of %"PRIi64" bytes", total + size);
retval = JS_FALSE;
break;
}
p = np;
memcpy(p + total, buff, size);
total += size;
}
JSString* js_str = JS_NewStringCopyN(cx, p, total);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
if(retval == JS_TRUE) {
JSString* js_str = JS_NewStringCopyN(cx, p, total);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
}
free(p);
break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment