1
0
Fork 0
Commit Graph

58 Commits

Author SHA1 Message Date
Andreas Rheinhardt dfffe03755 avutil/dict: Deduplicate freeing dictionary
Reviewed-by: epirat07@gmail.com
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-08 01:01:49 +01:00
Andreas Rheinhardt e3b355c0be avutil/mem: Don't include avutil.h
It is not necessary at all. So remove it.
This also breaks an inclusion cycle mem.h->avutil.h->common.h->mem.h.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-07 00:42:10 +02:00
Marvin Scholz 3101b8afb3 avutil/dict: Use av_dict_iterate in av_dict_get_string
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-11-06 08:26:50 +01:00
Marvin Scholz 3c2050b749 avutil/dict: Use av_dict_iterate in av_dict_copy
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-11-06 08:26:50 +01:00
Marvin Scholz 5f7c5a0bd7 avutil/dict: Use av_dict_iterate in av_dict_get
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-11-06 08:26:50 +01:00
Marvin Scholz 9dad237928 avutil/dict: Add av_dict_iterate
This is a more explicit iteration API rather than using the "magic"
av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX) which is not really
trivial to grasp what it does when casually reading through code.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-11-06 08:26:48 +01:00
Andreas Rheinhardt 187cd27832 avutil/dict: Error out in case of key == NULL
Up until now, using NULL as key in av_dict_get() on a non-empty
AVDictionary would crash; using NULL as key in av_dict_set()
would also crash for a non-empty AVDictionary unless AV_DICT_MULTIKEY
was set; in case the dictionary was initially empty or AV_DICT_MULTIKEY
was set, it was even possible for av_dict_set() to succeed when
adding a NULL key, namely when one uses a value != NULL and
the AV_DICT_DONT_STRDUP_VAL flag. Using av_dict_get() on such
an AVDictionary will usually lead to crashes, though.

Fix this by actually checking for key in both functions; error out
if they are NULL.

While just at it, also stop relying on av_strdup(NULL) to return NULL
in av_dict_set().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-19 23:39:58 +02:00
Andreas Rheinhardt e867a29ec1 avutil/dict: Improve appending values
When appending two values (due to AV_DICT_APPEND), the earlier code
would first zero-allocate a buffer of the required size and then
copy both parts into it via av_strlcat(). This is problematic,
as it leads to quadratic performance in case of frequent enlargements.
Fix this by using av_realloc() (which is hopefully designed to handle
such cases in a better way than simply throwing the buffer we already
have away) and by copying the string via memcpy() (after all, we already
calculated the strlen of both strings).

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-14 19:01:02 +02:00
Andreas Rheinhardt c15dd31d2a avutil/dict: Fix memleak when using AV_DICT_APPEND
If a key already exists in an AVDictionary and the AV_DICT_APPEND flag
is set, the old entry is at first discarded from the dictionary, but
a pointer to the value is kept. Lateron enough memory to store the
appended string is allocated; should this allocation fail, the old string
is not freed and hence leaks. This commit changes this by moving
creating the combined value to an earlier point in the function,
which also ensures that the AVDictionary is unchanged in case of errors.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-14 19:00:44 +02:00
Andreas Rheinhardt f976ed7fcf avutil/dict: Avoid check whose result is known in advance
We know that an AVDictionary is not empty if we have just added
an entry to it, so only check for it being empty on the branch
that does not do so.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-14 15:03:59 +02:00
Andreas Rheinhardt 04b7217872 avutil/dict: Move avpriv_dict_set_timestamp() to a header of its own
It is used almost nowhere, so it needn't be auto-included
almost everywhere.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-03 15:41:44 +02:00
Limin Wang 4bc5eb27a7 avutil/dict: av_realloc -> av_realloc_array()
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-06-06 10:32:07 +08:00
Marton Balint b72a7b96f8 avformat: factorize iso 8601 timestamp writer to a dictionary avutil function
Signed-off-by: Marton Balint <cus@passwd.hu>
2016-08-17 23:45:41 +02:00
Derek Buitenhuis 96d616052b Merge commit 'd12b5b2f135aade4099f4b26b0fe678656158c13'
* commit 'd12b5b2f135aade4099f4b26b0fe678656158c13':
  build: Split test programs off into separate files

Some conversions done by: James Almer <jamrial@gmail.com>
Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-05-11 19:13:03 +01:00
Thilo Borgmann 4ebf0b109c lavu/dict: Add new flag to allow multiple equal keys. 2016-03-25 17:08:11 +01:00
Marton Balint a740263d7e avutil/dict: do not realloc entries when deleting a non-existing item
Deleting a non-existing item should not invalidate existing entries returned
with av_dict_get.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Marton Balint <cus@passwd.hu>
2016-03-15 00:55:16 +01:00
Hendrik Leppkes b994788353 Merge commit '11c5f438ff83da5040e85bfa6299f56b321d32ef'
* commit '11c5f438ff83da5040e85bfa6299f56b321d32ef':
  dict: Change return type of av_dict_copy()

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-10-14 14:01:11 +02:00
Vittorio Giovara 11c5f438ff dict: Change return type of av_dict_copy()
av_dict_set() could return an error, so forward it appropriately.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-10-12 13:35:01 +02:00
Michael Niedermayer 4c128ea162 avutil/dict: Use size_t for appending strings
the string length is not constrained to INT_MAX

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-10 16:09:07 +02:00
Lukasz Marek 96f896750d lavu/dict: add more tests
Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
2015-04-02 23:15:57 +02:00
Lukasz Marek a8c5b4551e lavu/dict: fix set function when reuse existing key pointer
Fixes following scenario:

av_dict_set(&d, "key", "old", 0);
AVDictionaryEentry *e = av_dict_get(d, "key", NULL, 0);
av_dict_set(&d, e->key, "new", 0);

Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
2015-04-02 23:15:57 +02:00
Lukasz Marek 08d0dbf2ae lavu/dict: don't accept AV_DICT_DONT_STRDUP_VAL for av_dict_set_int
Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-02 00:48:19 +02:00
Luca Barbato 1279221cc4 lavu: Check av_dict_set allocations
Bug-Id: CID 1257772
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-01-29 14:59:57 +00:00
Michael Niedermayer 336bb3f706 avutil/dict: Use av_freep() to avoid leaving stale pointers in memory
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-12-27 15:48:32 +01:00
wm4 a963fdb0ea lavu/dict: check for malloc failures
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-12-12 23:40:50 +01:00
Michael Niedermayer 5182a2a235 avutil: remove FF_CONST_AVUTIL53, its no longer needed
version is 54 already

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-11-24 02:22:19 +01:00
Lukasz Marek ab922f9ef1 lavu/dict: add av_dict_get_string
Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
2014-11-21 01:25:54 +01:00
Michael Niedermayer 8407cbbfc9 Fix "passing argument 1 of av_free discards const qualifier from pointer target type"
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-13 22:32:20 +02:00
Reimar Döffinger 8fc9bd0d32 dict.c: Free non-strduped av_dict_set arguments on error.
Unfortunately this was not explicitly documented and thus
might be risky.
But all uses I could find in FFmpeg and one in VLC had a memleak
in these cases, and I could not find any that relied on the previous
behaviour.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2014-08-23 15:28:48 +02:00
Reimar Döffinger bddc592001 dict.c: empty dictionaries should be a NULL pointer.
Ensure this is even the case if they are empty because
we failed adding the first entry.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2014-08-16 14:47:06 +02:00
Reimar Döffinger c2829dc925 dict.c: Add av_dict_set_int helper function.
This allows getting rid of the many, slightly differing, implementations
of basically the same thing.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2014-08-16 14:30:18 +02:00
Reimar Döffinger f0de01856f dict.c: minor simplification.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2014-07-31 20:10:29 +02:00
Michael Niedermayer 375fa06125 Merge commit '1619274fb393f55a365cc10f88faa173c9a8e772'
* commit '1619274fb393f55a365cc10f88faa173c9a8e772':
  av_dict_set: fix potential memory leak with AV_DICT_DONT_OVERWRITE

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2014-06-09 17:25:09 +02:00
Janne Grunau 1619274fb3 av_dict_set: fix potential memory leak with AV_DICT_DONT_OVERWRITE
av_dict_set leaks it key/value arguments if AV_DICT_DONT_OVERWRITE is
combined with AV_DICT_DONT_STRDUP_{KEY,VAL} and the key exists.
2014-06-09 12:33:19 +02:00
Diego Biurrun d816e125fe dict: const correctness for av_dict_get() and av_dict_copy() 2014-06-05 09:16:15 -07:00
Michael Niedermayer 3690393f68 avutil/dict: delay addition of const from e12a73246d until next major ABI bump
This unbreaks API

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-05-14 15:44:01 +02:00
Roman Fietze e12a73246d dict: const pointers to dictionary where possible
This avoids temporaries or ugly casting in the calling code where
const dictionaries are used. Esp. helpful when writing C++ wrappers
for an AVDictionary having const member functions and CTORs with const
references.

Signed-off-by: Roman Fietze <roman.fietze@telemotive.de>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-04-03 13:13:25 +02:00
Michael Niedermayer 774d0c9dba Merge commit '93d216d37a3f95190ecb9d51cf72f54ea4e04ec7'
* commit '93d216d37a3f95190ecb9d51cf72f54ea4e04ec7':
  dict: K&R formatting cosmetics

Conflicts:
	libavutil/dict.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2014-03-07 12:44:09 +01:00
Patrice Clement 93d216d37a dict: K&R formatting cosmetics 2014-03-07 01:19:22 +01:00
Clément Bœsch 28ac8426e6 lavu/dict: cosmetic realign. 2013-04-13 23:48:26 +02:00
Reimar Döffinger efa7f42020 Use the avstring.h locale-independent character type functions
Make sure the behavior does not change with the locale.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-03-07 15:16:36 +02:00
Reimar Döffinger 88d55b827d Remove incorrect use of ctype.h functions.
As far as I can tell the code should not change behaviour
depending on locale in any of these places.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2013-03-03 21:44:10 +01:00
Michael Niedermayer 086566a557 dict: fix memleak
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-02-01 03:56:51 +01:00
Paweł Hajdan, Jr 1d81f7448c dict.c: use av_mallocz instead of av_realloc
Memory passed to av_realloc must come from malloc,
calloc or realloc, and not e.g. memalign. realloc(3):

The realloc() function changes the size of the memory block pointed to
by ptr to size bytes. (...) Unless ptr is NULL, it must have been
returned by an earlier call to malloc(), calloc() or realloc().

The issue has been found by debugallocation, a part of google-perftools:
http://code.google.com/p/gperftools/ .

This makes fate pass when using LD_PRELOAD-ed debugallocation.

See also earlier discussion
http://ffmpeg.org/pipermail/ffmpeg-devel/2013-January/137234.html

Signed-off-by: Paweł Hajdan, Jr <phajdan@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-01-29 20:23:02 +01:00
Michael Niedermayer e7e14bc69a Merge commit '38c1466ca41c73c7ce347da702362cb69c151716'
* commit '38c1466ca41c73c7ce347da702362cb69c151716':
  dict: add av_dict_parse_string()
  doc: support multitable in texi2pod

Conflicts:
	doc/APIchanges
	libavutil/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-01-26 13:34:30 +01:00
Justin Ruggles 38c1466ca4 dict: add av_dict_parse_string()
Can be used to set multiple key/value pairs from a string.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2013-01-25 17:20:03 +01:00
Michael Niedermayer c581cb4e4f Merge remote-tracking branch 'qatar/master'
* qatar/master:
  Fix even more missing includes after the common.h removal
  build: Factor out rangecoder dependencies to CONFIG_RANGECODER
  build: Factor out error resilience dependencies to CONFIG_ERROR_RESILIENCE
  x86: avcodec: Consistently name all init files
  Add more missing includes after removing the implicit common.h
  Add some more missing includes after removing the implicit common.h
  Don't include common.h from avutil.h
  rtmp: Automatically compute the hash for SWFVerification

Conflicts:
	configure
	doc/APIchanges
	doc/examples/decoding_encoding.c
	libavcodec/Makefile
	libavcodec/assdec.c
	libavcodec/audio_frame_queue.c
	libavcodec/avpacket.c
	libavcodec/dv_profile.c
	libavcodec/dwt.c
	libavcodec/libtheoraenc.c
	libavcodec/rawdec.c
	libavcodec/rv40dsp.c
	libavcodec/tiff.c
	libavcodec/tiffenc.c
	libavcodec/v210dec.h
	libavcodec/vc1dsp.c
	libavcodec/x86/Makefile
	libavfilter/asrc_anullsrc.c
	libavfilter/avfilter.c
	libavfilter/buffer.c
	libavfilter/formats.c
	libavfilter/vf_ass.c
	libavfilter/vf_drawtext.c
	libavfilter/vf_fade.c
	libavfilter/vf_select.c
	libavfilter/video.c
	libavfilter/vsrc_testsrc.c
	libavformat/version.h
	libavutil/audioconvert.c
	libavutil/error.h
	libavutil/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-08-16 16:20:30 +02:00
Martin Storsjö 1d9c2dc89a Don't include common.h from avutil.h
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-08-15 22:32:06 +03:00
Michael Niedermayer f5f3684fb8 Merge remote-tracking branch 'qatar/master'
* qatar/master:
  lavf: simplify is_intra_only() by using codec descriptors.
  lavc: add an intra-only codec property.
  lavc: add codec descriptors.
  lavc: fix mixing CODEC_ID/AV_CODEC_ID in C++ code.
  dict: move struct AVDictionary definition to dict.c
  dict: add av_dict_count()

Conflicts:
	doc/APIchanges
	libavcodec/old_codec_ids.h
	libavformat/utils.c
	libavutil/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-08-11 15:01:45 +02:00
Mans Rullgard 33de86db2b dict: move struct AVDictionary definition to dict.c
This makes struct AVDictionary fully opaque now that nothing
needs to access it directly any more.

Signed-off-by: Mans Rullgard <mans@mansr.com>
2012-08-10 15:15:00 +01:00