]> git.sesse.net Git - vlc/blobdiff - modules/demux/asademux.c
Replace argument = realloc( argument, size ); with realloc_or_free() in modules/...
[vlc] / modules / demux / asademux.c
index 81dbd88d6a2bf5c075f6d9681e7c78ea49584873..0739b58a76162c090d417988ca8794c373704441 100644 (file)
 #include <vlc_common.h>
 #include <vlc_input.h>
 #include <vlc_demux.h>
+#include <vlc_memory.h>
 
 #include <limits.h>
 #include <string.h>
+#include <assert.h>
 
 #include "asademux.h"
 
@@ -45,7 +47,7 @@
 #define MAXGROUP       24      /**< maximum number of regex match groups */
 
 #define xmalloc malloc
-#define xrealloc realloc
+#define xrealloc realloc_or_free
 #define xfree free
 #define xstrdup strdup
 
@@ -97,7 +99,7 @@ static int asai_child  (iargs);
 #undef iargs
 
 /** vm functions. KEEP IN SYNC WITH imports.h! */
-static asa_import_func importfuncs[] = {
+static const asa_import_func importfuncs[] = {
        asai_commit,
        asai_discard,
        asai_break,
@@ -247,6 +249,7 @@ static int asai_select (struct asa_import_state *state,
        if (state->selstr)
                xfree(state->selstr);
        state->selstr = xstrdup(state->matches[insn->v.select]);
+       assert(state->selstr);
        state->sellen = strlen(state->selstr);
        return 0;
 }
@@ -262,6 +265,7 @@ static ptrdiff_t asai_process_replace(struct asa_import_state *state,
 
        newstr_size = v[0] * 2;
        newstr = (char *)xmalloc(newstr_size);
+       assert(newstr);
        memcpy(newstr, state->selstr, v[0]);
        newpos = v[0];
 
@@ -286,6 +290,7 @@ static ptrdiff_t asai_process_replace(struct asa_import_state *state,
                if (need > avail) {
                        newstr_size += need - avail + 256;
                        newstr = (char *)xrealloc(newstr, newstr_size);
+                       assert(newstr);
                }
                memcpy(newstr + newpos, src, need);
                newpos += need;
@@ -293,6 +298,7 @@ static ptrdiff_t asai_process_replace(struct asa_import_state *state,
        firstold = newpos;
        newstr_size = newpos + state->sellen - v[1];
        newstr = (char *)xrealloc(newstr, newstr_size + 1);
+       assert(newstr);
        memcpy(newstr + newpos, state->selstr + v[1],
                state->sellen - v[1] + 1);
        state->selstr = newstr;
@@ -352,6 +358,7 @@ static void asai_set_matches(struct asa_import_state *state,
        if (state->selstr)
                xfree(state->selstr);
        state->selstr = xstrdup(state->matches[0]);
+       assert(state->selstr);
        state->sellen = strlen(state->selstr);
 }
 
@@ -383,6 +390,7 @@ static int asai_append (struct asa_import_state *state,
 {
        state->out = (char *)xrealloc(state->out,
                state->outlen + state->sellen + 1);
+       assert(state->out);
        memcpy(state->out + state->outlen, state->selstr, state->sellen);
        state->outlen += state->sellen;
        state->out[state->outlen] = '\0';