PR #20991 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20991
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20991.patch


>From fccdc3f5dea922fbc3100814dce721acef82bfbb Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 21 Nov 2025 13:58:22 +0100
Subject: [PATCH 1/3] av{codec,util}/tests: Remove pointless undefs

Before commit e96d90eed66a198566c409958432d282e1b03869 lavu/internal.h
contained redefined various discouraged/forbidden functions to induce
compilation failures upon use, like e.g.
 #define malloc please_use_av_malloc
In order to use these functions, some files had to undefine these
macros. This commit removes the remaining pointless undefs.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/jacosubdec.c          | 2 --
 libavcodec/tests/motion.c        | 2 --
 libavcodec/tests/snowenc.c       | 4 ----
 libavfilter/tests/formats.c      | 2 --
 libavformat/sbgdec.c             | 1 -
 libavutil/file_open.c            | 1 -
 libavutil/tests/bprint.c         | 2 --
 libavutil/tests/error.c          | 2 --
 libavutil/tests/file.c           | 2 --
 libavutil/tests/imgutils.c       | 1 -
 libavutil/tests/pca.c            | 1 -
 libavutil/tests/random_seed.c    | 1 -
 libswresample/tests/swresample.c | 2 --
 tools/fourcc2pixfmt.c            | 3 ---
 14 files changed, 26 deletions(-)

diff --git a/libavcodec/jacosubdec.c b/libavcodec/jacosubdec.c
index 08349a9ec8..fd90dcc4b6 100644
--- a/libavcodec/jacosubdec.c
+++ b/libavcodec/jacosubdec.c
@@ -32,8 +32,6 @@
 #include "libavutil/bprint.h"
 #include "libavutil/time_internal.h"
 
-#undef time
-
 static int insert_text(AVBPrint *dst, const char *in, const char *arg)
 {
     av_bprintf(dst, "%s", arg);
diff --git a/libavcodec/tests/motion.c b/libavcodec/tests/motion.c
index 719fba537d..ad2d65ec78 100644
--- a/libavcodec/tests/motion.c
+++ b/libavcodec/tests/motion.c
@@ -36,8 +36,6 @@
 #include "libavutil/mem.h"
 #include "libavutil/time.h"
 
-#undef printf
-
 #define WIDTH 64
 #define HEIGHT 64
 
diff --git a/libavcodec/tests/snowenc.c b/libavcodec/tests/snowenc.c
index 311374e5d4..35feedba06 100644
--- a/libavcodec/tests/snowenc.c
+++ b/libavcodec/tests/snowenc.c
@@ -20,10 +20,6 @@
 
 #include "libavcodec/snowenc.c"
 
-#undef malloc
-#undef free
-#undef printf
-
 #include "libavutil/lfg.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/mem.h"
diff --git a/libavfilter/tests/formats.c b/libavfilter/tests/formats.c
index 5cc3ca3371..3fdad7427e 100644
--- a/libavfilter/tests/formats.c
+++ b/libavfilter/tests/formats.c
@@ -22,8 +22,6 @@
 #include "libavfilter/audio.h"
 #include "libavfilter/formats.c"
 
-#undef printf
-
 const int64_t avfilter_all_channel_layouts[] = {
     AV_CH_FRONT_CENTER,
     AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY,
diff --git a/libavformat/sbgdec.c b/libavformat/sbgdec.c
index 4afb51b844..0e3d860d9f 100644
--- a/libavformat/sbgdec.c
+++ b/libavformat/sbgdec.c
@@ -905,7 +905,6 @@ static int expand_timestamps(void *log, struct sbg_script 
*s)
         av_log(log, AV_LOG_WARNING,
                "Scripts with mixed absolute and relative timestamps can give "
                "unexpected results (pause, seeking, time zone change).\n");
-#undef time
         time(&now0);
         tm = localtime_r(&now0, &tmpbuf);
         now = tm ? tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec :
diff --git a/libavutil/file_open.c b/libavutil/file_open.c
index 4692035d55..121a562fcb 100644
--- a/libavutil/file_open.c
+++ b/libavutil/file_open.c
@@ -120,7 +120,6 @@ int avpriv_tempfile(const char *prefix, char **filename, 
int log_offset, void *l
     if(!ptr)
         ptr= tempnam(".", prefix);
     *filename = av_strdup(ptr);
-#undef free
     free(ptr);
 #else
     return AVERROR(ENOSYS);
diff --git a/libavutil/tests/bprint.c b/libavutil/tests/bprint.c
index d7f9abf23e..9a87283302 100644
--- a/libavutil/tests/bprint.c
+++ b/libavutil/tests/bprint.c
@@ -21,8 +21,6 @@
 #include "libavutil/avassert.h"
 #include "libavutil/bprint.c"
 
-#undef printf
-
 static void bprint_pascal(AVBPrint *b, unsigned size)
 {
     unsigned i, j;
diff --git a/libavutil/tests/error.c b/libavutil/tests/error.c
index 16efc8ac45..b7b253b7b5 100644
--- a/libavutil/tests/error.c
+++ b/libavutil/tests/error.c
@@ -18,8 +18,6 @@
 
 #include "libavutil/error.c"
 
-#undef printf
-
 int main(void)
 {
     int i;
diff --git a/libavutil/tests/file.c b/libavutil/tests/file.c
index 3608bcccbe..0b151de9a1 100644
--- a/libavutil/tests/file.c
+++ b/libavutil/tests/file.c
@@ -18,8 +18,6 @@
 
 #include "libavutil/file.c"
 
-#undef printf
-
 int main(void)
 {
     uint8_t *buf;
diff --git a/libavutil/tests/imgutils.c b/libavutil/tests/imgutils.c
index 6a5097bc35..cd363145ad 100644
--- a/libavutil/tests/imgutils.c
+++ b/libavutil/tests/imgutils.c
@@ -20,7 +20,6 @@
 #include "libavutil/crc.h"
 #include "libavutil/mem.h"
 
-#undef printf
 static int check_image_fill(enum AVPixelFormat pix_fmt, int w, int h) {
     uint8_t *data[4];
     size_t sizes[4];
diff --git a/libavutil/tests/pca.c b/libavutil/tests/pca.c
index b2afbea3b5..a2a620799a 100644
--- a/libavutil/tests/pca.c
+++ b/libavutil/tests/pca.c
@@ -22,7 +22,6 @@
 #include "libavutil/pca.c"
 #include "libavutil/lfg.h"
 
-#undef printf
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/libavutil/tests/random_seed.c b/libavutil/tests/random_seed.c
index bf0c6c7986..614c958d42 100644
--- a/libavutil/tests/random_seed.c
+++ b/libavutil/tests/random_seed.c
@@ -21,7 +21,6 @@
 #define TEST 1
 #include "libavutil/random_seed.c"
 
-#undef printf
 #define N 256
 #define F 2
 #include <stdio.h>
diff --git a/libswresample/tests/swresample.c b/libswresample/tests/swresample.c
index b627aa4ad0..2a5f9d59c4 100644
--- a/libswresample/tests/swresample.c
+++ b/libswresample/tests/swresample.c
@@ -26,9 +26,7 @@
 
 #include "libswresample/swresample.h"
 
-#undef time
 #include <time.h>
-#undef fprintf
 
 #define SAMPLES 1000
 
diff --git a/tools/fourcc2pixfmt.c b/tools/fourcc2pixfmt.c
index 519cc1cad0..0b107db2ff 100644
--- a/tools/fourcc2pixfmt.c
+++ b/tools/fourcc2pixfmt.c
@@ -29,9 +29,6 @@
 #include "libavcodec/raw.h"
 #include "libavcodec/raw_pix_fmt_tags.h"
 
-#undef printf
-#undef fprintf
-
 #if !HAVE_GETOPT
 #include "compat/getopt.c"
 #endif
-- 
2.49.1


>From 6f094c0f34a24340e047315473d6e6f58e751a00 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 21 Nov 2025 14:18:05 +0100
Subject: [PATCH 2/3] avcodec/j2kenc: Remove dead, disabled debug code

Seems to have never worked, even when this was added in
83654c7b1b598add9041c7add6b77478eb91177f.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/j2kenc.c | 70 ---------------------------------------------
 1 file changed, 70 deletions(-)

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 7bec5bbe36..cba4d18adf 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -148,76 +148,6 @@ typedef struct {
 } Jpeg2000EncoderContext;
 
 
-/* debug */
-#if 0
-#undef ifprintf
-#undef printf
-
-static void nspaces(FILE *fd, int n)
-{
-    while(n--) putc(' ', fd);
-}
-
-static void printcomp(Jpeg2000Component *comp)
-{
-    int i;
-    for (i = 0; i < comp->y1 - comp->y0; i++)
-        ff_jpeg2000_printv(comp->i_data + i * (comp->x1 - comp->x0), comp->x1 
- comp->x0);
-}
-
-static void dump(Jpeg2000EncoderContext *s, FILE *fd)
-{
-    int tileno, compno, reslevelno, bandno, precno;
-    fprintf(fd, "XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
-                "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"
-                "tiles:\n",
-            s->width, s->height, s->tile_width, s->tile_height,
-            s->numXtiles, s->numYtiles, s->ncomponents);
-    for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
-        Jpeg2000Tile *tile = s->tile + tileno;
-        nspaces(fd, 2);
-        fprintf(fd, "tile %d:\n", tileno);
-        for(compno = 0; compno < s->ncomponents; compno++){
-            Jpeg2000Component *comp = tile->comp + compno;
-            nspaces(fd, 4);
-            fprintf(fd, "component %d:\n", compno);
-            nspaces(fd, 4);
-            fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
-                        comp->x0, comp->x1, comp->y0, comp->y1);
-            for(reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
-                Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
-                nspaces(fd, 6);
-                fprintf(fd, "reslevel %d:\n", reslevelno);
-                nspaces(fd, 6);
-                fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = 
%d\n",
-                        reslevel->x0, reslevel->x1, reslevel->y0,
-                        reslevel->y1, reslevel->nbands);
-                for(bandno = 0; bandno < reslevel->nbands; bandno++){
-                    Jpeg2000Band *band = reslevel->band + bandno;
-                    nspaces(fd, 8);
-                    fprintf(fd, "band %d:\n", bandno);
-                    nspaces(fd, 8);
-                    fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d,"
-                                "codeblock_width = %d, codeblock_height = %d 
cblknx = %d cblkny = %d\n",
-                                band->x0, band->x1,
-                                band->y0, band->y1,
-                                band->codeblock_width, band->codeblock_height,
-                                band->cblknx, band->cblkny);
-                    for (precno = 0; precno < reslevel->num_precincts_x * 
reslevel->num_precincts_y; precno++){
-                        Jpeg2000Prec *prec = band->prec + precno;
-                        nspaces(fd, 10);
-                        fprintf(fd, "prec %d:\n", precno);
-                        nspaces(fd, 10);
-                        fprintf(fd, "xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
-                                     prec->xi0, prec->xi1, prec->yi0, 
prec->yi1);
-                    }
-                }
-            }
-        }
-    }
-}
-#endif
-
 /* bitstream routines */
 
 /** put n times val bit */
-- 
2.49.1


>From 3d30d0092e1e4bd9fe69bdd663b9e2582bfbe510 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 21 Nov 2025 14:53:21 +0100
Subject: [PATCH 3/3] avutil/error: Avoid relocations and unused information

Use a string table instead to avoid relocations and don't add
the tag string to libavutil/error.c: It is only used
during the test program, so move it there.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavutil/error.c       | 197 ++++++++++++++++++++++------------------
 libavutil/tests/error.c |  13 ++-
 2 files changed, 119 insertions(+), 91 deletions(-)

diff --git a/libavutil/error.c b/libavutil/error.c
index 90bab7b9d3..23a2a0a53a 100644
--- a/libavutil/error.c
+++ b/libavutil/error.c
@@ -25,109 +25,128 @@
 #include "error.h"
 #include "macros.h"
 
-struct error_entry {
-    int num;
-    const char *tag;
-    const char *str;
+#define AVERROR_INPUT_AND_OUTPUT_CHANGED (AVERROR_INPUT_CHANGED | 
AVERROR_OUTPUT_CHANGED)
+
+#define AVERROR_LIST(E, E2)                                                    
                 \
+    E(BSF_NOT_FOUND,            "Bitstream filter not found")                  
                 \
+    E(BUG,                      "Internal bug, should not have happened")      
                 \
+    E2(BUG2, BUG,               "Internal bug, should not have happened")      
                 \
+    E(BUFFER_TOO_SMALL,         "Buffer too small")                            
                 \
+    E(DECODER_NOT_FOUND,        "Decoder not found")                           
                 \
+    E(DEMUXER_NOT_FOUND,        "Demuxer not found")                           
                 \
+    E(ENCODER_NOT_FOUND,        "Encoder not found")                           
                 \
+    E(EOF,                      "End of file")                                 
                 \
+    E(EXIT,                     "Immediate exit requested")                    
                 \
+    E(EXTERNAL,                 "Generic error in an external library")        
                 \
+    E(FILTER_NOT_FOUND,         "Filter not found")                            
                 \
+    E(INPUT_CHANGED,            "Input changed")                               
                 \
+    E(INVALIDDATA,              "Invalid data found when processing input")    
                 \
+    E(MUXER_NOT_FOUND,          "Muxer not found")                             
                 \
+    E(OPTION_NOT_FOUND,         "Option not found")                            
                 \
+    E(OUTPUT_CHANGED,           "Output changed")                              
                 \
+    E(PATCHWELCOME,             "Not yet implemented in FFmpeg, patches 
welcome")               \
+    E(PROTOCOL_NOT_FOUND,       "Protocol not found")                          
                 \
+    E(STREAM_NOT_FOUND,         "Stream not found")                            
                 \
+    E(UNKNOWN,                  "Unknown error occurred")                      
                 \
+    E(EXPERIMENTAL,             "Experimental feature")                        
                 \
+    E(INPUT_AND_OUTPUT_CHANGED, "Input and output changed")                    
                 \
+    E(HTTP_BAD_REQUEST,         "Server returned 400 Bad Request")             
                 \
+    E(HTTP_UNAUTHORIZED,        "Server returned 401 Unauthorized 
(authorization failed)")      \
+    E(HTTP_FORBIDDEN,           "Server returned 403 Forbidden (access 
denied)")                \
+    E(HTTP_NOT_FOUND,           "Server returned 404 Not Found")               
                 \
+    E(HTTP_TOO_MANY_REQUESTS,   "Server returned 429 Too Many Requests")       
                 \
+    E(HTTP_OTHER_4XX,           "Server returned 4XX Client Error, but not one 
of 40{0,1,3,4}") \
+    E(HTTP_SERVER_ERROR,        "Server returned 5XX Server Error reply")      
                 \
+
+#define STRERROR_LIST(E)                                                     \
+    E(E2BIG,             "Argument list too long")                           \
+    E(EACCES,            "Permission denied")                                \
+    E(EAGAIN,            "Resource temporarily unavailable")                 \
+    E(EBADF,             "Bad file descriptor")                              \
+    E(EBUSY,             "Device or resource busy")                          \
+    E(ECHILD,            "No child processes")                               \
+    E(EDEADLK,           "Resource deadlock avoided")                        \
+    E(EDOM,              "Numerical argument out of domain")                 \
+    E(EEXIST,            "File exists")                                      \
+    E(EFAULT,            "Bad address")                                      \
+    E(EFBIG,             "File too large")                                   \
+    E(EILSEQ,            "Illegal byte sequence")                            \
+    E(EINTR,             "Interrupted system call")                          \
+    E(EINVAL,            "Invalid argument")                                 \
+    E(EIO,               "I/O error")                                        \
+    E(EISDIR,            "Is a directory")                                   \
+    E(EMFILE,            "Too many open files")                              \
+    E(EMLINK,            "Too many links")                                   \
+    E(ENAMETOOLONG,      "File name too long")                               \
+    E(ENFILE,            "Too many open files in system")                    \
+    E(ENODEV,            "No such device")                                   \
+    E(ENOENT,            "No such file or directory")                        \
+    E(ENOEXEC,           "Exec format error")                                \
+    E(ENOLCK,            "No locks available")                               \
+    E(ENOMEM,            "Cannot allocate memory")                           \
+    E(ENOSPC,            "No space left on device")                          \
+    E(ENOSYS,            "Function not implemented")                         \
+    E(ENOTDIR,           "Not a directory")                                  \
+    E(ENOTEMPTY,         "Directory not empty")                              \
+    E(ENOTTY,            "Inappropriate I/O control operation")              \
+    E(ENXIO,             "No such device or address")                        \
+    E(EPERM,             "Operation not permitted")                          \
+    E(EPIPE,             "Broken pipe")                                      \
+    E(ERANGE,            "Result too large")                                 \
+    E(EROFS,             "Read-only file system")                            \
+    E(ESPIPE,            "Illegal seek")                                     \
+    E(ESRCH,             "No such process")                                  \
+    E(EXDEV,             "Cross-device link")                                \
+
+enum {
+#define OFFSET(CODE, DESC)     \
+    ERROR_ ## CODE ## _OFFSET, \
+    ERROR_ ## CODE ## _END_OFFSET = ERROR_ ## CODE ## _OFFSET + sizeof(DESC) - 
1,
+#define NOTHING(CODE, CODE2, DESC)
+    AVERROR_LIST(OFFSET, NOTHING)
+#if !HAVE_STRERROR_R
+    STRERROR_LIST(OFFSET)
+#endif
+    ERROR_LIST_SIZE
 };
 
-#define ERROR_TAG(tag) AVERROR_##tag, #tag
-#define EERROR_TAG(tag) AVERROR(tag), #tag
-#define AVERROR_INPUT_AND_OUTPUT_CHANGED (AVERROR_INPUT_CHANGED | 
AVERROR_OUTPUT_CHANGED)
-static const struct error_entry error_entries[] = {
-    { ERROR_TAG(BSF_NOT_FOUND),      "Bitstream filter not found"              
       },
-    { ERROR_TAG(BUG),                "Internal bug, should not have happened"  
       },
-    { ERROR_TAG(BUG2),               "Internal bug, should not have happened"  
       },
-    { ERROR_TAG(BUFFER_TOO_SMALL),   "Buffer too small"                        
       },
-    { ERROR_TAG(DECODER_NOT_FOUND),  "Decoder not found"                       
       },
-    { ERROR_TAG(DEMUXER_NOT_FOUND),  "Demuxer not found"                       
       },
-    { ERROR_TAG(ENCODER_NOT_FOUND),  "Encoder not found"                       
       },
-    { ERROR_TAG(EOF),                "End of file"                             
       },
-    { ERROR_TAG(EXIT),               "Immediate exit requested"                
       },
-    { ERROR_TAG(EXTERNAL),           "Generic error in an external library"    
       },
-    { ERROR_TAG(FILTER_NOT_FOUND),   "Filter not found"                        
       },
-    { ERROR_TAG(INPUT_CHANGED),      "Input changed"                           
       },
-    { ERROR_TAG(INVALIDDATA),        "Invalid data found when processing 
input"       },
-    { ERROR_TAG(MUXER_NOT_FOUND),    "Muxer not found"                         
       },
-    { ERROR_TAG(OPTION_NOT_FOUND),   "Option not found"                        
       },
-    { ERROR_TAG(OUTPUT_CHANGED),     "Output changed"                          
       },
-    { ERROR_TAG(PATCHWELCOME),       "Not yet implemented in FFmpeg, patches 
welcome" },
-    { ERROR_TAG(PROTOCOL_NOT_FOUND), "Protocol not found"                      
       },
-    { ERROR_TAG(STREAM_NOT_FOUND),   "Stream not found"                        
       },
-    { ERROR_TAG(UNKNOWN),            "Unknown error occurred"                  
       },
-    { ERROR_TAG(EXPERIMENTAL),       "Experimental feature"                    
       },
-    { ERROR_TAG(INPUT_AND_OUTPUT_CHANGED), "Input and output changed"          
       },
-    { ERROR_TAG(HTTP_BAD_REQUEST),   "Server returned 400 Bad Request"         
},
-    { ERROR_TAG(HTTP_UNAUTHORIZED),  "Server returned 401 Unauthorized 
(authorization failed)" },
-    { ERROR_TAG(HTTP_FORBIDDEN),     "Server returned 403 Forbidden (access 
denied)" },
-    { ERROR_TAG(HTTP_NOT_FOUND),     "Server returned 404 Not Found"           
},
-    { ERROR_TAG(HTTP_TOO_MANY_REQUESTS), "Server returned 429 Too Many 
Requests"      },
-    { ERROR_TAG(HTTP_OTHER_4XX),     "Server returned 4XX Client Error, but 
not one of 40{0,1,3,4}" },
-    { ERROR_TAG(HTTP_SERVER_ERROR),  "Server returned 5XX Server Error reply" 
},
+#define STRING(CODE, DESC) DESC "\0"
+static const char error_stringtable[ERROR_LIST_SIZE] =
+    AVERROR_LIST(STRING, NOTHING)
 #if !HAVE_STRERROR_R
-    { EERROR_TAG(E2BIG),             "Argument list too long" },
-    { EERROR_TAG(EACCES),            "Permission denied" },
-    { EERROR_TAG(EAGAIN),            "Resource temporarily unavailable" },
-    { EERROR_TAG(EBADF),             "Bad file descriptor" },
-    { EERROR_TAG(EBUSY),             "Device or resource busy" },
-    { EERROR_TAG(ECHILD),            "No child processes" },
-    { EERROR_TAG(EDEADLK),           "Resource deadlock avoided" },
-    { EERROR_TAG(EDOM),              "Numerical argument out of domain" },
-    { EERROR_TAG(EEXIST),            "File exists" },
-    { EERROR_TAG(EFAULT),            "Bad address" },
-    { EERROR_TAG(EFBIG),             "File too large" },
-    { EERROR_TAG(EILSEQ),            "Illegal byte sequence" },
-    { EERROR_TAG(EINTR),             "Interrupted system call" },
-    { EERROR_TAG(EINVAL),            "Invalid argument" },
-    { EERROR_TAG(EIO),               "I/O error" },
-    { EERROR_TAG(EISDIR),            "Is a directory" },
-    { EERROR_TAG(EMFILE),            "Too many open files" },
-    { EERROR_TAG(EMLINK),            "Too many links" },
-    { EERROR_TAG(ENAMETOOLONG),      "File name too long" },
-    { EERROR_TAG(ENFILE),            "Too many open files in system" },
-    { EERROR_TAG(ENODEV),            "No such device" },
-    { EERROR_TAG(ENOENT),            "No such file or directory" },
-    { EERROR_TAG(ENOEXEC),           "Exec format error" },
-    { EERROR_TAG(ENOLCK),            "No locks available" },
-    { EERROR_TAG(ENOMEM),            "Cannot allocate memory" },
-    { EERROR_TAG(ENOSPC),            "No space left on device" },
-    { EERROR_TAG(ENOSYS),            "Function not implemented" },
-    { EERROR_TAG(ENOTDIR),           "Not a directory" },
-    { EERROR_TAG(ENOTEMPTY),         "Directory not empty" },
-    { EERROR_TAG(ENOTTY),            "Inappropriate I/O control operation" },
-    { EERROR_TAG(ENXIO),             "No such device or address" },
-    { EERROR_TAG(EPERM),             "Operation not permitted" },
-    { EERROR_TAG(EPIPE),             "Broken pipe" },
-    { EERROR_TAG(ERANGE),            "Result too large" },
-    { EERROR_TAG(EROFS),             "Read-only file system" },
-    { EERROR_TAG(ESPIPE),            "Illegal seek" },
-    { EERROR_TAG(ESRCH),             "No such process" },
-    { EERROR_TAG(EXDEV),             "Cross-device link" },
+    STRERROR_LIST(STRING)
+#endif
+;
+
+static const struct ErrorEntry {
+    int num;
+    unsigned offset;
+} error_entries[] = {
+#define ENTRY(CODE, DESC) { .num = AVERROR_ ## CODE, .offset = ERROR_ ## CODE 
## _OFFSET },
+#define ENTRY2(CODE, CODE2, DESC) { .num = AVERROR_ ## CODE, .offset = ERROR_ 
## CODE2 ## _OFFSET },
+    AVERROR_LIST(ENTRY, ENTRY2)
+#if !HAVE_STRERROR_R
+#undef ENTRY
+#define ENTRY(CODE, DESC) { .num = AVERROR(CODE), .offset = ERROR_ ## CODE ## 
_OFFSET },
+    STRERROR_LIST(ENTRY)
 #endif
 };
 
 int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
 {
-    int ret = 0, i;
-    const struct error_entry *entry = NULL;
-
-    for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
+    for (size_t i = 0; i < FF_ARRAY_ELEMS(error_entries); ++i) {
         if (errnum == error_entries[i].num) {
-            entry = &error_entries[i];
-            break;
+            av_strlcpy(errbuf, error_stringtable + error_entries[i].offset, 
errbuf_size);
+            return 0;
         }
     }
-    if (entry) {
-        av_strlcpy(errbuf, entry->str, errbuf_size);
-    } else {
 #if HAVE_STRERROR_R
-        ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size));
+    int ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size));
 #else
-        ret = -1;
+    int ret = -1;
 #endif
-        if (ret < 0)
-            snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);
-    }
+    if (ret < 0)
+        snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);
 
     return ret;
 }
diff --git a/libavutil/tests/error.c b/libavutil/tests/error.c
index b7b253b7b5..774c71fcb9 100644
--- a/libavutil/tests/error.c
+++ b/libavutil/tests/error.c
@@ -18,13 +18,22 @@
 
 #include "libavutil/error.c"
 
+static const char *const tag_list[] = {
+#define ERROR_TAG(CODE, DESC) #CODE,
+#define ERROR_TAG2(CODE, CODE2, DESC) #CODE,
+    AVERROR_LIST(ERROR_TAG, ERROR_TAG2)
+#if !HAVE_STRERROR_R
+    STRERROR_LIST(ERROR_TAG)
+#endif
+};
+
 int main(void)
 {
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
-        const struct error_entry *entry = &error_entries[i];
-        printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), 
entry->tag);
+        const struct ErrorEntry *entry = &error_entries[i];
+        printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), 
tag_list[i]);
     }
 
     for (i = 0; i < 256; i++) {
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to