Fix API documentation + theoretical NPEs (#602)

This commit is contained in:
Eugene Kliuchnikov 2017-09-20 15:02:01 +02:00 committed by GitHub
parent b6a017492e
commit c60563591a
3 changed files with 17 additions and 11 deletions

View File

@ -72,7 +72,9 @@ typedef enum BrotliEncoderOperation {
* Actual flush is performed when input stream is depleted and there is enough * Actual flush is performed when input stream is depleted and there is enough
* space in output stream. This means that client should repeat * space in output stream. This means that client should repeat
* ::BROTLI_OPERATION_FLUSH operation until @p available_in becomes @c 0, and * ::BROTLI_OPERATION_FLUSH operation until @p available_in becomes @c 0, and
* ::BrotliEncoderHasMoreOutput returns ::BROTLI_FALSE. * ::BrotliEncoderHasMoreOutput returns ::BROTLI_FALSE. If output is acquired
* via ::BrotliEncoderTakeOutput, then operation should be repeated after
* output buffer is drained.
* *
* @warning Until flush is complete, client @b SHOULD @b NOT swap, * @warning Until flush is complete, client @b SHOULD @b NOT swap,
* reduce or extend input stream. * reduce or extend input stream.
@ -86,8 +88,10 @@ typedef enum BrotliEncoderOperation {
* *
* Actual finalization is performed when input stream is depleted and there is * Actual finalization is performed when input stream is depleted and there is
* enough space in output stream. This means that client should repeat * enough space in output stream. This means that client should repeat
* ::BROTLI_OPERATION_FLUSH operation until @p available_in becomes @c 0, and * ::BROTLI_OPERATION_FINISH operation until @p available_in becomes @c 0, and
* ::BrotliEncoderHasMoreOutput returns ::BROTLI_FALSE. * ::BrotliEncoderHasMoreOutput returns ::BROTLI_FALSE. If output is acquired
* via ::BrotliEncoderTakeOutput, then operation should be repeated after
* output buffer is drained.
* *
* @warning Until finalization is complete, client @b SHOULD @b NOT swap, * @warning Until finalization is complete, client @b SHOULD @b NOT swap,
* reduce or extend input stream. * reduce or extend input stream.

View File

@ -174,11 +174,11 @@ static Command ParseParams(Context* params) {
for (i = 1; i < argc; ++i) { for (i = 1; i < argc; ++i) {
const char* arg = argv[i]; const char* arg = argv[i];
size_t arg_len = strlen(arg);
/* C99 5.1.2.2.1: "members argv[0] through argv[argc-1] inclusive shall /* C99 5.1.2.2.1: "members argv[0] through argv[argc-1] inclusive shall
contain pointers to strings"; NULL and 0-length are not forbidden. */ contain pointers to strings"; NULL and 0-length are not forbidden. */
if (!arg || arg_len == 0) { size_t arg_len = arg ? strlen(arg) : 0;
if (arg_len == 0) {
params->not_input_indices[next_option_index++] = i; params->not_input_indices[next_option_index++] = i;
continue; continue;
} }
@ -588,7 +588,9 @@ static BROTLI_BOOL OpenFiles(Context* context) {
static BROTLI_BOOL CloseFiles(Context* context, BROTLI_BOOL success) { static BROTLI_BOOL CloseFiles(Context* context, BROTLI_BOOL success) {
BROTLI_BOOL is_ok = BROTLI_TRUE; BROTLI_BOOL is_ok = BROTLI_TRUE;
if (!context->test_integrity && context->fout) { if (!context->test_integrity && context->fout) {
if (!success) unlink(context->current_output_path); if (!success && context->current_output_path) {
unlink(context->current_output_path);
}
if (fclose(context->fout) != 0) { if (fclose(context->fout) != 0) {
if (success) { if (success) {
fprintf(stderr, "fclose failed [%s]: %s\n", fprintf(stderr, "fclose failed [%s]: %s\n",
@ -612,7 +614,7 @@ static BROTLI_BOOL CloseFiles(Context* context, BROTLI_BOOL success) {
is_ok = BROTLI_FALSE; is_ok = BROTLI_FALSE;
} }
} }
if (success && context->junk_source) { if (success && context->junk_source && context->current_input_path) {
unlink(context->current_input_path); unlink(context->current_input_path);
} }

View File

@ -1,4 +1,4 @@
.TH "encode.h" 3 "Wed Aug 2 2017" "Brotli" \" -*- nroff -*- .TH "encode.h" 3 "Wed Sep 20 2017" "Brotli" \" -*- nroff -*-
.ad l .ad l
.nh .nh
.SH NAME .SH NAME
@ -210,7 +210,7 @@ Operations that can be performed by streaming encoder\&.
Process input\&. Encoder may postpone producing output, until it has processed enough input\&. Process input\&. Encoder may postpone producing output, until it has processed enough input\&.
.TP .TP
\fB\fIBROTLI_OPERATION_FLUSH \fP\fP \fB\fIBROTLI_OPERATION_FLUSH \fP\fP
Produce output for all processed input\&. Actual flush is performed when input stream is depleted and there is enough space in output stream\&. This means that client should repeat \fBBROTLI_OPERATION_FLUSH\fP operation until \fCavailable_in\fP becomes \fC0\fP, and \fBBrotliEncoderHasMoreOutput\fP returns \fBBROTLI_FALSE\fP\&. Produce output for all processed input\&. Actual flush is performed when input stream is depleted and there is enough space in output stream\&. This means that client should repeat \fBBROTLI_OPERATION_FLUSH\fP operation until \fCavailable_in\fP becomes \fC0\fP, and \fBBrotliEncoderHasMoreOutput\fP returns \fBBROTLI_FALSE\fP\&. If output is acquired via \fBBrotliEncoderTakeOutput\fP, then operation should be repeated after output buffer is drained\&.
.PP .PP
\fBWarning:\fP \fBWarning:\fP
.RS 4 .RS 4
@ -220,7 +220,7 @@ Until flush is complete, client \fBSHOULD\fP \fBNOT\fP swap, reduce or extend in
When flush is complete, output data will be sufficient for decoder to reproduce all the given input\&. When flush is complete, output data will be sufficient for decoder to reproduce all the given input\&.
.TP .TP
\fB\fIBROTLI_OPERATION_FINISH \fP\fP \fB\fIBROTLI_OPERATION_FINISH \fP\fP
Finalize the stream\&. Actual finalization is performed when input stream is depleted and there is enough space in output stream\&. This means that client should repeat \fBBROTLI_OPERATION_FLUSH\fP operation until \fCavailable_in\fP becomes \fC0\fP, and \fBBrotliEncoderHasMoreOutput\fP returns \fBBROTLI_FALSE\fP\&. Finalize the stream\&. Actual finalization is performed when input stream is depleted and there is enough space in output stream\&. This means that client should repeat \fBBROTLI_OPERATION_FINISH\fP operation until \fCavailable_in\fP becomes \fC0\fP, and \fBBrotliEncoderHasMoreOutput\fP returns \fBBROTLI_FALSE\fP\&. If output is acquired via \fBBrotliEncoderTakeOutput\fP, then operation should be repeated after output buffer is drained\&.
.PP .PP
\fBWarning:\fP \fBWarning:\fP
.RS 4 .RS 4