diff mbox series

[FFmpeg-devel,02/10] lavu/opt: use ff_hexpair2int().

Message ID 20210727144813.452917-3-george@nsup.org
State New
Headers show
Series [FFmpeg-devel,01/10] lavu/internal: add hex to int functions.
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Nicolas George July 27, 2021, 2:48 p.m. UTC
Signed-off-by: Nicolas George <george@nsup.org>
---
 libavutil/opt.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 41284d4ecd..c7844d6241 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -167,16 +167,6 @@  static int write_number(void *obj, const AVOption *o, void *dst, double num, int
     return 0;
 }
 
-static int hexchar2int(char c) {
-    if (c >= '0' && c <= '9')
-        return c - '0';
-    if (c >= 'a' && c <= 'f')
-        return c - 'a' + 10;
-    if (c >= 'A' && c <= 'F')
-        return c - 'A' + 10;
-    return -1;
-}
-
 static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
 {
     int *lendst = (int *)(dst + 1);
@@ -197,13 +187,13 @@  static int set_string_binary(void *obj, const AVOption *o, const char *val, uint
     if (!ptr)
         return AVERROR(ENOMEM);
     while (*val) {
-        int a = hexchar2int(*val++);
-        int b = hexchar2int(*val++);
-        if (a < 0 || b < 0) {
+        int a = ff_hexpair2int(val);
+        if (a < 0) {
             av_free(bin);
             return AVERROR(EINVAL);
         }
-        *ptr++ = (a << 4) | b;
+        *ptr++ = a;
+        val += 2;
     }
     *dst    = bin;
     *lendst = len;