FFmpeg
coverity.c
Go to the documentation of this file.
1 /* Coverity Scan model
2 *
3 * Copyright (C) 2014 Red Hat, Inc.
4 *
5 * Authors:
6 * Markus Armbruster <armbru@redhat.com>
7 * Paolo Bonzini <pbonzini@redhat.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or, at your
10 * option, any later version. See the COPYING file in the top-level directory.
11 */
12 /*
13 * This is the source code for our Coverity user model file. The
14 * purpose of user models is to increase scanning accuracy by explaining
15 * code Coverity can't see (out of tree libraries) or doesn't
16 * sufficiently understand. Better accuracy means both fewer false
17 * positives and more true defects. Memory leaks in particular.
18 *
19 * - A model file can't import any header files. Some built-in primitives are
20 * available but not wchar_t, NULL etc.
21 * - Modeling doesn't need full structs and typedefs. Rudimentary structs
22 * and similar types are sufficient.
23 * - An uninitialized local variable signifies that the variable could be
24 * any value.
25 *
26 * The model file must be uploaded by an admin in the analysis settings of
27 * https://scan.coverity.com/projects/54
28 *
29 * above text is based on https://github.com/qemu/qemu/blob/master/scripts/coverity-model.c
30 */
31 
32 #define NULL (void *)0
33 
34 // Based on https://scan.coverity.com/models
35 void *av_malloc(size_t size) {
36  int has_memory;
37  __coverity_negative_sink__(size);
38  if (has_memory) {
39  void *ptr = __coverity_alloc__(size);
40  __coverity_mark_as_uninitialized_buffer__(ptr);
41  __coverity_mark_as_afm_allocated__(ptr, "av_free");
42  return ptr;
43  } else {
44  return 0;
45  }
46 }
47 
48 void *av_mallocz(size_t size) {
49  int has_memory;
50  __coverity_negative_sink__(size);
51  if (has_memory) {
52  void *ptr = __coverity_alloc__(size);
53  __coverity_writeall0__(ptr);
54  __coverity_mark_as_afm_allocated__(ptr, "av_free");
55  return ptr;
56  } else {
57  return 0;
58  }
59 }
60 
61 void *av_realloc(void *ptr, size_t size) {
62  int has_memory;
63  __coverity_negative_sink__(size);
64  if (has_memory) {
65  __coverity_escape__(ptr);
66  ptr = __coverity_alloc__(size);
67  __coverity_writeall__(ptr);
68  __coverity_mark_as_afm_allocated__(ptr, "av_free");
69  return ptr;
70  } else {
71  return 0;
72  }
73 }
74 
75 void *av_free(void *ptr) {
76  __coverity_free__(ptr);
77  __coverity_mark_as_afm_freed__(ptr, "av_free");
78 }
79 
size
int size
Definition: twinvq_data.h:10344
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: coverity.c:48
av_free
void * av_free(void *ptr)
Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family.
Definition: coverity.c:75
av_malloc
void * av_malloc(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: coverity.c:35
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: coverity.c:61