Coverage Report

Created: 2025-07-23 06:43

/src/libunistring/lib/unistr/u-cpy-alloc.h
Line
Count
Source (jump to first uncovered line)
1
/* Copy piece of UTF-8/UTF-16/UTF-32 string.
2
   Copyright (C) 1999, 2002, 2006-2007, 2009-2024 Free Software Foundation,
3
   Inc.
4
   Written by Bruno Haible <bruno@clisp.org>, 2002.
5
6
   This file is free software.
7
   It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+".
8
   You can redistribute it and/or modify it under either
9
     - the terms of the GNU Lesser General Public License as published
10
       by the Free Software Foundation, either version 3, or (at your
11
       option) any later version, or
12
     - the terms of the GNU General Public License as published by the
13
       Free Software Foundation; either version 2, or (at your option)
14
       any later version, or
15
     - the same dual license "the GNU LGPLv3+ or the GNU GPLv2+".
16
17
   This file is distributed in the hope that it will be useful,
18
   but WITHOUT ANY WARRANTY; without even the implied warranty of
19
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
   Lesser General Public License and the GNU General Public License
21
   for more details.
22
23
   You should have received a copy of the GNU Lesser General Public
24
   License and of the GNU General Public License along with this
25
   program.  If not, see <https://www.gnu.org/licenses/>.  */
26
27
#include <stdlib.h>
28
#include <string.h>
29
30
UNIT *
31
FUNC (const UNIT *s, size_t n)
32
1.72k
{
33
1.72k
  UNIT *dest;
34
35
1.72k
  dest = (UNIT *) malloc (n > 0 ? n * sizeof (UNIT) : 1);
36
1.72k
  if (dest != NULL)
37
1.72k
    {
38
#if 0
39
      UNIT *destptr = dest;
40
41
      for (; n > 0; n--)
42
        *destptr++ = *s++;
43
#else
44
1.72k
      if (n > 0)
45
1.72k
        memcpy ((char *) dest, (const char *) s, n * sizeof (UNIT));
46
1.72k
#endif
47
1.72k
    }
48
1.72k
  return dest;
49
1.72k
}