← Back to C-Kernel-Engine Docs Doxygen Source Documentation
Loading...
Searching...
No Matches
concat_i32_checked.c File Reference
#include "ckernel_concat_i32.h"
#include <stdint.h>
#include <string.h>

Go to the source code of this file.

Functions

int ck_concat_i32_checked (const int32_t *left, size_t left_elements, size_t left_count, const int32_t *right, size_t right_elements, size_t right_count, int32_t *output, size_t output_elements)
static int overlaps (const int32_t *left, size_t left_count, const int32_t *right, size_t right_count)
static int valid_region (const int32_t *pointer, size_t elements)

Function Documentation

◆ ck_concat_i32_checked()

int ck_concat_i32_checked ( const int32_t * left,
size_t left_elements,
size_t left_count,
const int32_t * right,
size_t right_elements,
size_t right_count,
int32_t * output,
size_t output_elements )

Definition at line 20 of file concat_i32_checked.c.

23 {
24 if (!left_count || !right_count || left_count > SIZE_MAX - right_count ||
25 left_count > left_elements || right_count > right_elements ||
26 left_count + right_count > output_elements)
27 return -2;
28 if (!valid_region(left, left_count) || !valid_region(right, right_count) ||
29 !valid_region(output, left_count + right_count) ||
30 overlaps(left, left_count, output, left_count + right_count) ||
31 overlaps(right, right_count, output, left_count + right_count))
32 return -1;
33 memcpy(output, left, left_count * sizeof(int32_t));
34 memcpy(output + left_count, right, right_count * sizeof(int32_t));
35 return 0;
36}
static int overlaps(const int32_t *left, size_t left_count, const int32_t *right, size_t right_count)
static int valid_region(const int32_t *pointer, size_t elements)
const char * left
Definition true_bpe.h:140
const char const char * right
Definition true_bpe.h:141

References left, overlaps(), right, and valid_region().

◆ overlaps()

int overlaps ( const int32_t * left,
size_t left_count,
const int32_t * right,
size_t right_count )
static

Definition at line 12 of file concat_i32_checked.c.

13 {
14 const uintptr_t a = (uintptr_t)left;
15 const uintptr_t b = (uintptr_t)right;
16 return a < b + right_count * sizeof(int32_t) &&
17 b < a + left_count * sizeof(int32_t);
18}

References left, and right.

Referenced by ck_concat_i32_checked().

◆ valid_region()

int valid_region ( const int32_t * pointer,
size_t elements )
static

Definition at line 6 of file concat_i32_checked.c.

6 {
7 return pointer && (uintptr_t)pointer % _Alignof(int32_t) == 0 &&
8 elements <= SIZE_MAX / sizeof(int32_t) &&
9 (uintptr_t)pointer <= UINTPTR_MAX - elements * sizeof(int32_t);
10}

Referenced by ck_concat_i32_checked().