coverity.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #define NULL (void *)0
  32. typedef long long int64_t;
  33. enum AVRounding {
  34. AV_ROUND_ZERO = 0,
  35. AV_ROUND_INF = 1,
  36. AV_ROUND_DOWN = 2,
  37. AV_ROUND_UP = 3,
  38. AV_ROUND_NEAR_INF = 5,
  39. AV_ROUND_PASS_MINMAX = 8192,
  40. };
  41. // Based on https://scan.coverity.com/models
  42. void *av_malloc(size_t size) {
  43. int has_memory;
  44. __coverity_negative_sink__(size);
  45. if (has_memory) {
  46. void *ptr = __coverity_alloc__(size);
  47. __coverity_mark_as_uninitialized_buffer__(ptr);
  48. __coverity_mark_as_afm_allocated__(ptr, "av_free");
  49. return ptr;
  50. } else {
  51. return 0;
  52. }
  53. }
  54. void *av_mallocz(size_t size) {
  55. int has_memory;
  56. __coverity_negative_sink__(size);
  57. if (has_memory) {
  58. void *ptr = __coverity_alloc__(size);
  59. __coverity_writeall0__(ptr);
  60. __coverity_mark_as_afm_allocated__(ptr, "av_free");
  61. return ptr;
  62. } else {
  63. return 0;
  64. }
  65. }
  66. void *av_realloc(void *ptr, size_t size) {
  67. int has_memory;
  68. __coverity_negative_sink__(size);
  69. if (has_memory) {
  70. __coverity_escape__(ptr);
  71. ptr = __coverity_alloc__(size);
  72. __coverity_writeall__(ptr);
  73. __coverity_mark_as_afm_allocated__(ptr, "av_free");
  74. return ptr;
  75. } else {
  76. return 0;
  77. }
  78. }
  79. void *av_free(void *ptr) {
  80. __coverity_free__(ptr);
  81. __coverity_mark_as_afm_freed__(ptr, "av_free");
  82. }
  83. int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd) {
  84. __coverity_negative_sink__(b);
  85. __coverity_negative_sink__(c);
  86. return (double)a * (double)b / (double)c;
  87. }