interplane.Get Omega
Read in your language

cJSON

[Ported from github.com/DaveGamble/cJSON] Fix: heap-use-after-free in merge_patch when patch is subtree of target (#1065)

Brought by drakestapleton

branch master Branches Tags History

cJSON / tests / unity / extras / fixture / test / unity_output_Spy.c

57 lines · 1206 bytes Raw Blame History
1/* Copyright (c) 2010 James Grenning and Contributed to Unity Project
2 * ==========================================
3 * Unity Project - A Test Framework for C
4 * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
5 * [Released under MIT License. Please refer to license.txt for details]
6 * ========================================== */
7
8
9#include "unity_output_Spy.h"
10#include "unity_fixture.h"
11
12#include <stdio.h>
13#include <string.h>
14
15static int size;
16static int count;
17static char* buffer;
18static int spy_enable;
19
20void UnityOutputCharSpy_Create(int s)
21{
22 size = (s > 0) ? s : 0;
23 count = 0;
24 spy_enable = 0;
25 buffer = malloc((size_t)size);
26 TEST_ASSERT_NOT_NULL_MESSAGE(buffer, "Internal malloc failed in Spy Create():" __FILE__);
27 memset(buffer, 0, (size_t)size);
28}
29
30void UnityOutputCharSpy_Destroy(void)
31{
32 size = 0;
33 free(buffer);
34}
35
36void UnityOutputCharSpy_OutputChar(int c)
37{
38 if (spy_enable)
39 {
40 if (count < (size-1))
41 buffer[count++] = (char)c;
42 }
43 else
44 {
45 putchar(c);
46 }
47}
48
49const char * UnityOutputCharSpy_Get(void)
50{
51 return buffer;
52}
53
54void UnityOutputCharSpy_Enable(int enable)
55{
56 spy_enable = enable;
57}