2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 18:19:42 +00:00
bind/util/models.c

140 lines
2.6 KiB
C
Raw Normal View History

2015-04-18 21:26:35 +10:00
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
2015-04-18 21:26:35 +10:00
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
2015-04-18 21:26:35 +10:00
*/
2015-04-17 13:59:28 +10:00
/*
* Provide a simple memory management model for lib/isc/mem.c
* which hides all the internal storage and memory filling.
2015-09-15 16:47:50 +10:00
*
* See https://scan.coverity.com/models
2015-04-17 13:59:28 +10:00
*/
#define FLARG , const char *file, unsigned int line
2015-04-17 13:59:28 +10:00
#define FLARG_PASS , file, line
int condition;
void *
isc__mem_get(void *mem, unsigned int size FLARG)
{
if (!mem)
__coverity_panic__();
2015-04-18 21:26:35 +10:00
__coverity_negative_sink__(size);
if (condition)
return (0);
return (__coverity_alloc__(size));
2015-04-17 13:59:28 +10:00
}
void
isc__mem_put(void *mem, void *ptr, unsigned int size FLARG)
{
if (!mem)
__coverity_panic__();
2015-04-18 21:26:35 +10:00
__coverity_free__(ptr);
2015-04-17 13:59:28 +10:00
}
void
isc__mem_putanddetach(void *mem, void *ptr, unsigned int size FLARG)
{
if (!mem)
__coverity_panic__();
2015-04-18 21:26:35 +10:00
__coverity_free__(ptr);
2015-04-17 13:59:28 +10:00
}
void *
isc__mem_allocate(void *mem, unsigned int size FLARG)
{
if (!mem)
__coverity_panic__();
2015-04-18 21:26:35 +10:00
__coverity_negative_sink__(size);
if (condition)
return (0);
return (__coverity_alloc__(size));
2015-04-17 13:59:28 +10:00
}
void *
memcpy(void *s1, const void *s2, size_t n);
2015-04-17 13:59:28 +10:00
void *
isc__mem_reallocate(void *mem, void *ptr, size_t size FLARG)
{
char * p = (char *)0;
2015-04-18 21:26:35 +10:00
size_t l;
2015-04-17 13:59:28 +10:00
if (!mem)
__coverity_panic__();
2015-04-18 21:26:35 +10:00
if (size > 0) {
p = isc__mem_allocate(mem, size FLARG_PASS);
if (p && ptr) {
2015-04-17 13:59:28 +10:00
l = (l > size) ? size : l;
2015-04-18 21:26:35 +10:00
memcpy(p, ptr, l);
__coverity_free__(ptr);
}
} else if (ptr)
__coverity_free__(ptr);
return (p);
2015-04-17 13:59:28 +10:00
}
void
isc__mem_free(void *mem, void *ptr FLARG)
{
if (!mem)
__coverity_panic__();
2015-04-18 21:26:35 +10:00
__coverity_free__(ptr);
2015-04-17 13:59:28 +10:00
}
unsigned int
strlen(const char *);
2015-04-17 13:59:28 +10:00
void *
isc__mem_strdup(void *mem, char *s FLARG)
{
2015-04-18 21:26:35 +10:00
void *d;
if (!mem)
__coverity_panic__();
2015-04-18 21:26:35 +10:00
if (condition)
return (0);
d = __coverity_alloc__(strlen(s) + 1);
__coverity_writeall__(d);
return (d);
2015-04-17 13:59:28 +10:00
}
void *
isc__mempool_get(void *mem FLARG)
{
2015-04-18 21:26:35 +10:00
unsigned int size;
if (!mem)
__coverity_panic__();
2015-04-18 21:26:35 +10:00
if (condition)
return (0);
return (__coverity_alloc__(size));
2015-04-17 13:59:28 +10:00
}
void
isc__mempool_put(void *mem, void *ptr FLARG)
{
if (!mem)
__coverity_panic__();
2015-04-18 21:26:35 +10:00
__coverity_free__(ptr);
2015-04-17 13:59:28 +10:00
}
2018-11-21 12:45:55 +11:00
/*
* Cmocka models.
*/
#define LargestIntegralType unsigned long int
void
_assert_true(const LargestIntegralType result, const char *const expression,
const char *const file, const int line)
2018-11-21 12:45:55 +11:00
{
if (!result)
__coverity_panic__();
2018-11-21 12:45:55 +11:00
}