History

Merge commit '3b4feac1ec14f861bdd7f494f288f4d8dd7f449e'

* commit '3b4feac1ec14f861bdd7f494f288f4d8dd7f449e': movenc: Keep track of the allocated size for the cluster array mem: Add av_realloc_array and av_reallocp_array Conflicts: doc/APIchanges libavformat/movenc.c libavutil/mem.c libavutil/mem.h libavutil/version.h

Michael Niedermayer committed 13 years ago

Commit 30b491f2 parents ea038b9 3b4feac6 files · +63 −5Browse files

Unified · Split

6 files
  1. doc/APIchanges +3 −0
  2. libavformat/movenc.c +6 −4
  3. libavformat/movenc.h +1 −0
  4. libavutil/mem.c +26 −0
  5. libavutil/mem.h +26 −0
  6. libavutil/version.h +1 −1
doc/APIchanges+3−0
@@ -16,6 +16,9 @@ libavutil: 2012-10-22 · 15 unmodified lines
1616 API changes, most recent first:
1717
1818
19+2013-06-05 - fc962d4 - lavu 52.13.0 - mem.h
20+ Add av_realloc_array and av_reallocp_array
21+
1922 2013-05-24 - xxxxxxx - lavfi 3.70.100 - avfilter.h
2023 Add support for slice multithreading to lavfi. Filters supporting threading
2124 are marked with AVFILTER_FLAG_SLICE_THREADS.
libavformat/movenc.c+6−4
@@ -3208,10 +3208,12 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) · 3207 unmodified lines
32083208 memcpy(trk->vos_data, pkt->data, size);
32093209 }
32103210
3211− if (!(trk->entry % MOV_INDEX_CLUSTER_SIZE)) {
3212− trk->cluster = av_realloc_f(trk->cluster, sizeof(*trk->cluster), (trk->entry + MOV_INDEX_CLUSTER_SIZE));
3213− if (!trk->cluster)
3214− return -1;
3211+ if (trk->entry >= trk->cluster_capacity) {
3212+ unsigned new_capacity = trk->entry + MOV_INDEX_CLUSTER_SIZE;
3213+ if (av_reallocp_array(&trk->cluster, new_capacity,
3214+ sizeof(*trk->cluster)))
3215+ return AVERROR(ENOMEM);
3216+ trk->cluster_capacity = new_capacity;
32153217 }
32163218
32173219 trk->cluster[trk->entry].pos = avio_tell(pb) - size;
libavformat/movenc.h+1−0
@@ -102,6 +102,7 @@ typedef struct MOVTrack { · 101 unmodified lines
102102 int vos_len;
103103 uint8_t *vos_data;
104104 MOVIentry *cluster;
105+ unsigned cluster_capacity;
105106 int audio_vbr;
106107 int height; ///< active picture (w/o VBI) height for D-10/IMX
107108 uint32_t tref_tag;
libavutil/mem.c+26−0
@@ -180,6 +180,32 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize) · 179 unmodified lines
180180 return r;
181181 }
182182
183+void *av_realloc_array(void *ptr, size_t nmemb, size_t size)
184+{
185+ if (size <= 0 || nmemb >= INT_MAX / size)
186+ return NULL;
187+ return av_realloc(ptr, nmemb * size);
188+}
189+
190+int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
191+{
192+ void **ptrptr = ptr;
193+ void *ret;
194+ if (size <= 0 || nmemb >= INT_MAX / size)
195+ return AVERROR(ENOMEM);
196+ if (nmemb <= 0) {
197+ av_freep(ptr);
198+ return 0;
199+ }
200+ ret = av_realloc(*ptrptr, nmemb * size);
201+ if (!ret) {
202+ av_freep(ptr);
203+ return AVERROR(ENOMEM);
204+ }
205+ *ptrptr = ret;
206+ return 0;
207+}
208+
183209 void av_free(void *ptr)
184210 {
185211 #if CONFIG_MEMALIGN_HACK
libavutil/mem.h+26−0
@@ -122,6 +122,32 @@ void *av_realloc(void *ptr, size_t size) av_alloc_size(2); · 121 unmodified lines
122122 */
123123 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
124124
125+/**
126+ * Allocate or reallocate an array.
127+ * If ptr is NULL and nmemb > 0, allocate a new block. If
128+ * nmemb is zero, free the memory block pointed to by ptr.
129+ * @param ptr Pointer to a memory block already allocated with
130+ * av_malloc(z)() or av_realloc() or NULL.
131+ * @param nmemb Number of elements
132+ * @param size Size of the single element
133+ * @return Pointer to a newly reallocated block or NULL if the block
134+ * cannot be reallocated or the function is used to free the memory block.
135+ */
136+av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size);
137+
138+/**
139+ * Allocate or reallocate an array.
140+ * If *ptr is NULL and nmemb > 0, allocate a new block. If
141+ * nmemb is zero, free the memory block pointed to by ptr.
142+ * @param ptr Pointer to a pointer to a memory block already allocated
143+ * with av_malloc(z)() or av_realloc(), or pointer to a pointer to NULL.
144+ * The pointer is updated on success, or freed on failure.
145+ * @param nmemb Number of elements
146+ * @param size Size of the single element
147+ * @return Zero on success, an AVERROR error code on failure.
148+ */
149+av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size);
150+
125151 /**
126152 * Free a memory block which has been allocated with av_malloc(z)() or
127153 * av_realloc().
libavutil/version.h+1−1
@@ -75,7 +75,7 @@ · 74 unmodified lines
7575 */
7676
7777 #define LIBAVUTIL_VERSION_MAJOR 52
78−#define LIBAVUTIL_VERSION_MINOR 34
78+#define LIBAVUTIL_VERSION_MINOR 35
7979 #define LIBAVUTIL_VERSION_MICRO 100
8080
8181 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t