Coverage Report

Created: 2024-05-20 06:11

/src/FreeRDP/libfreerdp/primitives/prim_set.c
Line
Count
Source (jump to first uncovered line)
1
/* FreeRDP: A Remote Desktop Protocol Client
2
 * Routines to set a chunk of memory to a constant.
3
 * vi:ts=4 sw=4:
4
 *
5
 * (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
6
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
7
 * not use this file except in compliance with the License. You may obtain
8
 * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
9
 * Unless required by applicable law or agreed to in writing, software
10
 * distributed under the License is distributed on an "AS IS" BASIS,
11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12
 * or implied. See the License for the specific language governing
13
 * permissions and limitations under the License.
14
 *
15
 */
16
17
#include <freerdp/config.h>
18
19
#include <string.h>
20
21
#include <freerdp/types.h>
22
#include <freerdp/primitives.h>
23
24
#include "prim_internal.h"
25
26
/* ========================================================================= */
27
static pstatus_t general_set_8u(BYTE val, BYTE* pDst, UINT32 len)
28
0
{
29
0
  memset((void*)pDst, (int)val, (size_t)len);
30
0
  return PRIMITIVES_SUCCESS;
31
0
}
32
33
/* ------------------------------------------------------------------------- */
34
static pstatus_t general_zero(void* pDst, size_t len)
35
0
{
36
0
  memset(pDst, 0, len);
37
0
  return PRIMITIVES_SUCCESS;
38
0
}
39
40
/* ========================================================================= */
41
static pstatus_t general_set_32s(INT32 val, INT32* pDst, UINT32 len)
42
0
{
43
0
  INT32* dptr = (INT32*)pDst;
44
0
  size_t span = 0;
45
0
  size_t remaining = 0;
46
0
  primitives_t* prims = NULL;
47
48
0
  if (len < 256)
49
0
  {
50
0
    while (len--)
51
0
      *dptr++ = val;
52
53
0
    return PRIMITIVES_SUCCESS;
54
0
  }
55
56
  /* else quadratic growth memcpy algorithm */
57
0
  span = 1;
58
0
  *dptr = val;
59
0
  remaining = len - 1;
60
0
  prims = primitives_get();
61
62
0
  while (remaining)
63
0
  {
64
0
    size_t thiswidth = span;
65
66
0
    if (thiswidth > remaining)
67
0
      thiswidth = remaining;
68
69
0
    prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), thiswidth << 2);
70
0
    remaining -= thiswidth;
71
0
    span <<= 1;
72
0
  }
73
74
0
  return PRIMITIVES_SUCCESS;
75
0
}
76
77
/* ------------------------------------------------------------------------- */
78
static pstatus_t general_set_32u(UINT32 val, UINT32* pDst, UINT32 len)
79
0
{
80
0
  UINT32* dptr = (UINT32*)pDst;
81
0
  size_t span = 0;
82
0
  size_t remaining = 0;
83
0
  primitives_t* prims = NULL;
84
85
0
  if (len < 256)
86
0
  {
87
0
    while (len--)
88
0
      *dptr++ = val;
89
90
0
    return PRIMITIVES_SUCCESS;
91
0
  }
92
93
  /* else quadratic growth memcpy algorithm */
94
0
  span = 1;
95
0
  *dptr = val;
96
0
  remaining = len - 1;
97
0
  prims = primitives_get();
98
99
0
  while (remaining)
100
0
  {
101
0
    size_t thiswidth = span;
102
103
0
    if (thiswidth > remaining)
104
0
      thiswidth = remaining;
105
106
0
    prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), thiswidth << 2);
107
0
    remaining -= thiswidth;
108
0
    span <<= 1;
109
0
  }
110
111
0
  return PRIMITIVES_SUCCESS;
112
0
}
113
114
/* ------------------------------------------------------------------------- */
115
void primitives_init_set(primitives_t* prims)
116
1
{
117
  /* Start with the default. */
118
1
  prims->set_8u = general_set_8u;
119
1
  prims->set_32s = general_set_32s;
120
1
  prims->set_32u = general_set_32u;
121
1
  prims->zero = general_zero;
122
1
}