diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 31a5d373472627545a0ec70fefed2b91730e7cac..cc2a3a2a8db663a2426ec392a8d2ac67811328c3 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1009,6 +1009,8 @@ AVCodec *avcodec_find_encoder(enum CodecID id)
 AVCodec *avcodec_find_encoder_by_name(const char *name)
 {
     AVCodec *p;
+    if (!name)
+        return NULL;
     p = first_avcodec;
     while (p) {
         if (p->encode != NULL && strcmp(name,p->name) == 0)
@@ -1033,6 +1035,8 @@ AVCodec *avcodec_find_decoder(enum CodecID id)
 AVCodec *avcodec_find_decoder_by_name(const char *name)
 {
     AVCodec *p;
+    if (!name)
+        return NULL;
     p = first_avcodec;
     while (p) {
         if (p->decode != NULL && strcmp(name,p->name) == 0)