diff --git a/main/format_cap.c b/main/format_cap.c
index bf3bd1c4bf021f98e6a94947795f59f684cd678a..5d8a6e5852024900bbcfe9faf7f770b800f17ed1 100644
--- a/main/format_cap.c
+++ b/main/format_cap.c
@@ -737,7 +737,7 @@ const char *ast_format_cap_get_names(struct ast_format_cap *cap, struct ast_str
 
 	ast_str_set(buf, 0, "(");
 
-	if (!AST_VECTOR_SIZE(&cap->preference_order)) {
+	if (!cap || !AST_VECTOR_SIZE(&cap->preference_order)) {
 		ast_str_append(buf, 0, "nothing)");
 		return ast_str_buffer(*buf);
 	}