On Tue, Mar 21, 2017 at 08:32:59PM +0800, Steven Liu wrote:
[...]
> +static char *strreplace(const char *str, const char *from, const char *to)
> +{
> + /* Adjust each of the below values to suit your needs. */
> + /* Increment positions cache size initially by this number. */
> + size_t cache_sz_inc = 16;
> + /* Thereafter, each time capacity needs to be increased,
> + * multiply the increment by this factor. */
> + const size_t cache_sz_inc_factor = 3;
> + /* But never increment capacity by more than this number. */
> + const size_t cache_sz_inc_max = 1048576;
> +
> + char *pret, *ret = NULL;
> + const char *pstr2, *pstr = str;
> + size_t i, count = 0;
> + uintptr_t *pos_cache_tmp, *pos_cache = NULL;
> + size_t cache_sz = 0;
> + size_t cpylen, orglen, retlen, tolen, fromlen = strlen(from);
> +
> + /* Find all matches and cache their positions. */
> + while ((pstr2 = av_stristr(pstr, from))) {
> + count++;
> + /* Increase the cache size when necessary. */
> + if (cache_sz < count) {
> + cache_sz += cache_sz_inc;> + pos_cache_tmp = realloc(pos_cache, sizeof(*pos_cache) * > cache_sz); should be av_realloc() simiarly av_free() later where its freed [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB What does censorship reveal? It reveals fear. -- Julian Assange
signature.asc
Description: Digital signature
_______________________________________________ ffmpeg-devel mailing list [email protected] http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
