Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avutil/error: Provide better feedback about unknown error codes
@ 2024-07-15 15:13 Andrew Sayers
  2024-07-15 15:45 ` Marton Balint
  0 siblings, 1 reply; 15+ messages in thread
From: Andrew Sayers @ 2024-07-15 15:13 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andrew Sayers

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".

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-07-18 15:43 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-15 15:13 [FFmpeg-devel] [PATCH] avutil/error: Provide better feedback about unknown error codes Andrew Sayers
2024-07-15 15:45 ` Marton Balint
2024-07-15 16:13   ` Andrew Sayers
2024-07-15 23:01     ` Marton Balint
2024-07-16 11:13       ` [FFmpeg-devel] [RFC PATCH v2 0/1] " Andrew Sayers
2024-07-16 11:13         ` [FFmpeg-devel] [RFC PATCH v2] " Andrew Sayers
2024-07-17 21:06           ` Michael Niedermayer
2024-07-18  9:26         ` [FFmpeg-devel] [RFC PATCH v2 0/1] " Marton Balint
2024-07-18 10:46           ` [FFmpeg-devel] [PATCH v3 0/3] Protect against undocumented " Andrew Sayers
2024-07-18 10:46             ` [FFmpeg-devel] [PATCH v3 1/3] avutil/utils: Allow "!" in FourCCs Andrew Sayers
2024-07-18 15:42               ` Paul B Mahol
2024-07-18 10:46             ` [FFmpeg-devel] [PATCH v3 2/3] avutil/error: Provide better feedback about unknown error codes Andrew Sayers
2024-07-18 10:46             ` [FFmpeg-devel] [PATCH v3 3/3] tests/fate/source-check: Check for AVERROR codes without error strings Andrew Sayers
2024-07-18 11:16           ` [FFmpeg-devel] [RFC PATCH v2 0/1] avutil/error: Provide better feedback about unknown error codes Zhao Zhili
2024-07-17  6:25       ` [FFmpeg-devel] [PATCH] " Anton Khirnov

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git