Coverage Report

Created: 2023-09-25 06:56

/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, remaining;
45
0
  primitives_t* prims;
46
47
0
  if (len < 256)
48
0
  {
49
0
    while (len--)
50
0
      *dptr++ = val;
51
52
0
    return PRIMITIVES_SUCCESS;
53
0
  }
54
55
  /* else quadratic growth memcpy algorithm */
56
0
  span = 1;
57
0
  *dptr = val;
58
0
  remaining = len - 1;
59
0
  prims = primitives_get();
60
61
0
  while (remaining)
62
0
  {
63
0
    size_t thiswidth = span;
64
65
0
    if (thiswidth > remaining)
66
0
      thiswidth = remaining;
67
68
0
    prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), thiswidth << 2);
69
0
    remaining -= thiswidth;
70
0
    span <<= 1;
71
0
  }
72
73
0
  return PRIMITIVES_SUCCESS;
74
0
}
75
76
/* ------------------------------------------------------------------------- */
77
static pstatus_t general_set_32u(UINT32 val, UINT32* pDst, UINT32 len)
78
0
{
79
0
  UINT32* dptr = (UINT32*)pDst;
80
0
  size_t span, remaining;
81
0
  primitives_t* prims;
82
83
0
  if (len < 256)
84
0
  {
85
0
    while (len--)
86
0
      *dptr++ = val;
87
88
0
    return PRIMITIVES_SUCCESS;
89
0
  }
90
91
  /* else quadratic growth memcpy algorithm */
92
0
  span = 1;
93
0
  *dptr = val;
94
0
  remaining = len - 1;
95
0
  prims = primitives_get();
96
97
0
  while (remaining)
98
0
  {
99
0
    size_t thiswidth = span;
100
101
0
    if (thiswidth > remaining)
102
0
      thiswidth = remaining;
103
104
0
    prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), thiswidth << 2);
105
0
    remaining -= thiswidth;
106
0
    span <<= 1;
107
0
  }
108
109
0
  return PRIMITIVES_SUCCESS;
110
0
}
111
112
/* ------------------------------------------------------------------------- */
113
void primitives_init_set(primitives_t* prims)
114
0
{
115
  /* Start with the default. */
116
0
  prims->set_8u = general_set_8u;
117
0
  prims->set_32s = general_set_32s;
118
0
  prims->set_32u = general_set_32u;
119
0
  prims->zero = general_zero;
120
0
}