examples: Fix error condition processing

Don't attempt to attach failed metadata objects. This also avoids
clobbering the error flag if attaching the objects should succeed.

There may still be problems later, for example calling _delete()
on a possibly null metadata object pointer, but this it at least
and improvement in the compromise between error handling and
readability in C.

Signed-off-by: Ralph Giles <giles@thaumas.net>
This commit is contained in:
Andrey Astafyev 2019-11-19 05:38:00 -08:00 committed by Ralph Giles
parent eba0ff8d3e
commit a9557c13fa
No known key found for this signature in database
GPG Key ID: 9259A8F2D2D44C84
2 changed files with 10 additions and 6 deletions

View File

@ -109,11 +109,13 @@ int main(int argc, char *argv[])
) {
fprintf(stderr, "ERROR: out of memory or tag error\n");
ok = false;
}
} else {
metadata[1]->length = 1234; /* set the padding length */
metadata[1]->length = 1234; /* set the padding length */
ok = FLAC__stream_encoder_set_metadata(encoder, metadata, 2);
ok = FLAC__stream_encoder_set_metadata(encoder, metadata, 2);
}
}
/* initialize encoder */

View File

@ -117,11 +117,13 @@ int main(int argc, char *argv[])
) {
fprintf(stderr, "ERROR: out of memory or tag error\n");
ok = false;
}
} else {
metadata[1]->length = 1234; /* set the padding length */
metadata[1]->length = 1234; /* set the padding length */
ok = encoder.set_metadata(metadata, 2);
ok = encoder.set_metadata(metadata, 2);
}
}
/* initialize encoder */