|
Packit Service |
20376f |
#include "clar_libgit2.h"
|
|
Packit Service |
20376f |
#include "buffer.h"
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* We want to use some ridiculous size that `malloc` will fail with
|
|
Packit Service |
20376f |
* but that does not otherwise interfere with testing. On Linux, choose
|
|
Packit Service |
20376f |
* a number that is large enough to fail immediately but small enough
|
|
Packit Service |
20376f |
* that valgrind doesn't believe it to erroneously be a negative number.
|
|
Packit Service |
20376f |
* On macOS, choose a number that is large enough to fail immediately
|
|
Packit Service |
20376f |
* without having libc print warnings to stderr.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
#if defined(GIT_ARCH_64) && defined(__linux__)
|
|
Packit Service |
20376f |
# define TOOBIG 0x0fffffffffffffff
|
|
Packit Service |
20376f |
#elif defined(__linux__)
|
|
Packit Service |
20376f |
# define TOOBIG 0x0fffffff
|
|
Packit Service |
20376f |
#elif defined(GIT_ARCH_64)
|
|
Packit Service |
20376f |
# define TOOBIG 0xffffffffffffff00
|
|
Packit Service |
20376f |
#else
|
|
Packit Service |
20376f |
# define TOOBIG 0xffffff00
|
|
Packit Service |
20376f |
#endif
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* If we make a ridiculously large request the first time we
|
|
Packit Service |
20376f |
* actually allocate some space in the git_buf, the realloc()
|
|
Packit Service |
20376f |
* will fail. And because the git_buf_grow() wrapper always
|
|
Packit Service |
20376f |
* sets mark_oom, the code in git_buf_try_grow() will free
|
|
Packit Service |
20376f |
* the internal buffer and set it to git_buf__oom.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* We initialized the internal buffer to (the static variable)
|
|
Packit Service |
20376f |
* git_buf__initbuf. The purpose of this test is to make sure
|
|
Packit Service |
20376f |
* that we don't try to free the static buffer.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
void test_buf_oom__grow(void)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
git_buf buf = GIT_BUF_INIT;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_buf_clear(&buf;;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
cl_assert(git_buf_grow(&buf, TOOBIG) == -1);
|
|
Packit Service |
20376f |
cl_assert(git_buf_oom(&buf));
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_buf_free(&buf;;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void test_buf_oom__grow_by(void)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
git_buf buf = GIT_BUF_INIT;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
buf.size = SIZE_MAX-10;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
cl_assert(git_buf_grow_by(&buf, 50) == -1);
|
|
Packit Service |
20376f |
cl_assert(git_buf_oom(&buf));
|
|
Packit Service |
20376f |
}
|