[FFmpeg-cvslog] avutil: use EINVAL instead of -1 for the return code of crypto related init functions

Ganesh Ajjanagadde git at videolan.org
Sun Oct 18 21:22:08 CEST 2015


ffmpeg | branch: master | Ganesh Ajjanagadde <gajjanagadde at gmail.com> | Thu Oct 15 19:36:22 2015 -0400| [07d4fe3a871f3ea2f3e475bc84c3e85102ec75ba] | committer: Ganesh Ajjanagadde

avutil: use EINVAL instead of -1 for the return code of crypto related init functions

These functions return an error typically when the key size is an
incorrect number. AVERROR(EINVAL) is more specific than -1.

Reviewed-by: Ronald S. Bultje <rsbultje at gmail.com>
Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=07d4fe3a871f3ea2f3e475bc84c3e85102ec75ba
---

 libavutil/aes.c      |    2 +-
 libavutil/camellia.c |    2 +-
 libavutil/cast5.c    |    2 +-
 libavutil/des.c      |    2 +-
 libavutil/rc4.c      |    2 +-
 libavutil/ripemd.c   |    2 +-
 libavutil/sha.c      |    2 +-
 libavutil/sha512.c   |    2 +-
 libavutil/twofish.c  |    2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavutil/aes.c b/libavutil/aes.c
index 8d4bbbb..b59e7de 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -223,7 +223,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
     }
 
     if (key_bits != 128 && key_bits != 192 && key_bits != 256)
-        return -1;
+        return AVERROR(EINVAL);
 
     a->rounds = rounds;
 
diff --git a/libavutil/camellia.c b/libavutil/camellia.c
index 483eed2..f21ca12 100644
--- a/libavutil/camellia.c
+++ b/libavutil/camellia.c
@@ -354,7 +354,7 @@ av_cold int av_camellia_init(AVCAMELLIA *cs, const uint8_t *key, int key_bits)
     uint64_t Kl[2], Kr[2], Ka[2], Kb[2];
     uint64_t D1, D2;
     if (key_bits != 128 && key_bits != 192 && key_bits != 256)
-        return -1;
+        return AVERROR(EINVAL);
     memset(Kb, 0, sizeof(Kb));
     memset(Kr, 0, sizeof(Kr));
     cs->key_bits = key_bits;
diff --git a/libavutil/cast5.c b/libavutil/cast5.c
index 98aa19d..a47697b 100644
--- a/libavutil/cast5.c
+++ b/libavutil/cast5.c
@@ -459,7 +459,7 @@ av_cold int av_cast5_init(AVCAST5* cs, const uint8_t *key, int key_bits)
     int i;
     uint32_t p[4], q[4];
     if (key_bits % 8 || key_bits < 40 || key_bits > 128)
-        return -1;
+        return AVERROR(EINVAL);
     memset(newKey, 0, sizeof(newKey));
     memcpy(newKey, key, key_bits >> 3);
 
diff --git a/libavutil/des.c b/libavutil/des.c
index c97158a..3ccbf89 100644
--- a/libavutil/des.c
+++ b/libavutil/des.c
@@ -292,7 +292,7 @@ AVDES *av_des_alloc(void)
 
 int av_des_init(AVDES *d, const uint8_t *key, int key_bits, av_unused int decrypt) {
     if (key_bits != 64 && key_bits != 192)
-        return -1;
+        return AVERROR(EINVAL);
     d->triple_des = key_bits > 64;
     gen_roundkeys(d->round_keys[0], AV_RB64(key));
     if (d->triple_des) {
diff --git a/libavutil/rc4.c b/libavutil/rc4.c
index 6bd702c..ffcb112 100644
--- a/libavutil/rc4.c
+++ b/libavutil/rc4.c
@@ -36,7 +36,7 @@ int av_rc4_init(AVRC4 *r, const uint8_t *key, int key_bits, int decrypt) {
     uint8_t *state = r->state;
     int keylen = key_bits >> 3;
     if (key_bits & 7)
-        return -1;
+        return AVERROR(EINVAL);
     for (i = 0; i < 256; i++)
         state[i] = i;
     y = 0;
diff --git a/libavutil/ripemd.c b/libavutil/ripemd.c
index 0084860..d247fb4 100644
--- a/libavutil/ripemd.c
+++ b/libavutil/ripemd.c
@@ -504,7 +504,7 @@ av_cold int av_ripemd_init(AVRIPEMD *ctx, int bits)
         ctx->transform = ripemd320_transform;
         break;
     default:
-        return -1;
+        return AVERROR(EINVAL);
     }
     ctx->count = 0;
     return 0;
diff --git a/libavutil/sha.c b/libavutil/sha.c
index 9963043..748bb9c 100644
--- a/libavutil/sha.c
+++ b/libavutil/sha.c
@@ -305,7 +305,7 @@ av_cold int av_sha_init(AVSHA *ctx, int bits)
         ctx->transform = sha256_transform;
         break;
     default:
-        return -1;
+        return AVERROR(EINVAL);
     }
     ctx->count = 0;
     return 0;
diff --git a/libavutil/sha512.c b/libavutil/sha512.c
index 66a864f..e2fc58a 100644
--- a/libavutil/sha512.c
+++ b/libavutil/sha512.c
@@ -233,7 +233,7 @@ av_cold int av_sha512_init(AVSHA512 *ctx, int bits)
         ctx->state[7] = UINT64_C(0x5BE0CD19137E2179);
         break;
     default:
-        return -1;
+        return AVERROR(EINVAL);
     }
     ctx->count = 0;
     return 0;
diff --git a/libavutil/twofish.c b/libavutil/twofish.c
index f735a1f..162069b 100644
--- a/libavutil/twofish.c
+++ b/libavutil/twofish.c
@@ -273,7 +273,7 @@ av_cold int av_twofish_init(AVTWOFISH *cs, const uint8_t *key, int key_bits)
     uint32_t Key[8], Me[4], Mo[4], A, B;
     const uint32_t rho = 0x01010101;
     if (key_bits < 0)
-        return -1;
+        return AVERROR(EINVAL);
     if (key_bits <= 128) {
         cs->ksize = 2;
     } else if (key_bits <= 192) {



More information about the ffmpeg-cvslog mailing list