From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 831C24BBEB for ; Mon, 15 Jul 2024 15:13:37 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8867F68D967; Mon, 15 Jul 2024 18:13:34 +0300 (EEST) Received: from alt2.a-painless.mh.aa.net.uk (alt2.a-painless.mh.aa.net.uk [81.187.30.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 30D2768D8CB for ; Mon, 15 Jul 2024 18:13:28 +0300 (EEST) Received: from 0.b.4.b.7.4.0.8.c.4.a.5.d.8.b.2.0.5.8.0.9.1.8.0.0.b.8.0.1.0.0.2.ip6.arpa ([2001:8b0:819:850:2b8d:5a4c:8047:b4b0] helo=andrews-2024-laptop.lan) by painless-a.thn.aa.net.uk with esmtp (Exim 4.96) (envelope-from ) id 1sTNOJ-00A34w-28; Mon, 15 Jul 2024 16:13:27 +0100 From: Andrew Sayers To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Jul 2024 16:13:19 +0100 Message-ID: <20240715151319.2322241-1-ffmpeg-devel@pileofstuff.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avutil/error: Provide better feedback about unknown error codes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andrew Sayers Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: AVERROR messages should always be less than zero, and are usually based on three or four ASCII characters. For error codes that aren't explicitly handled by error.c (e.g. FFERROR_REDO), print the ASCII code so the user has a little more information. If a non-negative number somehow gets passed to this function, print a message saying this shouldn't happen. --- libavutil/error.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libavutil/error.c b/libavutil/error.c index 90bab7b9d3..c40b54b1f9 100644 --- a/libavutil/error.c +++ b/libavutil/error.c @@ -119,6 +119,38 @@ int av_strerror(int errnum, char *errbuf, size_t errbuf_size) } if (entry) { av_strlcpy(errbuf, entry->str, errbuf_size); + } else if ( + -errnum <= 0xFFFFFFFF + && ((-errnum >> 0) & 0xFF) >= 0x20 && ((-errnum >> 0) & 0xFF) <= 0x7F + && ((-errnum >> 8) & 0xFF) >= 0x20 && ((-errnum >> 8) & 0xFF) <= 0x7F + && ((-errnum >> 16) & 0xFF) >= 0x20 && ((-errnum >> 16) & 0xFF) <= 0x7F + && ( + (((-errnum >> 24) & 0xFF) >= 0x20 && ((-errnum >> 24) & 0xFF) <= 0x7F) + || !((-errnum >> 24) & 0xFF) + ) + ) { + if ((-errnum >> 24) & 0xFF) { + snprintf( + errbuf, + errbuf_size, + "Unrecognised error code \"%c%c%c%c\" occurred", + (-errnum >> 0) & 0xFF, + (-errnum >> 8) & 0xFF, + (-errnum >> 16) & 0xFF, + (-errnum >> 24) & 0xFF + ); + } else { + snprintf( + errbuf, + errbuf_size, + "Unrecognised error code \"%c%c%c\" occurred", + (-errnum >> 0) & 0xFF, + (-errnum >> 8) & 0xFF, + (-errnum >> 16) & 0xFF + ); + } + } else if (errnum >= 0) { + snprintf(errbuf, errbuf_size, "Impossible: non-negative error number %d occurred", errnum); } else { #if HAVE_STRERROR_R ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size)); -- 2.45.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".