<commit_before>/*
 * Copyright 2008 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <setjmp.h>
#ifndef _WIN32
#include <signal.h>
#endif // !_WIN32
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#endif // _WIN32
#include <cmockery.h>

#ifdef _WIN32
#define vsnprintf _vsnprintf
#endif // _WIN32

/* Backwards compatibility with headers shipped with Visual Studio 2005 and
 * earlier. */
#ifdef _WIN32
WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID);
#endif // _WIN32

// Size of guard bytes around dynamically allocated blocks.
#define MALLOC_GUARD_SIZE 16
// Pattern used to initialize guard blocks.
#define MALLOC_GUARD_PATTERN 0xEF
// Pattern used to initialize memory allocated with test_malloc().
#define MALLOC_ALLOC_PATTERN 0xBA
#define MALLOC_FREE_PATTERN 0xCD
// Alignment of allocated blocks.  NOTE: This must be base2.
#define MALLOC_ALIGNMENT sizeof(size_t)

// Printf formatting for source code locations.
#define SOURCE_LOCATION_FORMAT "%s:%d"

// Calculates the number of elements in an array.
#define ARRAY_LENGTH(x) (sizeof(x) / sizeof((x)[0]))

// Declare and initialize the pointer member of ValuePointer variable name
// with ptr.
#define declare_initialize_value_pointer_pointer(name, ptr) \
    ValuePointer name ; \
    name.value = 0; \
    name.pointer = (void*)(ptr)

// Declare and initialize the value member of ValuePointer variable name
// with val.
#define declare_initialize_value_pointer_value(name, val) \
    ValuePointer name ; \
    name.value = val

// Cast a LargestIntegralType to pointer_type via a ValuePointer.
#define cast_largest_integral_type_to_pointer( \
    pointer_type, largest_integral_type) \
    ((pointer_type)((ValuePointer*)&(largest_integral_type))->pointer)

// Used to cast LargetIntegralType to void* and vice versa.
typedef union ValuePointer {
    LargestIntegralType value;
    void *pointer;
} ValuePointer;

// Doubly linked list node.
typedef struct ListNode {
    const void *value;
    int refcount;
    struct ListNode *next;
    struct ListNode *prev;
} ListNode;

// Debug information for malloc().
typedef struct MallocBlockInfo {
    void* block;              // Address of the block returned by malloc().
    size_t allocated_size;    // Total size of the allocated block.
    size_t size;              // Request block size.
    SourceLocation location;  // Where the block was allocated.
    ListNode node;            // Node within list of all allocated blocks.
} MallocBlockInfo;

// State of each test.
typedef struct TestState {
    const ListNode *check_point; // Check point of the test if there's a
                                 // setup function.
    void *state;                 // State associated with the test.
} TestState;

// Determines whether two values are the same.
typedef int (*EqualityFunction)(const void *left, const void *right);

// Value of a symbol and the place it was declared.
typedef struct SymbolValue {
    SourceLocation location;
    LargestIntegralType value;
} SymbolValue;

/* Contains a list of values for a symbol.
 * NOTE: Each structure referenced by symbol_values_list_head must have a
 * SourceLocation as its' first member.
 */
typedef struct SymbolMapValue {
    const char *symbol_name;
    ListNode symbol_values_list_head;
} SymbolMapValue;

// Used by list_free() to deallocate values referenced by list nodes.
typedef void (*CleanupListValue)(const void *value, void *cleanup_value_data);

// Structure used to check the range of integer types.
typedef struct CheckIntegerRange {
    CheckParameterEvent event;
    int minimum;
    int maximum;
} CheckIntegerRange;

// Structure used to check whether an integer value is in a set.
typedef struct CheckIntegerSet {
    CheckParameterEvent event;
    const LargestIntegralType *set;
    size_t size_of_set;
} CheckIntegerSet;

/* Used to check whether a parameter matches the area of memory referenced by
 * this structure.  */
typedef struct CheckMemoryData {
    CheckParameterEvent event;
    const void *memory;
    size_t size;
} CheckMemoryData;

static ListNode* list_initialize(ListNode * const node);
static ListNode* list_add(ListNode * const head, ListNode *new_node);
static ListNode* list_add_value(ListNode * const head, const void *value,
                                     const int count);<commit_msg>Fixed truncation in integer range checking event structure to store min and max values as LargestIntegralType rather than int.<commit_after>/*
 * Copyright 2008 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <setjmp.h>
#ifndef _WIN32
#include <signal.h>
#endif // !_WIN32
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#endif // _WIN32
#include <cmockery.h>

#ifdef _WIN32
#define vsnprintf _vsnprintf
#endif // _WIN32

/* Backwards compatibility with headers shipped with Visual Studio 2005 and
 * earlier. */
#ifdef _WIN32
WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID);
#endif // _WIN32

// Size of guard bytes around dynamically allocated blocks.
#define MALLOC_GUARD_SIZE 16
// Pattern used to initialize guard blocks.
#define MALLOC_GUARD_PATTERN 0xEF
// Pattern used to initialize memory allocated with test_malloc().
#define MALLOC_ALLOC_PATTERN 0xBA
#define MALLOC_FREE_PATTERN 0xCD
// Alignment of allocated blocks.  NOTE: This must be base2.
#define MALLOC_ALIGNMENT sizeof(size_t)

// Printf formatting for source code locations.
#define SOURCE_LOCATION_FORMAT "%s:%d"

// Calculates the number of elements in an array.
#define ARRAY_LENGTH(x) (sizeof(x) / sizeof((x)[0]))

// Declare and initialize the pointer member of ValuePointer variable name
// with ptr.
#define declare_initialize_value_pointer_pointer(name, ptr) \
    ValuePointer name ; \
    name.value = 0; \
    name.pointer = (void*)(ptr)

// Declare and initialize the value member of ValuePointer variable name
// with val.
#define declare_initialize_value_pointer_value(name, val) \
    ValuePointer name ; \
    name.value = val

// Cast a LargestIntegralType to pointer_type via a ValuePointer.
#define cast_largest_integral_type_to_pointer( \
    pointer_type, largest_integral_type) \
    ((pointer_type)((ValuePointer*)&(largest_integral_type))->pointer)

// Used to cast LargetIntegralType to void* and vice versa.
typedef union ValuePointer {
    LargestIntegralType value;
    void *pointer;
} ValuePointer;

// Doubly linked list node.
typedef struct ListNode {
    const void *value;
    int refcount;
    struct ListNode *next;
    struct ListNode *prev;
} ListNode;

// Debug information for malloc().
typedef struct MallocBlockInfo {
    void* block;              // Address of the block returned by malloc().
    size_t allocated_size;    // Total size of the allocated block.
    size_t size;              // Request block size.
    SourceLocation location;  // Where the block was allocated.
    ListNode node;            // Node within list of all allocated blocks.
} MallocBlockInfo;

// State of each test.
typedef struct TestState {
    const ListNode *check_point; // Check point of the test if there's a
                                 // setup function.
    void *state;                 // State associated with the test.
} TestState;

// Determines whether two values are the same.
typedef int (*EqualityFunction)(const void *left, const void *right);

// Value of a symbol and the place it was declared.
typedef struct SymbolValue {
    SourceLocation location;
    LargestIntegralType value;
} SymbolValue;

/* Contains a list of values for a symbol.
 * NOTE: Each structure referenced by symbol_values_list_head must have a
 * SourceLocation as its' first member.
 */
typedef struct SymbolMapValue {
    const char *symbol_name;
    ListNode symbol_values_list_head;
} SymbolMapValue;

// Used by list_free() to deallocate values referenced by list nodes.
typedef void (*CleanupListValue)(const void *value, void *cleanup_value_data);

// Structure used to check the range of integer types.
typedef struct CheckIntegerRange {
    CheckParameterEvent event;
    LargestIntegralType minimum;
    LargestIntegralType maximum;
} CheckIntegerRange;

// Structure used to check whether an integer value is in a set.
typedef struct CheckIntegerSet {
    CheckParameterEvent event;
    const LargestIntegralType *set;
    size_t size_of_set;
} CheckIntegerSet;

/* Used to check whether a parameter matches the area of memory referenced by
 * this structure.  */
typedef struct CheckMemoryData {
    CheckParameterEvent event;
    const void *memory;
    size_t size;
} CheckMemoryData;

static ListNode* list_initialize(ListNode * const node);
static ListNode* list_add(ListNode * const head, ListNode *new_node);
static ListNode* list_add_value(ListNode * const head, const void *value,
                                     const int count);
{'fraction_non_alphanumeric': 0.07953986825287582, 'fraction_numerical': 0.007078949955756563, 'mean_word_length': 3.6918819188191883, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3774849', 'n_tokens_mistral': 2969, 'n_tokens_neox': 2831, 'n_words': 1111}