On Thu, 15 Dec 2016, Diego Biurrun wrote:

Fixes a number of warnings of the type
libavutil/hmac.c:61:21: warning: assignment from incompatible pointer type
---

Now with the preliminaries requested by Anton.

libavutil/hmac.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/libavutil/hmac.c b/libavutil/hmac.c
index 378be62..2f4fa52 100644
--- a/libavutil/hmac.c
+++ b/libavutil/hmac.c
@@ -18,6 +18,8 @@
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

+#include <stddef.h>
+#include <stdint.h>
#include <string.h>

#include "attributes.h"
@@ -29,12 +31,16 @@
#define MAX_HASHLEN 32
#define MAX_BLOCKLEN 64

+typedef void (*hmac_final)(void *ctx, uint8_t *dst);
+typedef void (*hmac_update)(void *ctx, const uint8_t *src, size_t len);
+typedef void (*hmac_init)(void *ctx);
+
struct AVHMAC {
    void *hash;
    int blocklen, hashlen;
-    void (*final)(void*, uint8_t*);
-    void (*update)(void*, const uint8_t*, int len);
-    void (*init)(void*);
+    hmac_final  final;
+    hmac_update update;
+    hmac_init   init;
    uint8_t key[MAX_BLOCKLEN];
    int keylen;
};
@@ -58,33 +64,33 @@ AVHMAC *av_hmac_alloc(enum AVHMACType type)
    case AV_HMAC_MD5:
        c->blocklen = 64;
        c->hashlen  = 16;
-        c->init     = av_md5_init;
-        c->update   = av_md5_update;
-        c->final    = av_md5_final;
+        c->init     = (hmac_init) av_md5_init;
+        c->update   = (hmac_update) av_md5_update;
+        c->final    = (hmac_final) av_md5_final;
        c->hash     = av_md5_alloc();
        break;

Until we actually do the major bump and change the parameter type, this is absolutely wrong.

Until the next major bump, the actual implementation of the function av_md5_update takes an int parameter, but here we'd ignore that and pretend that it takes a size_t. If we're unlucky, a size_t is passed differently as parameter than an (un)signed int on some architecture, and we'd have a complete breakage.

Yes it does give warnings right now, but the ABI of the functions at least match, contrary to what it would do after this patch. Additionally, this patch would hide any future ABI incompatibility completely by silencing all that with the cast.

// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to