Coverage Report

Created: 2025-10-10 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/winpr/libwinpr/path/include/PathCchAppend.h
Line
Count
Source
1
2
/*
3
#define DEFINE_UNICODE    FALSE
4
#define CUR_PATH_SEPARATOR_CHR  '\\'
5
#define CUR_PATH_SEPARATOR_STR  "\\"
6
#define PATH_CCH_APPEND   PathCchAppendA
7
*/
8
9
#include <string.h>
10
11
#include <winpr/wtypes.h>
12
#include <winpr/error.h>
13
#include <winpr/path.h>
14
15
#if defined(DEFINE_UNICODE) && (DEFINE_UNICODE != 0)
16
17
HRESULT PATH_CCH_APPEND(PWSTR pszPath, size_t cchPath, PCWSTR pszMore)
18
0
{
19
0
  if (!pszPath)
20
0
    return E_INVALIDARG;
21
22
0
  if (!pszMore)
23
0
    return E_INVALIDARG;
24
25
0
  if ((cchPath == 0) || (cchPath > PATHCCH_MAX_CCH))
26
0
    return E_INVALIDARG;
27
28
0
  const size_t pszMoreLength = _wcsnlen(pszMore, cchPath);
29
0
  const size_t pszPathLength = _wcsnlen(pszPath, cchPath);
30
31
0
  BOOL pathBackslash = FALSE;
32
0
  if (pszPathLength > 0)
33
0
    pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
34
35
0
  const BOOL moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
36
37
0
  if (pathBackslash && moreBackslash)
38
0
  {
39
0
    if (pszMoreLength < 1)
40
0
      return E_INVALIDARG;
41
42
0
    if ((pszPathLength + pszMoreLength - 1) < cchPath)
43
0
    {
44
0
      WCHAR* ptr = &pszPath[pszPathLength];
45
0
      *ptr = '\0';
46
0
      _wcsncat(ptr, &pszMore[1], pszMoreLength - 1);
47
0
      return S_OK;
48
0
    }
49
0
  }
50
0
  else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
51
0
  {
52
0
    if ((pszPathLength + pszMoreLength) < cchPath)
53
0
    {
54
0
      WCHAR* ptr = &pszPath[pszPathLength];
55
0
      *ptr = '\0';
56
0
      _wcsncat(ptr, pszMore, pszMoreLength);
57
0
      return S_OK;
58
0
    }
59
0
  }
60
0
  else if (!pathBackslash && !moreBackslash)
61
0
  {
62
0
    if ((pszPathLength + pszMoreLength + 1) < cchPath)
63
0
    {
64
0
      WCHAR* ptr = &pszPath[pszPathLength];
65
0
      *ptr = '\0';
66
0
      _wcsncat(ptr, CUR_PATH_SEPARATOR_STR,
67
0
               _wcsnlen(CUR_PATH_SEPARATOR_STR, ARRAYSIZE(CUR_PATH_SEPARATOR_STR)));
68
0
      _wcsncat(ptr, pszMore, pszMoreLength);
69
0
      return S_OK;
70
0
    }
71
0
  }
72
73
0
  return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
74
0
}
Unexecuted instantiation: PathCchAppendW
Unexecuted instantiation: UnixPathCchAppendW
Unexecuted instantiation: NativePathCchAppendW
75
76
#else
77
78
HRESULT PATH_CCH_APPEND(PSTR pszPath, size_t cchPath, PCSTR pszMore)
79
582k
{
80
582k
  BOOL pathBackslash = FALSE;
81
582k
  BOOL moreBackslash = FALSE;
82
83
582k
  if (!pszPath)
84
0
    return E_INVALIDARG;
85
86
582k
  if (!pszMore)
87
0
    return E_INVALIDARG;
88
89
582k
  if ((cchPath == 0) || (cchPath > PATHCCH_MAX_CCH))
90
0
    return E_INVALIDARG;
91
92
582k
  const size_t pszPathLength = strnlen(pszPath, cchPath);
93
582k
  if (pszPathLength > 0)
94
582k
    pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
95
96
582k
  const size_t pszMoreLength = strnlen(pszMore, cchPath);
97
582k
  if (pszMoreLength > 0)
98
582k
    moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
99
100
582k
  if (pathBackslash && moreBackslash)
101
0
  {
102
0
    if ((pszPathLength + pszMoreLength - 1) < cchPath)
103
0
    {
104
0
      sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", &pszMore[1]);
105
0
      return S_OK;
106
0
    }
107
0
  }
108
582k
  else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
109
0
  {
110
0
    if ((pszPathLength + pszMoreLength) < cchPath)
111
0
    {
112
0
      sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszMore);
113
0
      return S_OK;
114
0
    }
115
0
  }
116
582k
  else if (!pathBackslash && !moreBackslash)
117
582k
  {
118
582k
    if ((pszPathLength + pszMoreLength + 1) < cchPath)
119
582k
    {
120
582k
      sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s%s",
121
582k
                CUR_PATH_SEPARATOR_STR, pszMore);
122
582k
      return S_OK;
123
582k
    }
124
582k
  }
125
126
0
  return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
127
582k
}
Unexecuted instantiation: PathCchAppendA
Unexecuted instantiation: UnixPathCchAppendA
NativePathCchAppendA
Line
Count
Source
79
582k
{
80
582k
  BOOL pathBackslash = FALSE;
81
582k
  BOOL moreBackslash = FALSE;
82
83
582k
  if (!pszPath)
84
0
    return E_INVALIDARG;
85
86
582k
  if (!pszMore)
87
0
    return E_INVALIDARG;
88
89
582k
  if ((cchPath == 0) || (cchPath > PATHCCH_MAX_CCH))
90
0
    return E_INVALIDARG;
91
92
582k
  const size_t pszPathLength = strnlen(pszPath, cchPath);
93
582k
  if (pszPathLength > 0)
94
582k
    pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
95
96
582k
  const size_t pszMoreLength = strnlen(pszMore, cchPath);
97
582k
  if (pszMoreLength > 0)
98
582k
    moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
99
100
582k
  if (pathBackslash && moreBackslash)
101
0
  {
102
0
    if ((pszPathLength + pszMoreLength - 1) < cchPath)
103
0
    {
104
0
      sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", &pszMore[1]);
105
0
      return S_OK;
106
0
    }
107
0
  }
108
582k
  else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
109
0
  {
110
0
    if ((pszPathLength + pszMoreLength) < cchPath)
111
0
    {
112
0
      sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszMore);
113
0
      return S_OK;
114
0
    }
115
0
  }
116
582k
  else if (!pathBackslash && !moreBackslash)
117
582k
  {
118
582k
    if ((pszPathLength + pszMoreLength + 1) < cchPath)
119
582k
    {
120
582k
      sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s%s",
121
582k
                CUR_PATH_SEPARATOR_STR, pszMore);
122
582k
      return S_OK;
123
582k
    }
124
582k
  }
125
126
0
  return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
127
582k
}
128
129
#endif
130
131
/*
132
#undef DEFINE_UNICODE
133
#undef CUR_PATH_SEPARATOR_CHR
134
#undef CUR_PATH_SEPARATOR_STR
135
#undef PATH_CCH_APPEND
136
*/