[FFmpeg-devel] [PATCH] lavu/hash: make all functions work gracefully with NULL.
Nicolas George
george at nsup.org
Sun Apr 20 20:50:30 CEST 2014
More robust in case of av_hash_get_size() failing without
error checks.
Signed-off-by: Nicolas George <george at nsup.org>
---
libavutil/hash.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
Not sure if it is a good idea, I will let other people's advice decide.
diff --git a/libavutil/hash.c b/libavutil/hash.c
index a8cf80b..a177f48 100644
--- a/libavutil/hash.c
+++ b/libavutil/hash.c
@@ -88,12 +88,12 @@ const char *av_hash_names(int i)
const char *av_hash_get_name(const AVHashContext *ctx)
{
- return hashdesc[ctx->type].name;
+ return ctx ? hashdesc[ctx->type].name : "<NULL>";
}
int av_hash_get_size(const AVHashContext *ctx)
{
- return hashdesc[ctx->type].size;
+ return ctx ? hashdesc[ctx->type].size : 0;
}
int av_hash_alloc(AVHashContext **ctx, const char *name)
@@ -135,6 +135,8 @@ int av_hash_alloc(AVHashContext **ctx, const char *name)
void av_hash_init(AVHashContext *ctx)
{
+ if (!ctx)
+ return;
switch (ctx->type) {
case MD5: av_md5_init(ctx->ctx); break;
case MURMUR3: av_murmur3_init(ctx->ctx); break;
@@ -156,6 +158,8 @@ void av_hash_init(AVHashContext *ctx)
void av_hash_update(AVHashContext *ctx, const uint8_t *src, int len)
{
+ if (!ctx)
+ return;
switch (ctx->type) {
case MD5: av_md5_update(ctx->ctx, src, len); break;
case MURMUR3: av_murmur3_update(ctx->ctx, src, len); break;
@@ -177,6 +181,8 @@ void av_hash_update(AVHashContext *ctx, const uint8_t *src, int len)
void av_hash_final(AVHashContext *ctx, uint8_t *dst)
{
+ if (!ctx)
+ return;
switch (ctx->type) {
case MD5: av_md5_final(ctx->ctx, dst); break;
case MURMUR3: av_murmur3_final(ctx->ctx, dst); break;
--
1.7.10.4
More information about the ffmpeg-devel
mailing list