Coverage Report

Created: 2026-01-09 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl/lib/curlx/strcopy.c
Line
Count
Source
1
/***************************************************************************
2
 *                                  _   _ ____  _
3
 *  Project                     ___| | | |  _ \| |
4
 *                             / __| | | | |_) | |
5
 *                            | (__| |_| |  _ <| |___
6
 *                             \___|\___/|_| \_\_____|
7
 *
8
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
 *
10
 * This software is licensed as described in the file COPYING, which
11
 * you should have received as part of this distribution. The terms
12
 * are also available at https://curl.se/docs/copyright.html.
13
 *
14
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
 * copies of the Software, and permit persons to whom the Software is
16
 * furnished to do so, under the terms of the COPYING file.
17
 *
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
 * KIND, either express or implied.
20
 *
21
 * SPDX-License-Identifier: curl
22
 *
23
 ***************************************************************************/
24
#include "../curl_setup.h"
25
26
#include "strcopy.h"
27
28
/*
29
 * curlx_strcopy() is a replacement for strcpy.
30
 *
31
 * Provide the target buffer @dest and size of the target buffer @dsize, If
32
 * the source string @src with its *string length* @slen fits in the target
33
 * buffer it will be copied there - including storing a null terminator.
34
 *
35
 * If the target buffer is too small, the copy is not performed but if the
36
 * target buffer has a non-zero size it will get a null terminator stored.
37
 */
38
void curlx_strcopy(char *dest,      /* destination buffer */
39
                   size_t dsize,    /* size of target buffer */
40
                   const char *src, /* source string */
41
                   size_t slen)     /* length of source string to copy */
42
0
{
43
0
  DEBUGASSERT(slen < dsize);
44
0
  if(slen < dsize) {
45
0
    memcpy(dest, src, slen);
46
0
    dest[slen] = 0;
47
0
  }
48
0
  else if(dsize)
49
0
    dest[0] = 0;
50
0
}